java code
unknown
java
4 years ago
1.6 kB
12
Indexable
import java.util.*;
public class Main {
public static void main(String[] args) {
UML Ans = new UML();
Ans.readInput();
Ans.writeOutput();
}
}
class UML {
private String itemName;
private double itemPrice;
private int itemQuantity;
private double amountDue;
// no need na yata tong totalCost?
private double totalCost;
void setItemName(String itemName) {
this.itemName = itemName;
}
String getItemName() {
return itemName;
}
void setTotalCost(int itemQuantity, double itemPrice) {
this.totalCost = itemQuantity * itemPrice;
}
double getTotalCost() {
return totalCost;
}
public void readInput() {
Scanner s = new Scanner(System.in);
UML Product = new UML();
System.out.println("Enter the name of the item you are purchasing.");
String itemName2 = s.nextLine();
Product.setItemName(itemName2);
System.out.println("Enter the quantity and price separated by a space.");
// dito yung error mo. irere-assign mo lang dapat to. so need lagyan ng another int
itemQuantity = s.nextInt();
// same lang dito
itemPrice = s.nextDouble();
// need mo icall ung setTotalCost method para macompute yung total
setTotalCost(itemQuantity, itemPrice);
}
public void writeOutput() {
System.out.println("You are purchasing " + itemQuantity + " bag(s) at " + itemPrice + " each.");
System.out.println("Amount due is " + totalCost);
}
}Editor is loading...