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

Exercise 2: Your friend who works at a store is urgently in need of your help wi

ID: 3875866 • Letter: E

Question

Exercise 2: Your friend who works at a store 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 clas:s 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.

Explanation / Answer

/* package codechef; // don't place package name! */

import java.util.*;

import java.lang.*;

import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */

class A

{

private String item;

private double cost;

private int bulk;

private int discount;

private int number;

private double k;

String setitem(String item)

{

this.item = item;

return item;

}

double getcost(double cost)

{

this.cost = cost;

return cost;

}

double setcost(double cost)

{

return cost;

}

int getbulk(int bulk)

{

this.bulk = bulk;

return bulk;

}

int setbulk(int bulk)

{

return bulk;

}

int getdis(int discount)

{

this.discount = discount;

return discount;

}

int setdis(int discount)

{

return discount;

}

int setnumber(int number)

{

this.number = number;

return number;

}

double registersale(int n)

{

  

cost = number*cost;

if(n>bulk)

{

cost = (cost/100) * 10;

return cost;

}

else

{

return 0;

}

}

double displaysale()

{double s;

System.out.println("item:"+item);

System.out.println("numbersold:"+number);

s = registersale(number);

System.out.println("total discount"+s);

s = (cost*number)+s;

System.out.println("totalamount"+s);

return 0;

  

  

  

}

  

}

class sales

{

public static void main (String[] args) throws java.lang.Exception

{

// your code goes here

Scanner sc = new Scanner(System.in);

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

String a = sc.next();

System.out.println("cost:");

double b = sc.nextInt();

System.out.println("bulk quanity(to qualify for discount)");

int c = sc.nextInt();

System.out.println("discount:");

int d = sc.nextInt();

System.out.println("number sold:");

int e = sc.nextInt();

A a1 = new A();

a1.setitem(a);

a1.setcost(b);

a1.setbulk(c);

a1.setdis(d);

a1.setnumber(e);

a1.displaysale();

}

}