4 Replies - 538 Views - Last Post: 07 April 2013 - 03:20 PM Rate Topic: -----

#1 Miab831  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 26-March 13

Retail sales assignment

Posted 05 April 2013 - 07:21 PM

Hi,

I'm new to programming as well as this forum. I was recently given an assignment to create a retail sales program which allows the user to shop, add items to their cart and have the items totaled upon check out. The instructor wants us to use several classes to create new objects for the cart, store, ect. I'm having a very difficult time tying everything together at the end. Here are the classes I have so far. She wants the main method written exactly as is which leads me to believe I should try to work bring everything together in the Store Class. Everything compiles so far and is kept together in one project. Attached is the problem statement. Thanks!


import java.util.*;

public class Store

{	
   private Item hammer;
	private Item yoga_mat;
	private Item apple;
	private Item balloon;
	private Item pillow;
	private String name;
	private int choice;
	UserIO menu = new UserIO ();
	
	public Store()
	{
		hammer = new Item();
		yoga_mat = new Item(0,"Yoga Mat",4.50,2);
		apple = new Item (0,"Apple",3.98,3);
		balloon = new Item (0,"Balloon",4.49,4);
		pillow = new Item (0,"Pillow",6.87,5);
	}
	
	public void makeMenu ()
	{
		choice = menu.promptForInt ("Press 1 to open the store or 2 to close. ", 1, 2);
	
		if (choice == 1) {
      System.out.println("Open");
		name = menu.promptForString ("Please enter your name ");
		System.out.println ("Hi " + name);
      }
      else if (choice == 2) {
        System.out.println("Closed");
		  System.exit(2);
   	}    
		else {
      System.out.println("You Have entered an incorrect value.");
      }
		}
		
  public void itemMenu ()
		{
		int i;
		Scanner input;
		input = new Scanner (System.in);
		System.out.println("\nMenu\n1:Hammmer $2.98\n2:Yoga Mat $4.50\n3:Apple $3.98");
		System.out.println("4:Balloon $4.49\n5:Pillow $6.87\n");
		System.out.println("\nPlease enter the item number you would like to purchase from the menu above.");
		i = input.nextInt ();
		
		String details = " ";

    	switch (i){ 
    	case 1:
		details = "Hammer(s)";
	 	break;
	 	case 2:
	 	details = "Yoga Mat(s)";
		break;
		case 3:
	 	details = "Apple(s)";
	 	break;
		case 4:
	 	details = "Balloon(s)";
	 	break;
		case 5:
	 	details = "Pillow(s)";
	 	break;
		}
		System.out.println("How many " + details + " would you like?");
		}
		}


import java.util.*;

public class Item
{
	private int qty;
	private String decs;
	private double cost;
	private int pn;

public Item ()
	{
	    qty = 0;
		 decs = "Hammer";
		 cost = 2.98;
		 pn = 1;
	}

public Item (int q, String d, double c, int p)
 	{
		qty = q;
		decs = d;
		cost = c;
		pn = p;
	}
	
	public int getQty () 
	{
	   return qty;
	}
	
	public String getDescription () 
	{
	   return decs;
	}
	
	public double getCost () 
	{
	   return cost;
	}

	public int getPn () 
	{
	   return pn;
	}
	
	public void setQty (int q)
	{
	   qty = q;
	}
	
	public void setDecs (String d)
	{
	   decs = d;
	}
	
	public void setCost (double c)
	{
	   cost = c;
	}
	
	public void setPn (int p)
	{
	 	 pn = p;
	}
	
	public void purchaseItem (int q)
	{
		qty = qty + q;
	}
}



import java.util.*;

public class UserIO
{
	public Scanner input;
	
	
	public UserIO ()
	{
		input = new Scanner (System.in);
	}
	
	
	public String promptForString (String s)
	{
		System.out.print (s);
		String name;
		name = input.next ();
		return name;
	}
	
		public int promptForInt (String s, int num1,int num2)
	{
		int size;
		System.out.print (s);
		size = input.nextInt ();
		return size;
	}
	
	
}



public class Tester
{
  
   private Store store;

   public Tester ()
	{
	    store = new Store ();
	}
	
	public void runStore ()
	{
	   store.makeMenu ();
	   store.itemMenu();

	}

////////////////////////////////////////
	public static void main (String [] s) 
	{
	   Tester t = new Tester ();
		t.runStore ();
	 }

}


Opps here is the statement if anyone is interested. Thanks.Attached File  retail program problem statement.pdf (181.25K)
Number of downloads: 45

Is This A Good Question/Topic? 0
  • +

Replies To: Retail sales assignment

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: Retail sales assignment

Posted 06 April 2013 - 12:45 AM

In the Store class, your methods are too complicated. Break them up into smaller, simpler pieces using other methods and/or shifting some of the burden to the partner classes.

Consider loading the store's inventory, the Item objects, into a collection of Items like an ArrayList. Then you can create methods that accept an argument collection of Items to create the shopping menu. Do something similar for the customer's shopping cart to show the items in the cart and the total cost of the items.

Beyond that, you need to explain the statement, "I'm having a very difficult time tying everything together at the end," so we know how to help. Not sure what difficulty you're having.
Was This Post Helpful? 0
  • +
  • -

