Requirements: Input: Create a shopping list of 7 items (in an array). Take input
ID: 3850721 • Letter: R
Question
Requirements:
Input: Create a shopping list of 7 items (in an array).
Take input from the user that puts the shopping item name and priority into an array, multiple arrays ok.
Set the price for all the items in the shopping list down to the penny. (Make sure the total of the items > $100.00)
Sort the items in the list by order of priority
Present the items back to the user and have the user determine the order of importance for the item to purchase.
Only have one entry of any type in the list, list entry name (ex. Apple). If the user tries to add the same item twice tell the user that it is already on the list.
Set the price, cost, of each item down to the penny.
Now go shopping , purchase as many items on the list by priority, using $59.00
Purchase the highest priority items first then go to the lower priority items and purchase them as needed, minimizing the amount of money left over.
Display the list of what was purchased, its price, and what wasn’t purchased, and its price (what could be used for the next shopping list).
Program must have:
Create an equals method for every physical class.
Make class attribute private
Have get and set methods to access items in the shopping list
Have defined class constructors
Include multiple classes(you determine what classes to create, what make sense)
Include pseudo code, UML diagram, test plans, and .java file
Explanation / Answer
Shopping.java
------------------
package venkanna;
import java.util.ArrayList;
import java.util.Scanner;
class Shopping
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
ShoppingList List = new ShoppingList();
int Opt = 0;
while (Opt != 3)
{
System.out.println("--------------------------");
System.out.println("----- Shopping List------");
System.out.println("1.Add an item to the list. ");
System.out.println("2.Display list and total number of items. ");
System.out.println("3.Exit. ");
Opt = sc.nextInt();
if (Opt == 1)
{
List.addItem();
}
if (Opt == 2)
{
List.displayItem();
}
}
sc.close();
}
}
class ShoppingList
{
ArrayList<ShoppingItem> obj=new ArrayList<ShoppingItem>();
public void addItem()
{
System.out.println();
System.out.println("Enter the name of item");
Scanner sc = new Scanner(System.in);
String ItemName = sc.nextLine();
System.out.println("Enter the price of your item");
double ItemPrice = sc.nextDouble();
System.out.println("Enter the Priority of your item");
int ItemQty = sc.nextInt();
ShoppingItem Item = new ShoppingItem(ItemName, ItemPrice,ItemQty);
obj.add(Item);
// sc.close();
}
public void displayItem()
{
System.out.println( obj.size()+ " items. ");
for (ShoppingItem x : obj)
{
System.out.println(x.toString());
}
}
}
class ShoppingItem
{
private String ItemName;
private double ItemPrice;
private int ItemQty;
public ShoppingItem()
{
ItemName = "Apple";
ItemPrice = 100;
ItemQty = 1;
}
public ShoppingItem(String ItemName, double ItemPrice, int ItemQty )
{
this.ItemName = ItemName;
this.ItemPrice = ItemPrice;
this.ItemQty = ItemQty;
}
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;
}
public String toString()
{
String state = ItemName + " - $" + ItemPrice + " x " + ItemQty;
return state;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.