This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2016/7/5

Shopping cart scenerio need explaining

divinity divinity

2016/7/5

#
hi i am practicing this object oriented programming where you have to program an online shopping cart, where you have to able to add and remove item to and from your cart, to be able to checkout your items and to also end when you have already checkout . I am receiving this error and would like to know how to fix it this error is in the if statement- if(intlist.contain (item)). the contain error is saying it cannot find symbol and the item error telling me to initialized. I have tried, the this.item but it didnt work. I have tried putting contain as a variable but it didnt work because i still was getting the error cannot find symbol
public static void main(String[]args)
    {
        System.out.println("Hello, Welcome to the Kaisley Grocery Store");
        
    }
    ArrayList<CartItem>shoppingCart = new ArrayList<CartItem>();
        
    Scanner userinput = new Scanner(System.in);
    
    //static NumberFormat fmt = new NumberFormat;
        
    ArrayList<Integer>intList = new ArrayList<Integer>();
    
       int userChoice =0;
        int intValue=0;
        int total=0;
        int input = 0;
        Integer item=0;
        String contain;
    
    public void start()
    {
        int userOption=0;
        
        do
        {
            showMenu();
            userOption = userinput.nextInt();
            chooseOption(userOption);
            
        }while(userOption!=6);
    }
    public void showMenu()
    {
        System.out.println("Choose the correct option");
        System.out.println("1: Add an item to your cart");
        System.out.println("2: Remove an item from your cart");
        System.out.println("3: View an item from your cart");
        System.out.println("4: End shopping and goa nd check out");
        System.out.println("5: Empty your cart");
        System.out.println("6: Exit program");
        System.out.println("Select a menu userOption");
    }
   
    public void chooseOption(int userOption)
    {
        if(userOption < 1 || userOption > 6)
        {
            System.out.println("Enter a value between 1 and 6");
        }
        else
        {
            switch(userOption)
            {
                case 1:
                    //adding an item to the cart
                    System.out.println("Please enter an item");
                    int input = userinput.nextInt();
                    Integer item = new Integer(input);
                    break;
                    
                case 2:
                    //remove item from the list
                    if(intList.contain(item))- the error is here. both contain and item is the errors am getting. contain(cannot find symbol-error) and item - item is not initialize- error am getting
                    {
                        intList.remove(item);
                        System.out.println(item+" has been removed");
                    }
                    else
                    {
                        System.out.println(item +"  was not found on the list");
                    }
                     break;
                
                 case 3:
                     // to view your item in the list
                     System.out.println("intList");
                     break;
                 
                 case 4:
                     //end shopping and add up total in cart
                     int i=0;
                     for(i = 0; i <intList.size(); i++)
                     {
                         item = intList.get(i);
                         total = total + intValue;
                     }
                
            }
        }
    }
danpost danpost

2016/7/5

#
Anytime you get a message like that ('cannot find'), you should first check the class in question where the symbol should be located (the List class of the java.util package, in this case) to make sure that the symbol is used correctly. Go here to check for the 'contain' symbol.
divinity divinity

2016/8/24

#
hi danpost I have since deleted that error and kinda redo the who thing over. while retaining some of the old codes. i have found an upgraded shopping online assignment that I have been practicing with for weeks now and which I am totally stuck for weeks now. this part of the question is where you have to add a customers to the shopping and that is where i am stuck. how do i add a customer to my shopping cart and do i have to make a constructor for it. and how do you add an item to the store. I tried using this Customer cust = new Customer but dont know if it work and i add it to an array list but didnt work or wasnt sure if it is the right thing. can u point me in the correct direction as to how to add a customers here is my codes. it has to have an arrayList for both the cart items and i would like to use the arrayList for the adding customers so that it can traverse through the arraylist . I have tried making a customers array list and now I am getting an error stated an arrayList cannot be converted to an arrayList. wat do i do to get dis to work. in the customer class i have import a idverifier and I am getting an error with the cart what is the proper way to import an idverifier. here is my codes. here is the shopping class codes
import java.util.Scanner;
import java.util.ArrayList;



public class ShoppingCart 
{
   public static void main(String[] args)
   {
       
   }
   
   private double itemPrice;
   private int capacity;
   private int CustomerNumber;
   private String CustomerName;
   private double totalprice;
   
