Results 1 to 3 of 3
  1. #1
    Inf1nity is offline Member
    Join Date
    Mar 2009
    Posts
    3
    Rep Power
    0

    Default Simple Text race game

    My class was given this as a project so I thought it would be a nice little program to share with other beginners. I had trouble with the switch statements but over all it was fun to create.
    Enjoy!

    // (1a) Create a Class Racer

    // (1b)create the main Method
    // (3a) In the main method
    // declare and initialize variables in main
    // declare a bolean variable, racing
    // declare and initialize an integer loop index, i to 0
    // declare and initialize an integer variable, speed to 0

    // (3b) delare a single dimension array, courseArray, of type string and initialize to
    // the following indexed values:
    // 0=Straightway, 1=Curve, 2=Straightway, 3=Curve,
    // 4=Curve, 5=Straightway, 6=Curve

    // (4a) construct a loop that runs at least once, exiting when the boolean variable
    // racing is false in the loop structure

    // (5a) Use the getIntValDialog method to assign a value to an integer variable, action
    // Message = "Select Action: 0-Stop Race 1-Accelerate 2-Slow"
    // Title = "Leg " + i + ": You are on a " + coursearray[i]

    // (4b) use a switch statement on the action value to do the following
    // (5b)if action = 0, Stop Race, set racing to false and speed to 0
    // (5c)if action = 1, to accelerate as follows
    // set racing to true
    // declare and assign an integer value to the variable, inchOfPedal
    // using the getIntValDialog method passing the arguments:
    // smessage = "Enter inches of Pedel"
    // title = "Press Pedal"
    // calculate speed using the PressGas method passing arguments
    // speed and inchOfPedal
    // (5d)if action = 2, to Break as follows:
    // set racing to true
    // declare and assign an integer value to the variable, duration
    // using the getIntValDialog method passing the arguments:
    // smessage = "Enter number of Seconds"
    // title = "Breaking"
    // calculate speed using the Break method passing arguments
    // speed and duration
    // (5e) otherwise, set a default option message as an error dialog telling the user to enter the range between 0 and 2

    // (5f) output the string "Leg" + i + " Speed is " + speed + " ft/sec "
    // increment i ... should i be preincremented or or incremented?

    // (4c) enter a conditional test for the end of the array that sets racing to false if it is exceeded

    // end loop structure

    // (5f) output the statement, Race over

    // end the program

    // end main

    // ************************************************** *********
    // (2a) create a private method, getIntValDialog, that returns an integer value and accepts
    // two string values as arguments
    // (6a) declare and initialize a string variable,sValue, to an empty string
    // Accept input to sValue from a Input Dialog using smessage, stitle, and a question icon as arguments
    // return the integer converted value of sValue
    // end getIntValDialog method

    // ************************************************** *********
    // (2b) create a PressGas method that returns an integer and accepts two integer arguments,
    // velocity and acceleration
    // (7b) return the value gotten by executing the PressGas method using velocity, acceleration and a default of 1
    // end PressGas

    // ************************************************** *********
    // (2c) create an overloaded PressGas method that returns an integer and accepts
    // three integer arguments, acceleration and seconds
    // (7a) Calculate new velocity as velocity (ft/sec) = velocity + (acceleration (ft/sqsec) * seconds (sec))
    // using a conditional statement, set a negative velocity to 0
    // return the current value of velocity
    // end overloaded PressGas method

    // ************************************************** *********
    // (2d) create a Break method that returns an integer and accepts integer arguments,
    // velocity and seconds
    // (6b)write a statement in the Break method that returns the a value from calling the
    // overloaded PressGass method
    // using values, -20 and the variable, seconds as arguments
    // end Break method

    // end Class Definition

  2. #2
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    We're not doing your homework...
    I die a little on the inside...
    Every time I get shot.

  3. #3
    Inf1nity is offline Member
    Join Date
    Mar 2009
    Posts
    3
    Rep Power
    0

    Default

    I already did this... I just posted it due to I had fun with it.

Similar Threads

  1. Replies: 3
    Last Post: 12-12-2008, 01:12 PM
  2. printing simple text as text on printer
    By Nicholas Jordan in forum Advanced Java
    Replies: 0
    Last Post: 12-01-2008, 02:42 AM
  3. Simple: Text to an image & save.
    By cilaes in forum Java 2D
    Replies: 4
    Last Post: 09-06-2008, 07:16 PM
  4. creating a text based game
    By Phobos0001 in forum New To Java
    Replies: 1
    Last Post: 02-12-2008, 05:35 PM
  5. Help with java text game
    By silvia in forum New To Java
    Replies: 6
    Last Post: 07-27-2007, 07:58 PM

Posting Permissions

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