Using object oriented programming approach, write a program to calculate the pur
ID: 3761195 • Letter: U
Question
Using object oriented programming approach, write a program to calculate the purchase price for a retail store.
Define a class Product (Product.java)
Four private data members: product number, product name, unit price, units sold
Two overloaded constructors
Get and set methods for each private data member
A method to calculate and return the purchase price (unit price * units sold)
toString() method
(Store.java) Write a client program that creates a Product object based on the user input, computes the purchase price, and outputs the sales information (include the item id, item name, unit price, units sold, and purchase price).
Explanation / Answer
class Product{
int number;
string name;
double price;
int unitsSold;
public Product(){
number = 0;
name = "";
price = 0;
unitsSold = 0;
}
public Product(int pno,string name,double price,int unitsSold){
number = pno;
this.name = name;
this.price = price;
this.unitsSold = unitsSold;
}
int getPNo(){
return number;
}
string getName(){
return name;
}
double getPrice(){
return price;
}
int getUnitsSold(){
return unitsSold;
}
void setPNo(int no){
number = no;
}
void setName(string name){
this.name = name;
}
void setPrice(double price){
this.price = price;
}
void setUnitsSold(int unitsSold){
this.unitsSold = unitsSold;
}
double purchasePrice(){
return price*unitsSold;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.