In: Computer Science
public class CashRegisterPartTwo { // TODO: Do not modify the main method. // You can add comments, but the main method should look exactly like this // when you submit your project. public static void main(String[] args) { runTransaction(); } // TODO: Define the runTranscation method. // runTransaction runs the cash register process from start to finish. However, // it will not contain ALL Of the code. You are going to have to delegate some of // its functionality to the other three methods: computePreTaxTotal, computeTax, // and displayTransactionSummary. The runTransaction method should call these three // methods at some point to perform their purpose. public static void runTransaction() { } // TODO: Define the computePreTaxTotal method. // computePreTaxTotal will calculate and return the pre-tax total based on the number of packages ordered, // the number of cheesecakes per package, and the price of each cheesecake. public static double computePreTaxTotal(int numPackagesOrdered, int packageQuantity, double price) { // Your code goes here. } // TODO: Define the computeTax method. // computeTax will calculate and return the special tax associated with the sale. // Within this method, you will need to figure out the normal in order to compute // the special tax. You don't need a separate method for calculating the normal tax. public static double computeTax(double preTaxTotal) { // Your code goes here. } // TODO: Define the displayTransactionSummary method. // displayTransactionSummary will print the summary of the transaction to the console. The values displayed // are the same as the ones required in Project 1 Part 3 except for the normal tax. You do not // need to display the normal tax associated with the sale. public static void displayTransactionSummary(int numPackagesOrdered, double price, double preTaxTotal, double tax, double totalCost) { // Your code goes here. } }
How to do these step in this part one of the code :
import java.util.Scanner; public class CashRegisterPartTwo { public static void main(String[] args) { // defining constants for each unit measurement Scanner sc = new Scanner(System.in); final double CHEESECAKE_UNIT_PRICE = 28.60; final int UNITS_PER_PACKAGE = 23; final double TAX_RATE = 0.1575; // finding price per package double price_per_package = CHEESECAKE_UNIT_PRICE * UNITS_PER_PACKAGE; // displaying basic details System.out.printf("Unit price of a cheesecake: $%.2f\n", CHEESECAKE_UNIT_PRICE); System.out.printf("Number of cheesecakes per package: %d\n", UNITS_PER_PACKAGE); System.out.printf("Price per package: $%.2f\n", price_per_package); // asking, reading name and num packages System.out.print("\nWhat is your name? "); String name = sc.nextLine(); System.out.print("How many packages do you want? "); int numPackages = sc.nextInt(); // finding pre tax total, normal tax, special tax and total double pre_tax_total = price_per_package * numPackages; double normal_tax = pre_tax_total * TAX_RATE; double special_tax = (normal_tax / 3.32) + 3.91; double total_cost = pre_tax_total + special_tax; // note: normal tax is excluded from the total cost //displaying every details in proper format System.out.printf("\nNumber of packages ordered: %d\n", numPackages); System.out.printf("Price of each package: $%.2f\n", price_per_package); System.out.printf("Pre tax total: $%.2f\n", pre_tax_total); System.out.printf("Normal tax (%.2f%%): $%.2f\n", TAX_RATE * 100, normal_tax); System.out.printf("Special tax: $%.2f\n", special_tax); System.out.printf("Total cost of the purchase: $%.2f\n", total_cost); //displaying a personalized message, modify this as needed. System.out.printf("\nThank you for the purchase, %s. " + "I think a bottle of Coca Cola would go well with this.\n", name);
}
}
Please if I can get help with this!
public class CashRegisterPartTwo {
// TODO: Do not modify the main method.
// You can add comments, but the main method should look exactly like this
// when you submit your project.
final double CHEESECAKE_UNIT_PRICE = 28.60;
final int UNITS_PER_PACKAGE = 23;
final double TAX_RATE = 0.1575;
public static void main(String[] args) {
runTransaction();
}
// TODO: Define the runTranscation method.
// runTransaction runs the cash register process from start to finish. However,
// it will not contain ALL Of the code. You are going to have to delegate some of
// its functionality to the other three methods: computePreTaxTotal, computeTax,
// and displayTransactionSummary. The runTransaction method should call these three
// methods at some point to perform their purpose.
public static void runTransaction() {
Scanner sc = new Scanner(System.in);
// finding price per package
double price_per_package = CHEESECAKE_UNIT_PRICE * UNITS_PER_PACKAGE;
// asking, reading name and num packages
System.out.print("\nWhat is your name? ");
String name = sc.nextLine();
System.out.print("How many packages do you want? ");
int numPackages = sc.nextInt();
double pre_tax_total = computePreTaxTotal(numPackages, UNITS_PER_PACKAGE, CHEESECAKE_UNIT_PRICE);
double special_tax =computeTax(pre_tax_total);
double total_cost = pre_tax_total + special_tax;
displayTransactionSummary( numPackages,CHEESECAKE_UNIT_PRICE,pre_tax_total,
special_tax, total_cost);
}
// TODO: Define the computePreTaxTotal method.
// computePreTaxTotal will calculate and return the pre-tax total based on the number of packages ordered,
// the number of cheesecakes per package, and the price of each cheesecake.
public static double computePreTaxTotal(int numPackagesOrdered, int packageQuantity, double price) {
// Your code goes here.
double pre_tax_total = numPackagesOrdered*packageQuantity*price;
return pre_tax_total;
}
// TODO: Define the computeTax method.
// computeTax will calculate and return the special tax associated with the sale.
// Within this method, you will need to figure out the normal in order to compute
// the special tax. You don't need a separate method for calculating the normal tax.
public static double computeTax(double preTaxTotal) {
// Your code goes here.
double normal_tax = preTaxTotal * TAX_RATE;
double special_tax = (normal_tax / 3.32) + 3.91;
return special_tax;
}
// TODO: Define the displayTransactionSummary method.
// displayTransactionSummary will print the summary of the transaction to the console. The values displayed
// are the same as the ones required in Project 1 Part 3 except for the normal tax. You do not
// need to display the normal tax associated with the sale.
public static void displayTransactionSummary(int numPackagesOrdered, double price, double preTaxTotal,
double tax, double totalCost) {
// Your code goes here.
System.out.printf("Unit price of a cheesecake: $%.2f\n",price);
System.out.printf("Number of cheesecakes per package: %d\n",UNITS_PER_PACKAGE);
System.out.printf("Price per package: $%.2f\n", price_per_package);
System.out.printf("\nNumber of packages ordered: %d\n", numPackagesOrdered);
System.out.printf("Pre tax total: $%.2f\n", preTaxTotal);
System.out.printf("Special tax: $%.2f\n", tax);
System.out.printf("Total cost of the purchase: $%.2f\n", totalCost);
}
}