Question

In: Computer Science

CIT 149 JAVA 1 program question? Write a program that will use static methods as described...

CIT 149 JAVA 1 program question?

Write a program that will use static methods as described in the specifications below. Utilizing the if and else statements, write a program which will calculate a commission based on a two-tiered commission plan of 3% and 7% paid on amounts of $15,000 or less, or over $15,000 in monthly sales by a sales force paid on a commission basis. Use the output specifications below.

? Specifications

  • There will be two classes (separate files) in this program. The class containing the main method will be called Commission. All methods will be called from the main method. The second class (file) will be called ComCalc and will contain all of the methods created below.
  • Prompt the user to input the total monthly sales. That number will be input from the keyboard.
  • The commission is paid at the rate of 3% on any amount of $15,000 or less, in sales. Anyone selling over $15,000 is paid at the rate of 7% on the total monthly sales amount.
  • Declare the necessary variables. Note that in the multiplication of the commission rate the result will potentially have a fractional part. Since the commission rates do not change, initialize them as constants. Initialize all numeric variables to 0.
  • Use the if, else if, and else statements where necessary, to determine the appropriate rate for the amount of the total monthly sales, then calculate the commission following the if/else structure.

? You only need to calculate the commission in one place, rather than having a calculation for each type of commission. Give this aspect of the problem some thought. There are two basic ways you can do this problem as far as the location of the calculation after you have determined the commission rate. Your objective is to do the commission calculation in one place near the end of the program.

  • Output the commission rate, total monthly sales amount, and the commission amount and use appropriate labels for each (see output format below).
  • Use text labels on the output which make it clear what information is being displayed. Do not simply use single words like Commission or Total. Single words such as those are not descriptive enough.
  • Use: good variable names (should be descriptive of what they hold), indentations of four spaces, comments within the body of the program, and label the output appropriately.
  • Test your program with numbers above and below the commission limits for accuracy in its calculations. Do not submit programs in which the calculations are not done correctly. Try numbers above, below, and at the commission breakpoints.
  • Format the output using the printf() function. Also, use a $ where appropriate.
  • Place one blank line between each method. Indent all code between braces by four spaces.

? Constructing the Methods

Create the following methods in the CommCalc class (separate file):

? The Commission class (file) will contain the main method, and it is the main method from which each of the methods below will be called.
The main method will control the logic within the program.

  1. inputTotalSales()

    • This method will display a prompt for the user to enter the total amount of the monthly sales.
    • This method will return the amount of the monthly sales that the user entered.
    • This method does not have parameters.
  2. setCommRate()

    • This method will accept an argument which will be the total monthly sales amount entered by the user and returned to the main method.
    • This method will determine the appropriate commission rate based on whether the monthly sales were over $15,000 or not. Setting the commission rate will be its only task.
    • This method will return the commission rate.
  3. calcCommAmount()

    • This method will accept the commission rate and the amount of monthly sales entered by the user and returned to the main method and will calculate the amount of the commission.
    • This method will return the amount of commission.
  4. displayCommResults()

    • This method will accept the sales amount, the commission rate, and the amount of commission sent from the main method.
    • This method will display the three items above with the output labels shown in the Output Format below.
    • This will be a void method.

? Output Format

Format the output as shown below (the 9s just represent possible numbers):

***** Commission Calculation *****
The commission rate is: 9.99
The total monthly sales amount is: $99999.00
The commission earned on total monthly sales is: $999.00

? Meaningful description of the purpose of the program.
I will be looking for good descriptions of what your program does. An example of a description might look like the following (not for this program of course):
Description: This program accepts input from the keyboard as an amount of a purchase as a double, and calculates a discount based on a customer type using a four-tier percentage scale of 2%, 4%, 6%, and 8%. The output is the amount of the discount rounded to two decimal places and the total purchase less the discount, also rounded to two decimal places.

Solutions

Expert Solution

thanks for the question, here are the two classes -

Comments included and variable names are descriptiove for you to follow the code. let me know for any questions or problem.

================================================================

import java.util.Scanner;

public class CompCalc {


    public CompCalc() {

    }

    public double inputTotalSales() {
        // scanner object to take user input
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter the total amount of monthly sales: ");
        double sales = scanner.nextDouble();
        return sales;
   }

    public double setCommRate(double totalSales){

        // if the sales is below or equal to 15000 set percentage as 3%
        if(totalSales<=15000)return 3;
        else return 5; // else its 7% above 15000
    }

    public double calcCommAmount(double rate, double totalSales){
        // calculate commission amount and return the value
        return rate*totalSales/100;
    }

    public void displayCommResults(double totalSales, double rate, double commissionAmount){

        System.out.println("********* Commission Calculation ************");
        System.out.printf("The comission rate is %.2f\n",rate);
        System.out.printf("The total monthly sales amount is $%.2f\n",totalSales);
        System.out.printf("The commission earned on total monthly sales is: $%.2f\n",commissionAmount);

    }
}

