Create, using NetBeans, a complete Java program called CalcTotalPrice according
ID: 3675760 • Letter: C
Question
Create, using NetBeans, a complete Java program called CalcTotalPrice according to the following guidelines.
The program must include ve methods: getSaleTotal, getSalePrice, getSaleWeight, calcTax, and calcShipping. The method getSaleTotal takes no input parameters and returns a double (the sale total), which it computes by calling the other four methods. The methods getSalePrice and getSaleWeight each return a double, which they get from user input. The method calcTax takes a double (the sale price) as a parameter and returns a double that is the amount of tax (use 6% as a xed tax rate). The method calcShipping takes a double (the sale weight) as a parameter and returns the shipping amount as a double (calculate shipping as $10 if weight is less than 10, and $20 if weight is 10 or greater). The method getSaleTotal should print the sale price amount, tax amount, shipping amount, and sale total amount.
Thoughts:
*) You might begin by mapping out the structure of the main method and other methods.
Explanation / Answer
import java.util.Scanner;
public class CalcTotalPrice {
public static double getSaleTotal(){
Scanner in = new Scanner(System.in);
System.out.print("Enter Sale Price Amount: ");
double saleprice = getSalePrice(in);
System.out.println("Sale Price Amount: "+saleprice);
System.out.println("");
double tax = calcTax(saleprice);
System.out.println("Tax Amount: "+tax);
System.out.println("");
System.out.print("Enter Shipping Amount: ");
double shipping = calcShipping(in.nextDouble());
System.out.println("Shipping Amount: "+shipping);
System.out.println("");
double saleTotal = tax+saleprice+shipping;
System.out.println("Sale Total Amount: "+saleTotal);
return saleTotal;
}
public static double getSalePrice(Scanner in){
double salePrice = in.nextDouble();
return salePrice;
}
public static double getSaleWeight(Scanner in){
double saleWeight = in.nextDouble();
return saleWeight;
}
public static double calcTax(double salePrice){
double salesTax = salePrice * .06;
return salesTax;
}
public static double calcShipping(double saleWeight){
double amountShipping = 0;
if (saleWeight < 10){
amountShipping = 10;
}else if(saleWeight >= 10){
amountShipping = 20;
}
return amountShipping;
}
public static void main(String[] args) {
double saletotal = getSaleTotal();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.