Respuesta :
Answer:
public class Product {
//Declaring the fields
private String name;
private int amount;
private double price;
//Constructor
public Product(String name, int amount, double price) {
this.name = name;
this.amount = amount;
this.price = price;
}
// The method get_price
public double get_price(int amount){
// amount of goods less than 10
if(amount<10){
double zeroDiscPrice;
zeroDiscPrice = this.price;
return zeroDiscPrice;
}
// amount of goods less than 100
else if(amount>=10 && amount<100){
double tenPercentDiscPrice;
tenPercentDiscPrice = this.price-(this.price*0.1);
return tenPercentDiscPrice;
}
// amount of goods greater than 100
else{
double twentyPercentDiscPrice;
twentyPercentDiscPrice = this.price-(this.price*0.2);
return twentyPercentDiscPrice;
}
}
}
Explanation:
The class is implemented in Java programming language
Three member variables (fields) are declared as described in the question
A constructor is created to initialize an instance of the class
The method get_price() as created uses a combination of if...else if....else To determing the price based on the amount of items bought as described in the question.