================================================================

public class Commission {





    public static void main(String[] args) {





        // create an object of CompCalc c

        CompCalc calculator = new CompCalc();

        // take total sales amount from user

        double totalSales = calculator.inputTotalSales();

        // find the rate for the sales amount

        double rate = calculator.setCommRate(totalSales);

        // calculate the commission

        double commissionAmount = calculator.calcCommAmount(rate,totalSales);

        // display all the results

        calculator.displayCommResults(totalSales,rate,commissionAmount);

    }

}

================================================================


Related Solutions

Write a java program that contains 3 overloaded static methods for calculating area of a circle,...
Write a java program that contains 3 overloaded static methods for calculating area of a circle, area of a cylinder and volume of a cylinder. Also create an output method which uses JOptionPaneto display instance field(s) and the result of the computing. Then code a driver class which will run and test calling each of these overloaded methods with hard-coded data and display the data and the result of the calculation by calling output method. Thanks!!
3) Create a Java program that uses NO methods, but use scanner: Write a program where...
3) Create a Java program that uses NO methods, but use scanner: Write a program where you will enter the flying distance from one continent to another, you will take the plane in one country, then you will enter miles per gallon and price of gallon and in the end it will calculate how much gas was spend for that distance in miles. Steps: 1) Prompt user to enter the name of country that you are 2) Declare variable to...
Write a class called VLPUtility with the following static methods: Java Language 1. concatStrings that will...
Write a class called VLPUtility with the following static methods: Java Language 1. concatStrings that will accept a variable length parameter list of Strings and concatenate them into one string with a space in between and return it. 2. Overload this method with two parameters, one is a boolean named upper and one is a variable length parameter list of Strings. If upper is true, return a combined string with spaces in upper case; otherwise, return the combined string as...
Assignment Purpose Write a well commented java program that demonstrates the use and re-use of methods...
Assignment Purpose Write a well commented java program that demonstrates the use and re-use of methods with input validation. Instructions It is quite interesting that most of us are likely to be able to read and comprehend words, even if the alphabets of these words are scrambled (two of them) given the fact that the first and last alphabets remain the same. For example, “I dn'ot gvie a dman for a man taht can olny sepll a wrod one way.”...
JAVA CODE FOR BEGINNERS!! DON'T USE FOR OR WHILE METHODS PLEASE! Write a program that reads...
JAVA CODE FOR BEGINNERS!! DON'T USE FOR OR WHILE METHODS PLEASE! Write a program that reads three strings from the keyboard. Although the strings are in no particular order, display the string that would be second if they were arranged lexicographically.
Coding in Java Assignment Write the following static methods. Assume they are all in the same...
Coding in Java Assignment Write the following static methods. Assume they are all in the same class. Assume the reference variable input for the Scanner class and any class-level variables mentioned are already declared. All other variables will have to be declared as local unless they are parameter variables. Use printf. A method that prompts for the customer’s name and returns it from the keyboard. A method called shippingInvoice() that prompts for an invoice number and stores it in a...
JAVA programming- answer prompts as apart of one java assignment Static static variables static methods constants...
JAVA programming- answer prompts as apart of one java assignment Static static variables static methods constants Create a class Die representing a die to roll randomly. ☑ Give Die a public final static int FACES, representing how many faces all dice will have for this run of the program. ☑ In a static block, choose a value for FACES that is a randomly chosen from the options 4, 6, 8, 10, 12, and 20. ☑ Give Die an instance variable...
Java Program Use for loop 1.) Write a program to display the multiplication table of a...
Java Program Use for loop 1.) Write a program to display the multiplication table of a given integer. Multiplier and number of terms (multiplicand) must be user's input. Sample output: Enter the Multiplier: 5 Enter the number of terms: 3 5x0=0 5x1=5 5x2=10 5x3=15 2 Create a program that will allow the user to input an integer and display the sum of squares from 1 to n. Example, the sum of squares for 10 is as follows: (do not use...
Coding Java Assignment Write the following static methods. Assume they are all in the same class....
Coding Java Assignment Write the following static methods. Assume they are all in the same class. Assume the reference variable input for the Scanner class and any class-level variables mentioned are already declared. All other variables will have to be declared as local unless they are parameter variables. Use printf. A method that prompts for the customer’s name and returns it from the keyboard. A method called shippingInvoice() that prompts for an invoice number and stores it in a class...
Question 3 A java source module contains the following class with the static methods main and...
Question 3 A java source module contains the following class with the static methods main and procedure1, and the instance method procedure2 (assume given the bodies of procedure1 and procedure2): public class TestQuestion3             {                         static int result, num1 = 10;                         public static void Main( String [ ] args )                         {                                     int [ ] list1 =   { 2, 4, 6, 8, 10}, list2;                                     .    .    .                         }                         static void procedure1( void )                         {                                     .   .   .                         } void procedure2( void )...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT