First try

This commit is contained in:
Logen Kain 2020-11-11 09:20:45 -05:00
parent e168d9d8db
commit 3125f9642e
2 changed files with 62 additions and 2 deletions

View File

@ -7,7 +7,38 @@
* int itemQuanity - init to 0 * int itemQuanity - init to 0
* *
* Public member mothods (mutators & accessors) * Public member mothods (mutators & accessors)
* setName() & getName()
* setPrice() & getPrice() * setPrice() & getPrice()
* setQuantity() & getQuantity()
*/ */
public class ItemToPurchase {
private String itemName;
private int itemPrice;
private int itemQuantity;
public ItemToPurchase() {
itemName = "none";
itemPrice = 0;
itemQuantity = 0;
}
public void setName(String name){
this.itemName = name;
}
public String getName(){
return itemName;
}
public void setQuantity(int q){
this.itemQuantity = q;
}
public int getQuantity(){
return itemQuantity;
}
public void setPrice(int p){
this.itemPrice = p;
}
public int getPrice(){
return itemPrice;
}
}

View File

@ -37,5 +37,34 @@ import java.util.Scanner;
public class ShoppingCartPrinter { public class ShoppingCartPrinter {
public static void main(String[] args) { public static void main(String[] args) {
Scanner scnr = new Scanner(System.in); Scanner scnr = new Scanner(System.in);
ItemToPurchase item1 = new ItemToPurchase();
ItemToPurchase item2 = new ItemToPurchase();
System.out.println("Item 1");
System.out.println("Enter the item name:");
item1.setName(scnr.nextLine());
System.out.println("Item 2");
System.out.println("Enter the item name:");
item2.setName(scnr.nextLine());
System.out.println("TOTAL COST");
System.out.println(item1.getName() + " " + item1.getQuantity() +
" @ $" + item1.getPrice() + " = $" +
(item1.getPrice() * item1.getQuantity()));
System.out.println(item2.getName() + " " + item2.getQuantity() +
" @ $" + item2.getPrice() + " = $" +
(item2.getPrice() * item2.getQuantity()));
System.out.println("\n Total: $" +
((item2.getPrice() * item2.getQuantity()) +
(item1.getPrice() * item2.getQuantity())));
scnr.close();
} }
} }