Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an application for computing sale discounts at a store register. First cr

ID: 3849188 • Letter: C

Question

Create an application for computing sale discounts at a store register. First create a class named Sale.java that contains the receipt number, cost of the item, discount rate and a sales tax rate that will default to 8%. Include the set methods for all but the sales tax rate which has a constant value of 8%, plus use a method that computes the sale amount after the discount is deducted and tax is added then prints the results. Next, create an application named SalesReceipts that uses the Sale class to allow the user to input item values for the receipt number, retail price and discount percent as a whole number, then call the method that prints the resulting discounted price with tax. It will keep a running total of the items’ discounted prices and continue looping and accepting user input while the user inputs ‘1’ to continue, ‘0’ to stop the input.

Explanation / Answer

Sale.java

public class Sale {
  
   //Declaring instance variables
   int receipt_num;
   int cost_of_item;
   int discount_rate;
   int sales_tax_rate=8;
  
   //Zero argumented constructor
   public Sale() {
       super();
   }
  
   //Parameterized constructor
   public Sale(int receipt_num, int cost_of_item, int discount_rate) {
       super();
       this.receipt_num = receipt_num;
       this.cost_of_item = cost_of_item;
       this.discount_rate = discount_rate;
   }
  

   //getters and setters
   public int getReceipt_num() {
       return receipt_num;
   }
   public void setReceipt_num(int receipt_num) {
       this.receipt_num = receipt_num;
   }
   public int getCost_of_item() {
       return cost_of_item;
   }
   public void setCost_of_item(int cost_of_item) {
       this.cost_of_item = cost_of_item;
   }
   public int getDiscount_rate() {
       return discount_rate;
   }
   public void setDiscount_rate(int discount_rate) {
       this.discount_rate = discount_rate;
   }
  
  
   //This method will calculate and display the sale amount
   public void calSaleAmount()
   {
       double sale_amt=cost_of_item-(cost_of_item*((double)discount_rate/100))+(cost_of_item*((double)sales_tax_rate/100));
       System.out.println("Sale Amount :$ "+sale_amt);
   }

}

____________________

SalesReceipts.java

import java.util.Scanner;

public class SalesReceipts {

   public static void main(String[] args) {

       //Declaring variables
       int cost_of_item, discount_rate, receipt_num, item = 0;
      
       // Scanner object is used to get the inputs entered by the user
       Scanner sc = new Scanner(System.in);

       //This loop continues to execute until the use renters '0' as input
       while (true) {
          
           //Getting the inputs entered by the user
           System.out.print("Enter the Receipt Number of Item#" + (++item)+ ":");
           receipt_num = sc.nextInt();

           System.out.print("Enter the Cost of an Item $:");
           cost_of_item = sc.nextInt();

           System.out.print("Enter the Discount Rate %:");
           discount_rate = sc.nextInt();

           //Creating an Sale class object by passing the user inputs as arguments
           Sale s = new Sale(receipt_num, cost_of_item, discount_rate);
          
           //Calling the method on the Sale class object
           s.calSaleAmount();
          
           //getting the input entered by the user
           System.out.print("Please Enter '1' to continue and '0' to Stop :");
           int n = sc.nextInt();
           if (n == 1)
               continue;
           else if (n == 0)
               break;
       }

   }

}

_______________________

Output:

Enter the Receipt Number of Item#1:1111
Enter the Cost of an Item $:450
Enter the Discount Rate %:10
Sale Amount :$ 441.0
Please Enter '1' to continue and '0' to Stop :1
Enter the Receipt Number of Item#2:2222
Enter the Cost of an Item $:780
Enter the Discount Rate %:15
Sale Amount :$ 725.4
Please Enter '1' to continue and '0' to Stop :1
Enter the Receipt Number of Item#3:3333
Enter the Cost of an Item $:220
Enter the Discount Rate %:5
Sale Amount :$ 226.6
Please Enter '1' to continue and '0' to Stop :1
Enter the Receipt Number of Item#4:4444
Enter the Cost of an Item $:550
Enter the Discount Rate %:20
Sale Amount :$ 484.0
Please Enter '1' to continue and '0' to Stop :0

____________Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote