Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2011
    Rep Power

    Default Beginner Java Problem (Running Objects)

    Hi Guys,

    I am new to Java and have a problem that i cannot seem to grasp. I am using BlueJ.

    My problem is that I cannot seem to execute the code I have written. I need to make this code run as an object and I do not understand how to do this. I've spent a good 5 hours trying to fix this and I still cant understand how to fix it - any advice would be much appreciated!

    My code is below

    Java Code:
    import java.util.Scanner;
    public class Game
        public static void main(String[] args)
            Game game;
            Item item1;
            String itemName1;
            int itemPosition1, itemPosition2, itemPosition3;
            int itemValue1, itemValue2, itemValue3;
            game = new Game();
            item1 = new Item();
            Scanner keyboard;
            keyboard = new Scanner(;
            System.out.println("\fWould you like to play (e)asy or (h)ard mode? ");
            System.out.println("You selected easy mode.");
     System.out.print("Please enter item name: ");
            itemName1 = keyboard.nextLine();
            System.out.print("Please enter " + itemName1 + "'s initial position: ");
            itemPosition1 = keyboard.nextInt();
            System.out.print("Please enter the points value of " + itemName1 + ": ");
            itemValue1 = keyboard.nextInt();
    public class Item
        private String itemName;
        private int itemPosition;
        private int itemValue;
        public Item()
            itemName = "Unknown";
            itemPosition = 0;
            itemValue = 0;
        public void setItemName(String name)
            itemName = name;    
        public String getItemName()
            return itemName;
        public void setItemPosition(int position)
            itemPosition = position;    
        public void setItemValue(int value)
            itemValue = value;    

    Last edited by Fubarable; 04-24-2011 at 05:42 AM. Reason: code tags added

  2. #2
    f1gh is offline Banned
    Join Date
    Nov 2010
    Rep Power


    to begin with i don't know if this is due to copy paste but you don't have closing braces for the main method in class game and than you are missing the closing braces for the game class after the closing brace for Item class.

  3. #3
    Join Date
    Apr 2011
    Rep Power


    Ive just gone through the code, and saw that both of those issues were due to a poor copy paste job.

  4. #4
    powerpravin is offline Member
    Join Date
    Mar 2011
    Rep Power


    The code compiles on my machine without any errors but doesn't perform much. It halts after asking for a couple of inputs.

    What exactly do you want to achieve with this code?

  5. #5
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Atlanta, Georgia, US
    Rep Power

Similar Threads

  1. Beginner Java Modding Problem...
    By walkineagle in forum New To Java
    Replies: 3
    Last Post: 04-13-2011, 05:20 AM
  2. Objects & Classes - Beginner question
    By jonytek in forum New To Java
    Replies: 4
    Last Post: 02-09-2011, 01:49 PM
  3. Java Code running problem
    By socboy6579 in forum New To Java
    Replies: 11
    Last Post: 10-26-2010, 05:07 AM
  4. Problem running Java with XP Pro SP2
    By swarv in forum New To Java
    Replies: 16
    Last Post: 06-23-2010, 02:58 PM
  5. Replies: 0
    Last Post: 08-26-2009, 02:03 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts