How do I write a code for this in java? Create a class named Commission that inc
ID: 669202 • Letter: H
Question
How do I write a code for this in java?
Create a class named Commission that includes three variables:
Ask the user to input a sales figure, a decimal commission rate (example: 0.15) and a percent commission rate (example: 15).
Create three overloaded methods all named computeCommission( ). The first method takes two double parameters representing sales and rate, multiplies them, and then displays the result. The second method takes double and int parameters representing sales and integer rate. This method must take the integer commission rate and change it to a decimal by dividing by 100.0 (ie 15 --> 0.15), then multiply and display the result. The third method takes a single double parameter representing the sales amount. When this method is call, the commission rate is assumed to be 7.5%. Calculate and display the results
Explanation / Answer
/**
* Problem: To find out the commission with overloaded methods
*
*
*/
import java.util.Scanner; //importing scanner class from util library of java
/**
* @author apurv
*
*/
public class Commission {
double salesAmount; // sales amount
double commissionRateDecimal; //commission in decimal
int commisionRateInteger; // commission in integer
/**
* @param args
*/
//reading the values of variables
void readValues(){
Scanner s = new Scanner(System.in); //scanner class object with inputstream object as input
//reading variable values
salesAmount = s.nextDouble();
commissionRateDecimal = s.nextDouble();
commisionRateInteger= s.nextInt();
s.close(); //closing stream
//calling overloaded methods
computeCommission(salesAmount,commissionRateDecimal);
computeCommission(salesAmount,commisionRateInteger);
computeCommission(salesAmount);
}
// overloaded method one
/*method takes two double parameters representing sales and rate, multiplies them, and then displays the result*/
void computeCommission(double sales,double rate){
System.out.println("Commisssion : "+ sales * rate);
}
// overloaded method two
/*method takes the integer commission rate and change it to a decimal by dividing by 100.0 then multiply and display the result*/
void computeCommission(double sales,int rate){
System.out.println("Commisssion : "+ sales * (rate/100.0));
}
// overloaded method three
/*method takes a single double parameter representing the sales amount ,the commission rate is assumed to be 7.5% and display the result*/
void computeCommission(double sales){
System.out.println("Commisssion : "+ sales * 7.5);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Commission().readValues(); //creating commission class object
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.