Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.project;
- import java.util.Scanner;
- public class PE2Proj {
- String itemName;
- double itemPrice, amountDue;
- int itemQuantity;
- PE2Proj(){
- //Default constructor
- }
- public void setItemName(String newItemName) {
- }
- public void setTotalCost(int quantity, double price) {
- }
- public String getItemName() {
- return itemName;
- }
- public double getTotalCost() {
- return amountDue = itemQuantity * itemPrice;
- }
- public void readInput() {
- Scanner sc = new Scanner(System.in);
- System.out.println("Enter the name of the item you are purchasing:");
- itemName = sc.nextLine();
- System.out.println("Enter the quantity and price separated by space:");
- itemQuantity = sc.nextInt();
- itemPrice = sc.nextDouble();
- setItemName(itemName);
- setTotalCost(itemQuantity, itemPrice);
- }
- public void writeOutput() {
- System.out.printf("You are purchasing %d %s(s) at %.2f each.", itemQuantity, itemName, itemPrice);
- System.out.printf("\nAmount due is %.2f", getTotalCost());
- }
- public static void main(String[] args) {
- PE2Proj proj = new PE2Proj();
- proj.readInput();
- proj.writeOutput();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment