Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Need advice in troubleshooting

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    9
    My Mood
    Stressed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Need advice in troubleshooting

    I have trouble troubleshooting my project and sincerely hoping someone will be able to point out my coding mistakes. I was looking to add an Item in the application which I am working on my project.

    I had attached my Item and ItemManager as well as the BidMenu. I did not attached my User and UserManager as they're both working perfectly, and so therefore I assumed either my ItemManager or my method to add item in BidMenu are wrongly-coded. Pls advice! Thank you.

    public class Item{
     
    	private String itemId;
    	private String itemDescription;
    	private User seller;
    	private double minBid;
     
    	public Item (String itemId, String itemDescription, User seller, double minBid){
    		this.itemId = itemId;
    		this.itemDescription = itemDescription;
    		this.seller = seller;
    		this.minBid = minBid;
    	}
     
    	public String getItemId(){
    		return itemId;
    	}
     
    	public String getItemDescription(){
    		return itemDescription;
    	}
     
    	public User getSeller(){
    		return seller;
    	}
     
    	public double getMinBid(){
    		return minBid;
    	}
     
    	public String toString(){
    		return "The item " +itemDescription +" has been added with ID " +itemId;
    	}
    }
    import java.util.*;
     
    public class ItemManager{
     
    	private UserManager userMgr;
    	private ArrayList<Item> itemList;
     
    	public ItemManager(){
    		itemList = new ArrayList<Item>();
    		itemList.add(new Item("I1","Java 6 book", userMgr.retrieveUser("plaura"),10.00));
    		itemList.add(new Item("I2","Baby pram", userMgr.retrieveUser("johna"),20.00));
    		itemList.add(new Item("I3","Water heater", userMgr.retrieveUser("mklee"),10.00));
    		itemList.add(new Item("I4","Wedding gown", userMgr.retrieveUser("johna"),50.00));
    	}
     
    	public ArrayList<Item> retrieveAll(){
    		return itemList;
    	}
     
    	public Item retrieveItem (String itemId) {
    		for (int i=0; i<itemList.size(); i++){
    			Item item = itemList.get(i);
    			if (item.getItemId().equals(itemId)){
    				return item;
    			}
    		}
    		return null;
    	}
     
    	public void addItem (String itemId, String itemDescription, User seller, double minBid){
    		Item item = new Item (itemId, itemDescription, seller, minBid);
    		itemList.add(item);
    	}
    }
    import java.util.*;
     
    public class BidMenu{
     
    	private ItemManager itemMgr;
    	private UserManager userMgr;
    	//private BidManager bidMgr;
    	private Scanner sc;
     
    	public BidMenu(){
    		itemMgr = new ItemManager();
    		userMgr = new UserManager();
    		//bidMgr = new BidManager();
    		sc = new Scanner(System.in);
    	}
     
    	public void display(){
    		System.out.println("=== Merlion Xchange :: Main Menu ===");
    		System.out.println("1. Add an Item");
    		System.out.println("2. Bid for an Item");
    		System.out.println("3. Add User");
    		System.out.println("4. List all users");
    		System.out.println("5. Close bid");
    		System.out.println("6. View Report");
    		System.out.println("7. Quit application");
    		System.out.print("\nEnter your option > "); 
    	}
     
    	public void processAddItem(){
    		System.out.println("\n=== Merlion Xchange :: Add Item ===");
    		System.out.print("\nEnter Item Description > ");
    		String itemDescription = sc.nextLine();
    		ArrayList<User> userList = userMgr.retrieveAll();
    		String userName = "";
    		ArrayList<Item> itemList = itemMgr.retrieveAll();
     
    		do {
    			System.out.print("\nEnter seller username > ");
    			userName = sc.nextLine();
    			if (userMgr.retrieveUser(userName) == null){
    				System.out.println("The username doesn't exist");
    			}
    		}while (userMgr.retrieveUser(userName) == null);
    		User seller = userMgr.retrieveUser(userName);
     
    		double minBid = 0;
    		do {
    		System.out.print("\nEnter minimum bid price > ");
    		minBid = sc.nextDouble();
    		if (minBid <= 0) {
    			System.out.println("Kindly enter a bid price greater than $0");
    		}
    		} while (minBid <= 0);
     
    		int listSize = itemList.size();
    		int newId = itemList.size()+1;
    		String itemId = "I"+newId;
    		itemMgr.addItem(itemId, itemDescription, seller, minBid);
    		/*for (int i= listSize; i<itemList.size(); i++){
    			Item item = itemList.get(i);
    			System.out.print(item.toString());
    		}*/
    		System.out.println(itemId);
    	}
     
    	public void processBidItem(){
    		System.out.println("\n=== Merlion Xchange :: Bid for Item ===");
    	}
     
    	public void processAddUser(){
    		System.out.println("\n=== Merlion Xchange :: Add User ===\n");
    		String userName = "";
    		double balance = 100.00;
    		ArrayList<User> userList = userMgr.retrieveAll();
     
    		do {
    			System.out.print("Enter username for the new user > ");
    			userName = sc.nextLine();
    			if (userMgr.retrieveUser(userName) != null){
    				System.out.println("The username already exists");
    			}
    		}while (userMgr.retrieveUser(userName) != null);
     
    		System.out.println("\nThe following user has been added:\n");
    		System.out.println("Username		Balance");
    		System.out.println("====================================");
    		int listSize = userList.size();
    		userMgr.addUser(userName, balance);
    		for (int i= listSize; i<userList.size(); i++){
    			User user = userList.get(i);
    			System.out.print(user.toString());
    		}
    		System.out.println();
    	}
     
    	public void processListAllUsers(){
    		System.out.println("\n=== Merlion Xchange :: List all users ===");
    		System.out.println("\nUsername		Balance");
    		System.out.println("====================================");
    		ArrayList<User> userList = userMgr.retrieveAll();
    		for (int i=0; i<userList.size(); i++){
    			User user = userList.get(i);
    			System.out.print(user.toString());
    		}
    		System.out.println();
    	}
     
    	public void processCloseBid(){
    		System.out.println("\n=== Merlion Xchange :: Close Bid ===");
    	}
     
    	public void processListHighestPoints(){
    		System.out.println("\n=== Merlion Xchange :: View Report ===");
    		System.out.println("\nUser(s) with the highest number of Xchange points:");
    		System.out.println("\nUsername	Xchange Points");
    		System.out.println("====================================");
    	}
     
    	public void readOption(){
    		int option;
     
            do {
                display();
                option = sc.nextInt();
                sc.nextLine();  
     
                switch(option){
                    case 1:processAddItem();                 
    					   break;
                    case 2:processBidItem();                  
    					   break;
                    case 3:processAddUser();
                           break;
                    case 4:processListAllUsers();
                           break;
                    case 5:processCloseBid();
                           break;
    				case 6:processListHighestPoints();
                           break;
    				case 7:System.out.println("\nThank you for using Merlion Xchange Bidding Items Application!\n");
                           break;
                    default:System.out.println("Please enter a valid option (1 to 7)!");
                }
            } while(option != 7);
        }
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Need advice in troubleshooting

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    9
    My Mood
    Stressed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Need advice in troubleshooting

    Thank you, KevinWorkman! It is working now

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Need advice in troubleshooting

    Thank copeg, he's the one that wrote the article! I'm glad you got it sorted out though.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Need some serious advice
    By Rituparna in forum The Cafe
    Replies: 4
    Last Post: September 25th, 2013, 08:26 AM
  2. Some Simple Advice?
    By Diamond Fowl in forum AWT / Java Swing
    Replies: 2
    Last Post: April 30th, 2011, 09:36 PM
  3. need for some advice
    By kasiopi in forum AWT / Java Swing
    Replies: 6
    Last Post: January 26th, 2011, 10:34 AM
  4. A little advice please:
    By SDKC in forum Java Theory & Questions
    Replies: 1
    Last Post: December 8th, 2010, 08:15 PM
  5. i need some advice ....
    By mdstrauss in forum Java Theory & Questions
    Replies: 8
    Last Post: July 24th, 2009, 02:29 PM