Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA PROGRAMMING Vic\'s Sweetshop sells cheesecake. The cheesecakes are sold in

ID: 3586191 • Letter: J

Question

JAVA PROGRAMMING

Vic's Sweetshop sells cheesecake. The cheesecakes are sold in bite size (3 inch), small (9 inch), and large (12 inch). They are also sold plain or with strawberry, raspberry, caramel, or chocolate topping.  Vic has decided it costs more to make a cheesecake with toppings than a plain cheesecake and he needs to make sure he charges customers appropriately. Price per inch will now be determined as follows:

plain - 0.50 per inch

strawberry - 1.25 per inch

raspberry - 1.15 per inch

caramel - 0.75 per inch

chocolate - 0.85 per inch

Vic wants to provide his customers with a receipt that contains all the information about their cheesecake and the total purchase price. I need a solution that will allow the customer to choose a size and topping. Then display the "receipt" back to the customer that includes their choices and total cost.  

For this weeks program I need to add to the functionality. Be sure the user/customer enters a valid option for the size and a valid option for the topping before proceeding with the program, meaning continue to ask them for a size or a topping until the answer is valid. This program should continue to run until the customer has ordered all the cheesecakes they want. When the user is done entering cheesecake orders display a receipt that lists each cheesecake order, the price of that cheesecake and the total for order.

Explanation / Answer

Please find the below code that matches your rquirement.

ShoppingCart.java

package com.shop;

import java.util.Scanner;

public class ShoppingCart {

public static void main( String [] args) {

Scanner input = new Scanner(System.in);

ShoppingList myList = new ShoppingList();

int userOpt = 0;

int secondOpt=0;

while (userOpt != 5) {

System.out.println("");

System.out.println("----- Welcome to Vic sweet shop------");

System.out.println("----- Select size of cake------");

System.out.println("(1) Bite Size. ");

System.out.println("(2) Small Size. ");

System.out.println("(3) Large. ");

System.out.println("(4) Display List. ");

System.out.println("(5) Exit. ");

userOpt = input.nextInt();  

  

if(userOpt==1 || userOpt==2 || userOpt==3){

System.out.println("");

System.out.println("----- Select topping for the Cake------");

System.out.println("(1) Plain ");

System.out.println("(2) Strawberry. ");

System.out.println("(3) Respberry. ");

System.out.println("(4) Caramel. ");

System.out.println("(5) Chocloate. ");

secondOpt = input.nextInt();

System.out.println(userOpt+":::User selection:::"+secondOpt);

  

myList.addItem(userOpt,secondOpt);

}

if (userOpt == 4) {

myList.displayItem();

}

  

}

}

}

ShoppingList.java

package com.shop;

import java.util.ArrayList;

import java.util.*;

import java.util.Scanner;

public class ShoppingList {

List<String> sizelist = new ArrayList<String>();

List<String> toppingList = new ArrayList<String>();

Map<Integer,Double> priceMap = new HashMap<Integer,Double>();

Map<Integer,Integer> sizeMap = new HashMap<Integer,Integer>();

ShoppingList(){

sizelist.add("Bite Size");

sizelist.add("Small Size");

sizelist.add("Large Size");

toppingList.add("Plain");

toppingList.add("Strawberry");

toppingList.add("Respberry");

toppingList.add("Caramel");

toppingList.add("Chocloate");

priceMap.put(1, 0.50);

priceMap.put(2, 1.25);

priceMap.put(3, 1.15);

priceMap.put(4, 0.75);

priceMap.put(5, 0.85);

sizeMap.put(1, 3);

sizeMap.put(2, 9);

sizeMap.put(3, 12);

}

ArrayList<ShoppingItem> list = new ArrayList<ShoppingItem>();

//Add a new ShoppingItem to the list

public void addItem(int size,int topping)

{

System.out.println();

//System.out.println("enter in the name of your item");

Scanner keyboard = new Scanner(System.in);

String ItemName = "";

String toppingName = toppingList.get(topping-1);

String sizeName = sizelist.get(size-1);

ItemName = toppingName+" "+sizeName;

  

//System.out.println("enter in the price of your item");

double ItemPrice = 0.0;

int inchsize = sizeMap.get(size);

double inchCost = priceMap.get(topping);

ItemPrice = inchsize*inchCost;

System.out.println("enter in the Qty of your item");

int ItemQty = keyboard.nextInt();

double totalCost=ItemPrice*ItemQty;

ShoppingItem Item = new ShoppingItem(ItemName, ItemPrice,

ItemQty,totalCost);

list.add(Item);

System.out.println("Item Added");

}

//Display list and total number of items.

public void displayItem(){

System.out.println( list.size()+ " items. ");

for (ShoppingItem x : list) {

System.out.println(x.toString());

}

}

}

ShoppingItem.java

package com.shop;

public class ShoppingItem {

private String ItemName;

private double ItemPrice;

private int ItemQty;

private double totalCost;

public double getTotalCost() {

return totalCost;

}

public void setTotalCost(double totalCost) {

this.totalCost = totalCost;

}

public void setItemPrice(double itemPrice) {

ItemPrice = itemPrice;

}

public ShoppingItem()

{

ItemName = "Fruit";

ItemPrice = 100;

ItemQty = 1;

totalCost = 100;

}

public ShoppingItem(String ItemName, double ItemPrice, int ItemQty, double totalCost )

{

this.ItemName = ItemName;

this.ItemPrice = ItemPrice;

this.ItemQty = ItemQty;

this.totalCost = totalCost;

}

public String getItemName() {

return ItemName;

}

public double getItemPrice() {

return ItemPrice;

}

public double getItemTotalPrice() {

return ItemPrice * ItemQty;

}

public int getItemQty() {

return ItemQty;

}

public void setItemName(String ItemName)

{

this.ItemName = ItemName;

}

public void setItempPrice(double ItemPrice)

{

this.ItemPrice = ItemPrice;

}

public void setItemQty(int ItemQty)

{

this.ItemQty = ItemQty;

}

@Override

public String toString()

{

String state = ItemName + " - €" + ItemPrice + " x " + ItemQty+ " x " + totalCost;

return state;

}

}