test

test
mail@pastecode.io avatar
unknown
java
2 years ago
1.6 kB
7
Indexable
Never
import java.util.*;

public class Main {
    public static void main(String[] args) {
        // from Main ginawa kong UML ksi dun galing ung readInpout and writeOutput
        UML Ans = new UML();
        Ans.readInput();
        Ans.writeOutput();
    }
}

// Dapat naka separate tong class pre
class UML {
    private String itemName;
    private double itemPrice;
    private int itemQuantity;
    private double amountDue;
    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;
    }

    // gagawin mo tong public para accessible siya sa Main Class
    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.");
        int itemQuantity = s.nextInt();
        double itemPrice = s.nextDouble();
    }

    // public din dapat to
    public void writeOutput() {
        System.out.println("You are purchasing " + itemQuantity + " bag(s) at " + itemPrice + " each.");
        System.out.println("Amount due is " + totalCost);
    }
}