#3 Miab831  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 26-March 13

Re: Retail sales assignment

Posted 07 April 2013 - 08:21 AM

I need to calculate the items the user wants at the end based on selection, quantity and price. I've hit a wall and am unsure how to bring it all together to do so.
Was This Post Helpful? 0
  • +
  • -

#4 Miab831  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 26-March 13

Re: Retail sales assignment

Posted 07 April 2013 - 02:32 PM

Got it to work! I broke it down into several more classes. I learned a lot!

import java.util.*;

public class Store

{	
	public Menu m;
	public Cart c;

	
	public void displayEntranceMenu ()
	{
	 Menu m = new Menu ();
	 m.makeMenu ();
	 m.itemMenu ();
   }
	
	public void displayitemSelection()
	{
	 Cart c = new Cart ();
	 c.itemSelection();
   }
}

		

import java.util.*;

public class Item
{
	private int qty;
	private String decs;
	private double cost;
	private int pn;

public Item ()
	{
	    qty = 0;
		 decs = "Hammer";
		 cost = 2.98;
		 pn = 1;
	}

public Item (int q, String d, double c, int p)
 	{
		qty = q;
		decs = d;
		cost = c;
		pn = p;
	}
	
	public int getQty () 
	{
	   return qty;
	}
	
	public String getDescription () 
	{
	   return decs;
	}
	
	public double getCost () 
	{
	   return cost;
	}

	public int getPn () 
	{
	   return pn;
	}
	
	public void setQty (int q)
	{
	   qty = q;
	}
	
	public void setDecs (String d)
	{
	   decs = d;
	}
	
	public void setCost (double c)
	{
	   cost = c;
	}
	
	public void setPn (int p)
	{
	 	 pn = p;
	}
	
	public void displayItem()
	{
	System.out.println("How many " + decs + "(s) would you like?");
	}
	
	public void purchaseItem (double c)
	{
	int i;
	double total;
	Scanner input;
	input = new Scanner (System.in);
	i = input.nextInt ();	
	total = i * c;
	System.out.println("Your total is " + total);
	
	 
	}
	
}



import java.util.*;

public class UserIO
{
	public Scanner input;
	
	
	public UserIO ()
	{
		input = new Scanner (System.in);
	}
	
	
	public String promptForString (String s)
	{
		System.out.print (s);
		String name;
		name = input.next ();
		return name;
	}
	
		public int promptForInt (String s, int num1,int num2)
	{
		int size;
		System.out.print (s);
		size = input.nextInt ();
		return size;
	}
	
	
}


import java.util.*;

public class Menu
{
	private int choice;
	private String name;
	UserIO io = new UserIO ();

public void makeMenu ()
	{
		choice = io.promptForInt ("Press 1 to open the store or 2 to close. ", 1, 2);
	
		if (choice == 1) {
      System.out.println("Open");
		name = io.promptForString ("Please enter your name ");
		System.out.println ("Hi " + name);
      }
      else if (choice == 2) {
        System.out.println("Closed");
		  System.exit(2);
   	}    
		else {
      System.out.println("You Have entered an incorrect value.");
      }
		}
		
		public void itemMenu ()
		{
		System.out.println("\nMenu\n1:Hammmer $2.98\n2:Yoga Mat $4.50\n3:Apple $3.98");
		System.out.println("4:Balloon $4.49\n5:Pillow $6.87\n");
		System.out.println("\nPlease enter the item number you would like to purchase from the menu above.");
		}
		

import java.util.*;

public class Cart
{
	private Item hammer;
	private Item yoga_mat;
	private Item apple;
	private Item balloon;
	private Item pillow;
	
	public Cart()
	{
		hammer = new Item();
		yoga_mat = new Item(0,"Yoga Mat",4.50,2);
		apple = new Item (0,"Apple",3.98,3);
		balloon = new Item (0,"Balloon",4.49,4);
		pillow = new Item (0,"Pillow",6.87,5);
	}
	
	public void itemSelection()
		{
		int i;
		Scanner input;
		input = new Scanner (System.in);
		i = input.nextInt ();

		switch (i){ 
    	case 1:
		hammer.displayItem();
		hammer.purchaseItem (2.98);
		break;
	 	case 2:
		yoga_mat.displayItem();
		yoga_mat.purchaseItem (4.50);
		break;
		case 3:
		apple.displayItem();
		apple.purchaseItem (3.98);
	 	break;
		case 4:
		balloon.displayItem();
		balloon.purchaseItem (4.49);
	 	break;
		case 5:
		pillow.displayItem();
		pillow.purchaseItem (6.87);
		break;
		}
		}
	
}


 Tester ()
	{
	    store = new Store ();
	}
	
	public void runStore ()
	{
	
		store.displayEntranceMenu ();
	   store.displayitemSelection();
		//store.displayitemSelection();

	}

////////////////////////////////////////
	public static void main (String [] s) 
	{
	   Tester t = new Tester ();
		t.runStore ();
	 }

}

Was This Post Helpful? 0
  • +
  • -

#5 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: Retail sales assignment

Posted 07 April 2013 - 03:20 PM

Congrats! Glad you figured it out.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1