Design and implement a Java program for programming exercise

Design and implement a Java program for programming exercise 6.11, page 236 (name it ComputeCommissions), to print out a table of sales amounts and commissions as shown in the textbook. Follow the instructions in the problem statement (the program takes no input from the user and all output is generated by the main() method). Document your code and follow the output model shown in the textbook. (NOTE: Even though the table starts with a sales amount of $10,000, the method computeCommission() must return the correct commission for any sales amount.)

**6.3 (Palindrome integer) Write the methods with the following headers // Return the reversal of an integer, i.e., reverse (456) returns 654 public static int reverse(int number) // Return true if number is a palindrome public static boolean isPalindrome(int number) Use the reverse method to implement isPalindrome. A number is a palin drome if its reversal is the same as itself. Write a test program that prompts the user to enter an integer and reports whether the integer is a palindrome

Solution

6.3)

PalindromeInterger.java

import java.io.*;

public class PalindromeInterger {
   // This is a static method to reverse the Entered number by the user.
   public static int reverse(int number) {
       int remainder = 0;
       int rev = 0;
       while (number > 0) {
           remainder = number % 10;
           rev = rev * 10 + remainder;
           number = number / 10;
       }
       return rev;
   }

   // This is a static method to check whether the entered number and reverse
   // number is equal or not.
   // If they are equal, it is a palindrome otherwise not.
   public static boolean isPalindrome(int number, int reverse) {
       if (reverse == number) {
           return true;
       } else {
           return false;
       }
   }

}

_____________________________________________

Test.java

import java.util.Scanner;

public class Test {

   public static void main(String[] args) {

       while (true) {
           System.out.println(\" \");
           // We have to take a positive integer to run the program
           System.out
                   .print(\"Enter an positive integer (Zero(0) to Quit ):\");
           // Read the values which entered by the user dynamically.
           Scanner sc = new Scanner(System.in);
           int num = sc.nextInt();
           // Check if the entered number is not equal to zero.If the Entered
           // number is equal to zero program will terminate
           if (num != 0) {
               // Calling the Static method here by passing Entered number as
               // an argument.
               int reverse = PalindromeInterger.reverse(num);
               // Printing the Returned reverse number by the method.
               System.out.println(\"The reverse of the integer:\"+ reverse);
               // Calling the static method by passing the entered number and
               // reverse number as an arguments
               boolean check = PalindromeInterger.isPalindrome(num, reverse);
               if (check == true) {
                   System.out.println(\"** This is a palindrome **\");
               } else {
                   System.out.println(\"** This is not a palindrome **\");
               }
               continue;
           }
           // If the user entered zero other than positive integer then the
           // program will terminate
           else {
               System.out.println(\"* Program Exit *\");
               break;
           }

       }
   }

}

_________________________________________________

Output:


Enter an positive integer (Zero(0) to Quit ):123
The reverse of the integer:321
** This is not a palindrome **

Enter an positive integer (Zero(0) to Quit ):151
The reverse of the integer:151
** This is a palindrome **

Enter an positive integer (Zero(0) to Quit ):0
* Program Exit *

_______________________________________________

5.39)

CommissionCalculator.java

import java.util.Scanner;

public class CommissionCalculator {

   // Declaring Base salary as constant
   public static final double baseSalary = 5000;

   public static void main(String[] args) {

       // Declaring variables
       double salAmount, reqCommission, targetAmount;

       /*
       * Scanner class object is used to read the inputs entered by the user
       */
       Scanner sc = new Scanner(System.in);

       // Getting the target Amount entered by the user
       System.out.print(\"Enter Target Amount :\");
       targetAmount = sc.nextDouble();

       // calculating the required commission he has to earn
       reqCommission = targetAmount - baseSalary;

       // calculating how much sales he has to done to reach required
       // commission
       if (reqCommission <= 400) {
           // calculating the sale amount
           salAmount = reqCommission / 0.08;

       } else if (reqCommission <= 900) {
           // calculating the sale amount
           salAmount = (reqCommission - 400) / 0.10 + 5000;
       } else {
           // calculating the sale amount
           salAmount = (reqCommission - 900) / 0.12 + 10000;
       }

       // Displaying the sales he has to do
       System.out.printf(\"Minimum Sales $: %.2f\", salAmount);

   }

}

_________________________________________

Output:

Enter Target Amount :30000
Minimum Sales $: 210833.33

_______________________________Thank You

Design and implement a Java program for programming exercise 6.11, page 236 (name it ComputeCommissions), to print out a table of sales amounts and commissions
Design and implement a Java program for programming exercise 6.11, page 236 (name it ComputeCommissions), to print out a table of sales amounts and commissions
Design and implement a Java program for programming exercise 6.11, page 236 (name it ComputeCommissions), to print out a table of sales amounts and commissions

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site