Results 1 to 17 of 17
  1. #1
    Spidermonkey is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default Something is Wrong O.o

    Hi,
    everyone :)

    i was just wondering i am haveing some trouble with a "project" i have been working on. It seems my code's are ummmm..... yeah xD , and i been working on this for about a week lol ><' and i am still not getting it to work right would someone perhaps be able to help me pls ^^ :) ~ code is ~

    mport java.io.Console;
    import java.io.Reader;

    public class ReverseGear {
    /**
    * @param arg
    */

    static int[] lapTime;

    static int avgLapTime;

    public static void main(String[] args)

    {

    System.out.println("Welcome to Reverse Gear");
    System.out.println("Reading lap times for 10 laps");
    System.out.println(" what was the time for Lap 1");
    System.out.println("what was the time for Lap 2");
    System.out.println(" what was the time for Lap 3");
    System.out.println("what was the time for Lap 4");
    System.out.println(" what was the time for Lap 5");
    System.out.println("what was the time for Lap 6");
    System.out.println(" what was the time for Lap 7");
    System.out.println("what was the time for Lap 8");
    System.out.println(" what was the time for Lap 9");
    System.out.println("what was the time for Lap 10");
    int lapNumber0Fix; // intialises int variable for fixing the lap number up

    lapTime = new int[10]; // sets the array sizes to 10
    for(int lapNumber = 0; lapNumber < 10; lapNumber = lapNumber + 1)
    {lapNumber0Fix = lapNumber + 1; // makes it show the correct lap number is shown to user
    System.out.print("Please enter the lap time for lap " + lapNumber0Fix + " ");
    int enteredLapTime = getValidNumber(60,240); // creates an int variable and send the entered number to the GetValidNumber class to check if number is correct, also sends the values 60 and 240 to that class aswell, lap can not be under 60 and more then 240
    lapTime[lapNumber] = enteredLapTime; // places the entered lap number into the array

    }

    highestLapTime(); // goes to te highestLapTime / get highest time

    lowestLapTime(); // goes to the lowestLapTime / get lowest time

    averageTime(); // goes to averageTime class / to calculate the avrage time

    difFromAvg(); // goes to diffferent to avrage times

    System.out.println("Thank you for using Reverse Gear");

    }

    //checks if number entered is a valid number. Wont exit loop till valid numbered is entered

    public static int getValidNumber(int min , int max ) // used min and max in case in the future someone wanted to change the min and max values

    {

    ; num();

    ConsoleReader console = new ConsoleReader();
    console.readInt();
    while (num() < 60 || num() > 240)
    {System.out.print("The lap time must be within " + min + "..." + max + ". Please re-input:");
    console.readInt();

    }

    return num();

    }

    // Finds the highest lap time

    private static int num() {

    return (System.input);
    }

    public static void highestLapTime() {
    }

    {

    int highestTime = lapTime[0]; // sets the variable to the first number in the array

    int highestLap = 0; // sets the lowest lap to 0

    for (int a = 0; a < 10; a = a + 1) // loops 10 times

    {

    if (lapTime[a] >= highestTime) // checks to the see if the amount in the array is higher then the number stored in the highestTime varible

    {

    highestTime = lapTime[a]; // sets the highestTime variable to the size of the current array size.

    highestLap = a + 1; // sets the highestLap variable to the current loop number, adds one to show lap number later

    }

    }

    System.out.println("The Highest lap time was " + highestTime + " this was on lap " + highestLap);

    }

    // Finds the lowest lap time

    public static void lowestLapTime()

    {

    int lowestTime = lapTime[0]; // sets the variable to the first number in the array

    int lowestLap = 0; // sets the lowest lap to 0

    for (int b = 0; b < 10; b = b + 1) // loops 10 times

    {

    if (lapTime[b] <= lowestTime) // checks to the see if the amount in the lapTime array is less then the time stored the lowestTime variable

    {

    lowestTime = lapTime[b]; // sets the variable lowestTime to the current lap time

    lowestLap = b + 1; // sets the lowest lap variable to the current loop number, adds one to show lap number later

    }

    }

    System.out.println("The Lowest lap time was " + lowestTime + " this was on lap " + lowestLap);

    }

    // calculates average time it took to do a lap

    public static void averageTime()

    {

    int totalLapTime = 0; // sets totalLapTime to 0 so that more numbers can be added

    for (int avgLap = 0; avgLap < 10; avgLap = avgLap + 1)

    {totalLapTime = totalLapTime + lapTime[avgLap]; // adds the lapTime to the other lap times

    }

    avgLapTime = totalLapTime / 10; // once all the lap times are added together this calculates the average lap time

    System.out.println("The average Lap Time was " + avgLapTime);

    }

    // calculates the difference for the average time, either above or below

    public static void difFromAvg()

    {

    for (int x = 0; x < 10; x = x + 1) //loops ten times to get the lap times from the array, change x later to something more appropiate.

    {

    int loopFix = x + 1; // makes it so that the correct lap is shown to the user

    if (lapTime[x] > avgLapTime) // checks to see if laptime is greater then average time

    {

    System.out.print("The time for lap ");

    System.out.print(loopFix);

    System.out.print(" was ");

    System.out.print(lapTime[x]);

    System.out.print(" this was ");

    System.out.print(lapTime[x] - avgLapTime); // takes the average lap time away from the lap time

    System.out.print(" seconds above the average Lap time");

    System.out.println("");

    } else if (lapTime[x] < avgLapTime) // checks to see if lap time is below lap average

    {

    System.out.print("The time for lap ");

    System.out.print(loopFix);

    System.out.print(" was ");

    System.out.print(lapTime[x]);

    System.out.print(" this was ");

    System.out.print(avgLapTime - lapTime[x]);

    System.out.print(" seconds below the average Lap time");

    System.out.println("");

    } else if (lapTime[x] == avgLapTime) //checks to see if lap time is equal to average time

    {

    System.out.print("The time for lap ");

    System.out.print(loopFix);

    System.out.print(" was ");

    System.out.print(lapTime[x]);

    System.out.print(" this was ");

    System.out.print(avgLapTime - lapTime[x]);

    System.out.print(" seconds below or above the average Lap time");

    System.out.println("");

    }

    }

    }

    }
    Last edited by Spidermonkey; 11-13-2010 at 05:52 AM. Reason: didnt put in code, :(

  2. #2
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Quote Originally Posted by Spidermonkey View Post
    i was just wondering i am haveing some trouble with a "project" i have been working on. It seems my code's are ummmm..... yeah xD , and i been working on this for about a week lol ><' and i am still not getting it to work right would someone perhaps be able to help me pls ^^ :)
    Hm, my magic eight ball tells me that there's an error on line 42 of your code. Hope this helps!

    I love mind reading exercises, by the way!

  3. #3
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Thanks for posting the code, but now you've got us guessing what the problem is. So what's wrong with it? Does it compile? Does it make the dog howl or have the neighbors call the police? Any error messages? Is it not doing something it should be doing? Is it doing something it shouldn't be doing?

    Suerte amigo! :)

  4. #4
    Spidermonkey is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default ops :) forgot to say

    what it was "supposed" to do was to
    get input from the person in a range off 60~240 ,
    then calculate the times for each Lap in min:sec:mils:
    then return which was the highest and quickest lap,
    but it jams up and only says "times for lap one" and doesnt ask for any other laps. Or can put in any more input it keeps erroring and not doing right

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,440
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Spidermonkey View Post
    Java Code:
    System.out.println("Welcome to Reverse Gear");
    System.out.println("Reading lap times for 10 laps");
    System.out.println(" what was the time for Lap 1");
    System.out.println("what was the time for Lap 2");
    System.out.println(" what was the time for Lap 3");
    System.out.println("what was the time for Lap 4");
    System.out.println(" what was the time for Lap 5");
    System.out.println("what was the time for Lap 6");
    System.out.println(" what was the time for Lap 7");
    System.out.println("what was the time for Lap 8");
    System.out.println(" what was the time for Lap 9");
    System.out.println("what was the time for Lap 10");
    Whatever the rest of your code does, this part most certainly isn't correct; have you tried it?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Spidermonkey is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default

    yeah it reads the following "what is the lap times for lap 1 ~ 10, but input some reason i cant do :/ , Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    Syntax error on token "int", invalid Expression

    at ReverseGear.num(ReverseGear.java:72)
    at ReverseGear.getValidNumber(ReverseGear.java:54)
    at ReverseGear.main(ReverseGear.java:31), are my errors :/

    what i wanted it to do was "what is the lap time for lap 1" then the person types in a number 60~240 , then it stores that number and asks
    "what was the time for lap 2" , etc through to lap 10 . Then it took the fastest / slowest and stated: Lap %num, was the fastest time @ min:sec: mil:. and average time to complete laps.
    Last edited by Spidermonkey; 11-13-2010 at 12:21 PM. Reason: forgot details.

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,440
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Spidermonkey View Post
    yeah it reads the following "what is the lap times for lap 1 ~ 10, but input some reason i cant do :/ , Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    Syntax error on token "int", invalid Expression

    at ReverseGear.num(ReverseGear.java:72)
    at ReverseGear.getValidNumber(ReverseGear.java:54)
    at ReverseGear.main(ReverseGear.java:31), are my errors :/

    what i wanted it to do was "what is the lap time for lap 1" then the person types in a number 60~240 , then it stores that number and asks
    "what was the time for lap 2" , etc through to lap 10 . Then it took the fastest / slowest and stated: Lap %num, was the fastest time @ min:sec: mil:. and average time to complete laps.
    Don't try to run your code because (as it says) it has compilation errors. Compile it again and carefully read the compiler error diagnostic messages and fix the errors one by one (compilation doesn't cost anything). Your last paragraph is just wishful thinking for now.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    Spidermonkey is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default

    thanks for input ^^ just courious , this is my frist java assignment ^^; , and well never really had chance to use java before was just thrown into it lol with out much teaching........ how would i make it go like System.out.println("Please enter the time for lap 1");
    and allow the user to enter a number between 60~204 ^^; ..
    any tips would be much appreated since it always tells me. import java.util.Scanner / ConsoleReader not available even though its there ><

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,440
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Spidermonkey View Post
    thanks for input ^^ just courious , this is my frist java assignment ^^; , and well never really had chance to use java before was just thrown into it lol with out much teaching........ how would i make it go like System.out.println("Please enter the time for lap 1");
    and allow the user to enter a number between 60~204 ^^; ..
    any tips would be much appreated since it always tells me. import java.util.Scanner / ConsoleReader not available even though its there ><
    I don't know about the ConsoleReader class but the Scanner class definitely exists (in the java.util package since Java 1.5). Personally I'd create a little method and pass it a prompt String as well as the min and max numbers allowed as parameters. The method returns a valid number, if invalid the method tells the user and asks more input. Something like this:

    Java Code:
    public static int getNumber(String prompt, int min, int max) {
       int result;
       BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
    
       while (true) { // keep on trying ...
          System.out.print(prompt);
          System.out.flush();
          try {
             result= Integer.parseInt(br.readLine());
             if (result >= min && result <= max) return result;'
             System.out.println(result+" not in the range "+min+"..."+max);
          }
          catch (Exception e) {
             System.out.println("incorrect input");
          }
       }
    }
    This is from the top of my head so no warranties at all ;-)

    kind regards,

    Jos
    Last edited by JosAH; 11-14-2010 at 08:36 AM. Reason: not that it matter much but corrected a little blooper
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    Javawizard is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default

    rmit assignment... lol

  11. #11
    Spidermonkey is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Unhappy yeah...

    used to play with this kinda stuff about 8-10 years ago.... and through never really owning a computer after i cooked my old one... with something,...
    tried to get back into it. ><; and my memory is fried ><;;; , atm .. so i getting lost lol ><; , and my Scanner and my Console reader always has the (!), please remove things which arnt being used.... next to it lol

    back when i was doing this i was taught how to do it useing the NWN, Bioware program for the gameing side... and going to this "Alice" . they had us useing is completely different (drop and drag ) ,
    in comparason to useing the Bioware one which was an object one aswell, so thats why this is confuseing to me. I just didnt see the point in teaching from "Alice" when the other one is soo much better, and you would have been learning C++/Java , from the start instead of being just droped into it....
    Last edited by Spidermonkey; 11-14-2010 at 12:50 AM. Reason: more on stuff,

  12. #12
    Spidermonkey is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default ok so i sortened it ^^;

    this is a shortened version of the longer one, but the problem it is haveing now is with the statements ><; i wanted it to reask the quesstions if they chose over 240 and under 60, it asks again if they chose under 60, but it doesnt seem to work right this is it.

    import javax.swing.JOptionPane;


    public class pane {

    /**
    * @param args
    */
    static int num = 240;
    public static void main(String[] args) {
    String inputValue = JOptionPane.showInputDialog("Please enter the lap time for lap 1");
    System.out.println(); // Message to the user.
    if (num > 60) {
    System.out.println("Please enter a number between 60-240");
    String inputValue11 = JOptionPane.showInputDialog("Please enter the lap time for lap 1");
    } else {
    System.out.println("");
    String inputValue11 = JOptionPane.showInputDialog("Please enter the lap time for lap 1");
    }
    String inputValue1 = JOptionPane.showInputDialog("Please enter the lap time for lap 2");
    if (num > 60) {
    System.out.println("Please enter a number between 60-240");
    String inputValue11 = JOptionPane.showInputDialog("Please enter the lap time for lap 2");
    } else {
    System.out.println("");
    String inputValue11 = JOptionPane.showInputDialog("Please enter the lap time for lap 2");
    }
    String inputValue2 = JOptionPane.showInputDialog("Please enter the lap time for lap 3");
    if (num > 60) {
    System.out.println("Please enter a number between 60-240");
    String inputValue11 = JOptionPane.showInputDialog("Please enter the lap time for lap 3");
    } else {
    System.out.println("");
    String inputValue11 = JOptionPane.showInputDialog("Please enter the lap time for lap 3");
    }
    String inputValue3 = JOptionPane.showInputDialog("Please enter the lap time for lap 4");
    if (num > 60) {
    System.out.println("Please enter a number between 60-240");
    String inputValue11 = JOptionPane.showInputDialog("Please enter the lap time for lap 4");
    } else {
    System.out.println("");
    String inputValue11 = JOptionPane.showInputDialog("Please enter the lap time for lap 4");
    }
    String inputValue4 = JOptionPane.showInputDialog("Please enter the lap time for lap 5");
    if (num > 60) {
    System.out.println("Please enter a number between 60-240");
    String inputValue11 = JOptionPane.showInputDialog("Please enter the lap time for lap 5");
    } else {
    System.out.println("");
    String inputValue11 = JOptionPane.showInputDialog("Please enter the lap time for lap 5");
    }
    String inputValue5 = JOptionPane.showInputDialog("Please enter the lap time for lap 6");
    if (num > 60) {
    System.out.println("Please enter a number between 60-240");
    String inputValue11 = JOptionPane.showInputDialog("Please enter the lap time for lap 6");
    } else {
    System.out.println("");
    String inputValue11 = JOptionPane.showInputDialog("Please enter the lap time for lap 6");
    }
    String inputValue6 = JOptionPane.showInputDialog("Please enter the lap time for lap 7");
    if (num > 60) {
    System.out.println("Please enter a number between 60-240");
    String inputValue11 = JOptionPane.showInputDialog("Please enter the lap time for lap 7");
    } else {
    System.out.println("");
    String inputValue11 = JOptionPane.showInputDialog("Please enter the lap time for lap 7");
    }
    String inputValue7 = JOptionPane.showInputDialog("Please enter the lap time for lap 8");
    if (num > 60) {
    System.out.println("Please enter a number between 60-240");
    String inputValue11 = JOptionPane.showInputDialog("Please enter the lap time for lap 8");
    } else {
    System.out.println("");
    String inputValue11 = JOptionPane.showInputDialog("Please enter the lap time for lap 8");
    }
    String inputValue8 = JOptionPane.showInputDialog("Please enter the lap time for lap 9");
    if (num > 60) {
    System.out.println("Please enter a number between 60-240");
    String inputValue11 = JOptionPane.showInputDialog("Please enter the lap time for lap 9");
    } else {
    System.out.println("");
    String inputValue11 = JOptionPane.showInputDialog("Please enter the lap time for lap 9");
    }
    String inputValue9 = JOptionPane.showInputDialog("Please enter the lap time for lap 10");
    if (num > 60) {
    System.out.println("Please enter a number between 60-240");
    String inputValue11 = JOptionPane.showInputDialog("Please enter the lap time for lap 10");
    } else {
    System.out.println("");
    String inputValue11 = JOptionPane.showInputDialog("Please enter the lap time for lap 10");

    }
    {


    }


    }





    {


    }
    }
    :confused:

  13. #13
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    variable num is always greater than 60 since it is assigned the value 240 and never reassigned. Btw this is not an advanced java question

  14. #14
    Spidermonkey is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default

    yeah, i was just courious as to how, with that code i would be able to
    "record" the numbers which were entered as long as they were above 60 but less then 240,
    and then turn it into a read out which read, in min:sec:ms , ><; i used the popup Box dialog
    because i thought it would have been eaiser to hold the numbers, not sure how O.O lol

  15. #15
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    well what does 60 and 240 represent? minutes?? hard to have a formatted output without values to slap in there..Going back to the original problem you need to parse the JDialogInput to an integer, since JDialogInput returns a String type (it is this String type you need to parse) Parse simply means convert from one form to another, String to int in your case, research how to convert String to an int type

  16. #16
    Spidermonkey is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default

    60~240,where values which were suppsoed to be read into a array, .. but i have done it so the "input" as long as its between 60-240,. I wanted it to be convereted into min:sec , by subtracting the number of 60+ -240 etc , if possible or it would at +60 to round up to a tripple diget number ^^; . but dang i am lost with this stuff lol

  17. #17
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Seriously make a small little program that takes a value you entered into JDialog and convert that value to an integer then get back to your original problem.

Similar Threads

  1. Replies: 4
    Last Post: 06-11-2013, 01:37 AM
  2. Please help, what am I doing wrong?
    By mmac1218 in forum New To Java
    Replies: 2
    Last Post: 09-01-2009, 11:21 PM
  3. What did i do wrong
    By jpnym15 in forum New To Java
    Replies: 8
    Last Post: 11-17-2008, 10:07 AM
  4. So, what am I doing wrong?
    By Charles_Smith in forum New To Java
    Replies: 0
    Last Post: 10-29-2008, 02:50 PM
  5. Can someone tell me what I did wrong??
    By booter4429 in forum New To Java
    Replies: 7
    Last Post: 08-13-2008, 08:35 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
  •