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 6 of 6

Thread: java Bluej Exercise

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy java Bluej Exercise

    i think i done step one on bluej but im stuck on step 2 which says add two fields which stores the nickname.....
    this really makes me confuse

    below is what i have to be doing codes on bluej
    Step 1
    The basic Game class should have
    • three fields, title, objective (of the game) and cost (in pence of each download);
    • a constructor, which allows you to pass arguments to initialise these three attributes;
    • accessor and mutator methods for each field as well as a printReport() method which outputs the title and objective of the game as well as the cost of each download.

    Step 2: adding functionality to the Game class.
    For this step, you should
    • write a method download() which allows a user to "download a copy of the game". Since this is only a model, at the moment, all we do is output a message which congratulates the user on their download and reminds them of the cost. It also updates the value of a new field noOfDownloads;
    • add two fields which store the nickname of the player with the best score as well as the score itself respectively;
    • write a method checkScore() which, when given a player's score and name, checks to see whether that particular score is the best score to date and if so, replaces the best score with this new score and also replaces the relevant nickname.
    Do not forget to amend your printReport() method to include the new information collected in this step.

    Step 3
    So far, testing of the program has been quite repetitive and always starts from scratch. However, we could introduce a default constructor with the field values hard-coded. This means that when we create our object and then call this default constructor, it is as though our object has been in existence for some time. This will help particularly with your testing. Introduce a second, default constructor now.
    Then
    • write a method calculateEarnings() which calculates how much money this particular game has earnt its writer;
    o do not add an extra field to keep track of the running earnings total.
    • Now amend your printReport() method to include this new information i.e. the earnt money, again without creating any new field(s).


    Step 4
    Introduce a new class, called Manager, to the project. Its purpose is to represent the manager of the game. It should have
    • two fields surname and managerID;
    • a suitable constructor and accessor methods.
    Next add a new field gameManager, of type Manager, to the Game class. Modify Game's constructor by giving it an additional parameter so that the new field can be initialised when the constructor is called.

    To test your code
    • create a Manager object;
    • create a Game object, and pass to its constructor
    o values for the three fields (as usual);
    o the identifier for the Manager object e.g. manager1 (or, more easily, click on the Manager object on the Object Bench);
    • inspect the Game object using the Object Inspector. If you double click on the gameManager field, a new Object Inspector window will open and you should see the fields of the Game object you created -- this will confirm that your code for Step 4 is working correctly.

    Now amend the printReport()method of the Game class so that it also outputs the surname of the manager.


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: java Bluej Exercise

    With a set of instructions like that I would think you could get something done before running into problems. Show what you have done so far. Without your code how are we supposed to help you add to it for step 2?

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java Bluej Exercise

    ok these are the codes that i have done so far for step 2.



    public Game(String setNickName, int setScore, int setBestScore)
    {
    // user sets the name
    nickName = setNickName;
    //user sets the type of holiday
    bestScore = setBestScore;
    //a method is called to set the price
    score = setScore;
    }

    on the method below for checking the checkscore() i dont know why im getting the error:

    public void checkScore(String newNickName, int newScore, int newBestScore)
    {
    if ( bestScore== (score))
    {
    System.out.println("********************");
    System.out.println("This is your best Score" +bestScore);
    System.out.println("********************");
    }

    else if (bestScore > (score))

    {
    System.out.println("****************************** ");
    System.out.println("Best Score has been replaced to New Score");
    System.out.println("****************************** ");
    }


    }


    /**
    * Prints out a report
    *
    */
    public void printReport()
    {
    System.out.println("##################");
    System.out.println("Title:" + title);
    System.out.println("Objective:" + objective);
    System.out.println("Cost " + cost + " pence.");
    System.out.println("##################");

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: java Bluej Exercise

    Please see the announcements page for instructions on the use of code tags.



    on the method below for checking the checkscore() i dont know why im getting the error:
    What is the error? Exact wording of the error is important. Always copy-paste the error when asking questions about it.



    You appear to be working on the third section of Step 2. The third section of Step 2 is dependent on the second section of Step 2 being completed before the third.

  5. #5
    Junior Member
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java Bluej Exercise

      on step 2 this is what i have done for it and its the third bullet point.
     
    these are the codes that i have done so far do you think it is right???
     
     
     public void Game(String newNickName, int newScore, int newBestScore)
        {
            // user sets the name
            nickName = newNickName;
            //user sets bestscore
            bestScore = newBestScore;
            //a method is called to set the score
            score = newScore;
        }
     
    public void checkScore(String newNickName, int newScore, int newBestScore)
       {
            if ( bestScore== (score))
            {
                System.out.println("********************");
                System.out.println("This is your best Score" +bestScore);
                System.out.println("********************");
            }
     
            else if (bestScore > (score))
     
            {
                System.out.println("******************************");
                System.out.println("Best Score has been replaced to New Score");
                System.out.println("******************************");
            }
     
     
        }
    }
    Last edited by kiara4; October 27th, 2012 at 02:59 PM.

  6. #6
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: java Bluej Exercise

    these are the codes that i have done so far do you think it is right???
    Does it compile? Does it run? Are there any errors? Does it produce the desired results for all test cases?

    Did you expect me to test it? If so you will need to provide more than a snippet of code. This project is designed for some steps to build on previous steps. Without seeing the rest of the code we have no way to tell if these snippets of code do what you wanted.

Similar Threads

  1. Oracle's answer to exercise 1 in Interfaces - Java Tutorials
    By MaXER in forum Object Oriented Programming
    Replies: 8
    Last Post: September 24th, 2012, 02:01 AM
  2. Bluej issue
    By BeardedAxeWound in forum Object Oriented Programming
    Replies: 16
    Last Post: August 26th, 2012, 03:07 AM
  3. Java Programming Exercise
    By Garron5899 in forum Loops & Control Statements
    Replies: 5
    Last Post: July 27th, 2012, 08:12 AM
  4. Make brick wall using BlueJ
    By boumasmoud in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 3rd, 2011, 04:32 PM
  5. JAVA exercise
    By gmilan in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 13th, 2010, 02:30 PM