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...
could you do all the challenges? public class Main { public static void main(String[] args) {...
could you do all the challenges? public class Main { public static void main(String[] args) { // declare an array so you can easily use them under // one name //ex1 array of test score 0-100 int[] testScores = new int[100]; //ex2 array of 200 gpa double[] gpa = new double[200]; //ex3 50 element array of age int[] age; //1 - declares age array age = new int[50]; //2 - instantiates age array age[0] = 10; //3 - put initial...
Java Language -Create a project and a class with a main method, TestCollectors. -Add new class,...
Java Language -Create a project and a class with a main method, TestCollectors. -Add new class, Collector, which has an int instance variable collected, to keep track of how many of something they collected, another available, for how many of that thing exist, and a boolean completist, which is true if we want to collect every item available, or false if we don't care about having the complete set. -Add a method addToCollection. In this method, add one to collected...
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...
/* Complete the TO DO comments below */ window.onload = function() { /* TODO add a...
/* Complete the TO DO comments below */ window.onload = function() { /* TODO add a border to the header of the page (a) a simple type selector, and (b) the style property of the element object. */ document.querySelector('TODO').TODO = TODO; /* TODO change the text of the h1 element by using (a) the first-child pseudo selector, and (b) the innerHTML property of the element object. */ document.querySelector('TODO').TODO = TODO; /* TODO change the background-color of the section with id...
////Fixme(1) add a statement to import ArrayList class public class ListManipulation { public static void main(String[]...
////Fixme(1) add a statement to import ArrayList class public class ListManipulation { public static void main(String[] args) { //Fixme(2) create an ArrayList of integers and name the ArrayList list. //Fixme(3) add the following numbers to the list: 10, 15, 7, -5, 73, -11, 100, 20, 5, -1    displayList(list); System.out.println(); displayListBackwards(list);       }    public static void displayList(ArrayList<Integer> list) { for(Integer i: list) System.out.print(i + " ");    } //Fixme(4) define a method displayListBackwards, which takes an ArrayList as...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT