Question

In: Computer Science

public class CashRegisterPartTwo { // TODO: Do not modify the main method. // You can add...

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!

Solutions

Expert Solution

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);

        

    }
}

Related Solutions

Modify Example 5.1 to add a ReadAccount method to the BankAccount class that will return a...
Modify Example 5.1 to add a ReadAccount method to the BankAccount class that will return a BankAccountconstructed from data input from the keyboard. Override ReadAccount in SavingsAccount to return an account that refers to a SavingsAccount that you construct, again initializing it with data from the keyboard. Similarly, implement ReadAccount in the CheckingAccount class. Use the following code to test your work. public static void testCode()         {             SavingsAccount savings = new SavingsAccount(100.00, 3.5);             SavingsAccount s = (SavingsAccount)savings.ReadAccount();...
public class AddValueToArray { // You must define the addValueTo method, which will add // a...
public class AddValueToArray { // You must define the addValueTo method, which will add // a given value to each element of the given array. // // TODO - define your code below this comment // // DO NOT MODIFY main! public static void main(String[] args) { int[] array = new int[]{3, 8, 6, 4}; int valueToAdd = Integer.parseInt(args[0]); addValueTo(valueToAdd, array); for (int index = 0; index < array.length; index++) { System.out.println(array[index]); } } }
Error: Main method is not static in class ArrayReview, please define the main method as: public...
Error: Main method is not static in class ArrayReview, please define the main method as: public static void main(String[] args) please help me fast: import java.util. Random; import java.util.Scanner; //ArrayReview class class ArrayReview { int array[];    //constructor ArrayReview (int n) { array = new int[n]; //populating array Random r = new Random(); for (int i=0;i<n; i++) array[i] = r.nextInt (); } //getter method return integer at given index int getElement (int i) { return array[i]; }    //method to...
Modify Account Class(Java programming) used in the exercises such that ‘add’ and ‘deduct’ method could only...
Modify Account Class(Java programming) used in the exercises such that ‘add’ and ‘deduct’ method could only run if the account status is active. You can do this adding a Boolean data member ‘active’ which describes account status (active or inactive). A private method isActive should also be added to check ‘active’ data member. This data member is set to be true in the constructor, i.e. the account is active the first time class Account is created. Add another private method...
please modify the method public void addList(SinglyLinkedList<E> s) that add list to another with addlast() and...
please modify the method public void addList(SinglyLinkedList<E> s) that add list to another with addlast() and remove() methods without changing the parameter of addList method. ////////////////////////////////////////////////// public class SinglyLinkedList<E> {      private class Node<E> {            private E element;            private Node<E> next;            public Node(E e, Node<E> n) {                 element = e;                 next = n;            }            public E getElement() {                 return element;            }            public void setElement(E element) {                 this.element = element;...
Add a public method called CountChildren to the OurPriorityQueue class that receives a priority value and...
Add a public method called CountChildren to the OurPriorityQueue class that receives a priority value and returns the number of children nodes below the node with the priority value. It must call a private recursive method that does the actual counting of children nodes. The recursive private method must count and return the number of nodes within a subtree where the subtree’s “root” node has a Value that equals the value passed into the method. Do not include the parent...
Modify the DetailedClockPane.java class in your detailed clock program, to add animation to this class. Be...
Modify the DetailedClockPane.java class in your detailed clock program, to add animation to this class. Be sure to include start() and stop() methods to start and stop the clock, respectively.Then write a program that lets the user control the clock with the start and stop buttons.
Could you do it with python please? public class BSTTraversal {         public static void main(String[]...
Could you do it with python please? public class BSTTraversal {         public static void main(String[] args) {                 /**                  * Creating a BST and adding nodes as its children                  */                 BSTTraversal binarySearchTree = new BSTTraversal();                 Node node = new Node(53);                 binarySearchTree.addChild(node, node, 65);                 binarySearchTree.addChild(node, node, 30);                 binarySearchTree.addChild(node, node, 82);                 binarySearchTree.addChild(node, node, 70);                 binarySearchTree.addChild(node, node, 21);                 binarySearchTree.addChild(node, node, 25);                 binarySearchTree.addChild(node, node, 15);                 binarySearchTree.addChild(node, node, 94);                 /**         ...
public class Sum2 { // TODO - write your code below this comment. } Download the...
public class Sum2 { // TODO - write your code below this comment. } Download the Sum2.java file, and open it in jGrasp (or a text editor of your choice). This program takes two values as command-line arguments, converts them to ints via Integer.parseInt, and adds them together. Example output of this program is shown below, with the command-line arguments 3 4: Sum: 7
public class FirstChar { // TODO - write your code below this comment. } Download the...
public class FirstChar { // TODO - write your code below this comment. } Download the FirstChar.java file, and open it in jGrasp (or a text editor of your choice). This program takes a single command-line argument and prints out the first character of this argument, using String's charAt() method. If you're unsure how to pass command-line arguments to a program with jGrasp, see this tutorial. Example output of this program with the command-line argument foo is shown below: First...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT