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

Need to be answered correctly. You must: Comment and Format and Must make sure a

ID: 3875928 • Letter: N

Question

Need to be answered correctly. You must: Comment and Format and Must make sure about indenting. If you don't follow these steps, it will be flagged for review. MUST BE IN JAVA FORMAT. IT IS A MUST. Please also check the output very carefully. Must not provide the answer on a page. Use the Java compiler. Please provide the code in such a way so that it can be copied and checked in the Java compiler.

Exercise 2: Your friend who works at the superstore is urgently in need of your help with some basic sales records. Consider a class Sales that keeps track of the sales of one item in the store. An object of this class will have the attributes

Name of the item

Cost of the item

Bulk quantity (to qualify for discount)

Discount (percentage)

Number sold

Total amount

Total discount

and the following methods

Constructor that sets the cost, bulk quantity and the discount

Get and set methods for cost, bulk quantity and discount

registerSale(int n) records the sale of n items. If n is larger than the bulk quantity, the cost will be reduced by the discount.

displaySales displays the name of the item, number sold, the total amount, and total discount.

Ignore sales tax.

Implement the class and test it. For example, for

Item: Shampoo

Cost: 2.50

Bulk quantity (to qualify for discount): 4

Discount: 10 percent

Number sold: 10

The output would be:

Shampoo

Number sold: 10

Total amount: $ 22.50

Total discount: $ 2.50

As another example, for

Item: Toothpaste

Cost: 1.99

Bulk quantity: 20

Discount: 15

Number sold: 10

The output would be:

Toothpaste

Number sold: 10

Total amount: 19.90

Total discount: 0

Need to be answered correctly. You must: Comment and Format and Must make sure about indenting. If you don't follow these steps, it will be flagged for review. MUST BE IN JAVA FORMAT. IT IS A MUST. Please also check the output very carefully. Must not provide the answer on a page. Use the Java compiler. Please provide the code in such a way so that it can be copied and checked in the Java compiler.

Explanation / Answer

Sales.java

import java.text.DecimalFormat;

public class Sales {

//Declaring instance variables

private String itemName;

private double cost;

private int bulkQty;

private double discount;

private int sold;

private double totAmount;

private double totDiscount;

//Parameterized constructor

public Sales(double cost, int bulkQty, double discount) {

this.cost = cost;

this.bulkQty = bulkQty;

this.discount = discount;

}

// getters and setters

public double getCost() {

return cost;

}

public void setCost(double cost) {

this.cost = cost;

}

public int getBulkQty() {

return bulkQty;

}

public void setBulkQty(int bulkQty) {

this.bulkQty = bulkQty;

}

public double getDiscount() {

return discount;

}

public void setDiscount(double discount) {

this.discount = discount;

}

public String getItemName() {

return itemName;

}

public void setItemName(String itemName) {

this.itemName = itemName;

}

public int getSold() {

return sold;

}

public void setSold(int sold) {

this.sold = sold;

}

public void registerSale(int sold)

{

if(sold>bulkQty)

{

totAmount=sold*cost-(sold*cost)*(discount/100);

totDiscount=(sold*cost)*(discount/100);

}

else

{

totAmount=sold*cost;

totDiscount=0;

}

}

public void displaySale()

{

// DecimalFormat class is used to format the output

DecimalFormat df = new DecimalFormat("0.00");

System.out.println(" "+itemName);

System.out.println("Number sold: "+sold);

System.out.println("Total amount: $ "+df.format(totAmount));

System.out.println("Total discount: $ "+df.format(totDiscount));

}

}

_________________

SalesDemo.java

import java.util.Scanner;

public class SalesDemo {

public static void main(String[] args) {

//Declaring variables

String itemName;

int qty,bulkQty,sold;

double cost,discount;

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

//Getting the inputs entered by the user

System.out.print("Item:");

itemName=sc.nextLine();

System.out.print("Cost:");

cost=sc.nextDouble();

System.out.print("Bulk quantity (to qualify for discount):");

bulkQty=sc.nextInt();

System.out.print("Discount:");

discount=sc.nextDouble();

System.out.print("Number sold:");

sold=sc.nextInt();

//Creating an Instance of Item class object

Sales i=new Sales(cost, bulkQty, discount);

i.setItemName(itemName);

i.setSold(sold);

i.registerSale(sold);

System.out.print("The output would be:");

i.displaySale();

}

}

____________________

Output:

Item:Shampoo
Cost:2.50
Bulk quantity (to qualify for discount):4
Discount:10
Number sold:10
The output would be:
Shampoo
Number sold: 10
Total amount: $ 22.50
Total discount: $ 2.50

_______________

Output#2:

Item:Toothpaste
Cost:1.99
Bulk quantity (to qualify for discount):20
Discount:15
Number sold:10
The output would be:
Toothpaste
Number sold: 10
Total amount: $ 19.90
Total discount: $ 0.00

__________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