   Customers cust = new Customers();
   
   private item[] cart = new item[capacity];
   
   public void shoppinCart()
   {
       capacity = 8;
       cart = new item[capacity];
       itemPrice = 0.0;
       
   }
   
   public void startShoppingCart()
   {
       int myChoice =0;
       
       do
       {
           showMenu();
           
       }while(myChoice !=8);
       
   }
   
   public void showMenu()
   {
       // store system menu that show the services available 
       System.out.println("Choose the option provided ");
       System.out.println("Press 1 to: Add item to the Shopping store");
       System.out.println("Press 2 to: Add a new customer to the store");
       System.out.println("Press 3 to: Add an item to the customer shopping cart");
       System.out.println("Press 4 to: Remove an item from the customer shopping cart");
       System.out.println("Press 5 to: View the item in the customer cart");
       System.out.println("Press 6 to: End shopping and go check out");
       System.out.println("Press 7 to: Empty customer shopping cart");
       System.out.println("press 8 to: Exit the program");
       
   }
       // adding item to the store 
    public void additemToStore(String itemNumber,String itemName, String itemType, String itemTitle,String itemAuthor,int quantity, double itemPrice)
    {
        int myChoice =0;
        String remainShopping = "y";
        Scanner userinput = new Scanner(System.in);
        ShoppingCart sc = new ShoppingCart();
        
        switch(myChoice)
        {
            case 1: 
                do
                {
                    System.out.println("Please enter item number");
                    itemNumber = userinput.next();

                    System.out.println("Please enter item name");
                    itemName = userinput.next();

                    System.out.println("Please enter  type of item");
                    itemType = userinput.next();

                    System.out.println("please enter the title of the item");
                    itemTitle = userinput.next();

                    System.out.println("Please enter the item author");
                    itemAuthor = userinput.next();

                    System.out.println("Please enter the quantity of the item");
                    quantity = userinput.nextInt();

                    System.out.println("Please enter the quantity of the item price");
                    itemPrice = userinput.nextDouble();

                    totalprice +=(quantity * itemPrice);
                    sc.additemToStore(itemNumber, itemName, itemType, itemTitle, itemAuthor, quantity, itemPrice);
                    System.out.println(sc.toString());

                    System.out.println("remain shopping (y/n)");
             
                }while(remainShopping.equals("y"));
                
                break;  
                
            case 2:
                //adding a customer to the cart
                ArrayList<Customers>Customers = new ArrayList<customers>();

this is the cart item class 
package CartItems;


class CartItem 
{
    //constructor without parameter
    public void Cartitems()
    {
        CartItem c = new CartItem();
       
    }
        private int quality =0;
        private double itemPrice;
        private int productID;
        private String productName;
        private String product;
       
    public void cartItem(String product, String productName, int productID, int quality, double itemPrice)
    {
        this.itemPrice = itemPrice;
        this.productName = productName;
        this.product = product;
        this.productID = productID;
        this.quality = quality;
    }
    //indicating the setter and getters;
    public double getitemPrice()
    {
        return itemPrice;
    }
    public void setitemPrice(double itemPrice)
    {
        this.itemPrice = itemPrice;
    }
    public String getproductName()
    {
        return productName;
    }
    public void setproductName(String productName)
    {
        this.productName = productName;
    }
    public String getproduct()
    {
        return product;
    }
    public void setproduct(String product)
    {
        this.product = product;
    }
    public int getproductID()
    {
        return productID;
    }
    public void setproductID(int productID)
    {
        this.productID = productID;
    }
      
this is the store class 
public class Store
{
    private String javaBooks;
    private String logoGame;
    private String SportsShoes;
    
    public String getJavaBooks()
    {
        return javaBooks;
    }
    public void setjavaBooks(String javaBooks)
    {
        this.javaBooks = javaBooks;
    }
    public String getlogoGame()
    {
        return logoGame;
    }
    public void setlogoGame(String logoGame)
    {
        this.logoGame = logoGame;
    }
    public String getSportsShoes()
    {
        return SportsShoes;
    }
    public void setSportsShoes(String SportsShoes)
    {
        this.SportsShoes = SportsShoes;
    }
    
this is the customer class
import cart.IdVerifier;

class Customers 
{
    private String CustomerName;
    private int CustomerNumber;
    private String CustomerID;
    
    Customers[] c = new Customers[5];
    
     public String getCustomerID()
    {
       
        IdVerifier idChecker = new IdVerifier();
        
        // check  if id is valid or not
        if(idChecker.validate(CustomerID))
        {
            System.out.println(" invalid ID");
        }
        else
        {
            System.out.println("Customer ID is invalid");
        }
        return CustomerID;
    }
     
    public String getCustomerName()
    {
        return CustomerName;
    }
    public void setCustomerName(String CustomerName)
    {
        this.CustomerName = CustomerName;
    }
    public int getCustomerNumber()
    {
        return CustomerNumber;
    }
    public void setCustomerNumber(int CustomerNumber)
    {
        this.CustomerNumber = CustomerNumber;
    }
}
    
danpost danpost

2016/8/25

#
I would think the first option given would be between adding a customer and exiting the program. Only after the first option is chosen would the other options become available.
divinity divinity

2016/8/25

#
okay another question. the thing is how do i add create and added automatically for a new customer which the shopping cart and it must be empty
danpost danpost

2016/8/26

#
divinity wrote...
okay another question. the thing is how do i add create and added automatically for a new customer which the shopping cart and it must be empty
The first option between a new customer and exiting the program can be given in the 'main' and if a new customer is chosen, a new shopping cart object can be created (being it would be a new shopping cart, it should already be empty).
divinity divinity

2016/8/27

#
hi danpost what I mean is this Add a new Customer. The system prompts to the system user for adding data for a new customer data. The customer data contains the following items: - customer No : holds an unique number of a customer. - customer name: holds a name of the course. - New Shopping cart will be create and added automatically for the new customer. The shopping cart will be empty. Enter customer number: Enter customer name: New shopping cart add to the customer Do you want add another customer (y/n)? The System will repeat adding another customer , if the user answer yes for the question " Do you want add another customer (y/n)? ". if the user select no, the system will return to the main menu showing it's services. how do i do this and this have to go in a loop in order for it to return to the main menu if the user say no, how do i accomplish
danpost danpost

2016/8/27

#
Then you would have something like this(pseudo code):
// in the main method
int selection = 0;
do
{
    selection = getMainSelection(); //  1 = new customer,  2 = exit 
    if (selection == 2) break;
    getCustomerData();
    do while (customerName != null) shopping();
}

// new methods
private void getCustomerData()
{
    customerNumber = getCustomerNumber();
    customerName = getCustomerName();
    cart = new ShoppingCart();
}

private void shopping()
{
    int optionSelected = 0;
    // print options
    optionSelected = getCustomerAction();
    if (optionSelected == 8) // exiting customer
    {
        customerName = null;
        return;
    }
    // act on other selections here
}
If customer checks out, 'customerName' will need to be set to 'null' there also.
divinity divinity

2016/9/5

#
hey danpost I have a question. if you have a customer and you want the customer to identify theirself, how do you import an idverifier through java. what is the correct way to import a idverifier i have something like this. import java.cart.idverifier and i am getting an error by the cart. dont know if that is the correct way. pray tell. i have a fair understanding of what you said above, but I need to add the customer first before, do I . I need to add the customers through an arraylist how do i accomplish dis,
danpost danpost

2016/9/5

#
divinity wrote...
i have something like this. import java.cart.idverifier
I do not think this class exists in the java package. Where did you come across this one: ? java.cart.idverifier ?
divinity divinity

2016/9/5

#
I saw it on a site while searching and just trying it to see how it work
danpost danpost

2016/9/5

#
divinity wrote...
I saw it on a site while searching and just trying it to see how it work
Well, the only valid importable packages are the 'greenfoot' package which greenfoot supplies and the 'java' packages which can be found here.
divinity divinity

2016/9/5

#
so that import cart.idverifier dont exit. okay, i have since erase it and how do i add a customer through an arraylist.
danpost danpost

2016/9/5

#
divinity wrote...
how do i add a customer through an arraylist.
Please elaborate as to what exactly you are wanting to do. The question is way to vague as to what you are wanting to do. Provide context as well and explain in detail. Also, you are assuming that an arraylist is what you are going to need. I am not quite so sure and cannot be without more information.
divinity divinity

2016/9/6

#
okay
You need to login to post a reply.