Results 1 to 17 of 17
  1. #1
    starplayerrob is offline Member
    Join Date
    Apr 2011
    Posts
    37
    Rep Power
    0

    Exclamation Need help with java program using eclipse

    Java Code:
     
     [SIZE=2][COLOR=#7f0055]
    
    [B][SIZE=2][COLOR=#7f0055]package
    [/COLOR][/SIZE][/B][/COLOR][/SIZE][LEFT][SIZE=2]review_pkg;[/SIZE]
    [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] java.util.Scanner; [/SIZE][/LEFT]
     
    [LEFT][SIZE=2] [/SIZE]
    [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] gradeAverage { [/SIZE][/LEFT]
     
     
     
    [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]static[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] main(String[] args)[U]{[/U][/SIZE][/LEFT]
     
     
     
    [LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//create the variables [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f]
    [/COLOR][/SIZE]
    [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]TestScore1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]; [/SIZE][/LEFT]
     
    [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]TestScore2[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]; [/SIZE][/LEFT]
     
    [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]TestScore3[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]; [/SIZE][/LEFT]
     
    [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]TestScore4[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]; [/SIZE][/LEFT]
     
    [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]TestScore5[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]; [/SIZE][/LEFT]
     
    [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]float[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]gradeAverage[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]; [/SIZE][/LEFT]
     
     
     
    [LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//create keyboard for input [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f]
    [/COLOR][/SIZE]
    [LEFT][SIZE=2]Scanner [/SIZE][/LEFT][SIZE=2]
    [/SIZE][/LEFT][SIZE=2]
    [/SIZE][LEFT][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]Keyboard[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Scanner(System.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]in[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]); [/SIZE]
     
     
     
    [LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//Ask the user for the 5 test scores [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f]
    [/COLOR][/SIZE]
    [LEFT][SIZE=2]System.out.println([/SIZE][/LEFT][SIZE=2]
    [/SIZE][/LEFT][SIZE=2]
    [/SIZE][LEFT][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Please enter test score 1"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]); [/SIZE]
     
    [LEFT][SIZE=2]TestScore1 = Keyboard.nextInt(); [/SIZE][/LEFT]
     
     
    [LEFT][SIZE=2]System.out.println([/SIZE][/LEFT][SIZE=2]
    [/SIZE][/LEFT][SIZE=2]
    [/SIZE][LEFT][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Please enter test score 2"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]); [/SIZE]
     
    [LEFT][SIZE=2]TestScore2 = Keyboard.nextInt(); [/SIZE][/LEFT]
     
     
     
    [LEFT][SIZE=2]System.out.println([/SIZE][/LEFT][SIZE=2]
    [/SIZE][/LEFT][SIZE=2]
    [/SIZE][LEFT][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Please enter test score 3"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]); [/SIZE]
     
    [LEFT][SIZE=2]TestScore3 = Keyboard.nextInt(); [/SIZE][/LEFT]
     
     
     
    [LEFT][SIZE=2]System.out.println([/SIZE][/LEFT][SIZE=2]
    [/SIZE][/LEFT][SIZE=2]
    [/SIZE][LEFT][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Please enter test score 4"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]); [/SIZE]
     
    [LEFT][SIZE=2]TestScore4 = Keyboard.nextInt(); [/SIZE][/LEFT]
     
     
     
    [LEFT][SIZE=2]System.out.println([/SIZE][/LEFT][SIZE=2]
    [/SIZE][/LEFT][SIZE=2]
    [/SIZE][LEFT][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Please enter test score 5"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]); [/SIZE]
     
    [LEFT][SIZE=2]TestScore5 = Keyboard.nextInt(); [/SIZE][/LEFT]
     
     
     
    [LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//Calculate the average score for the tests [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f][/COLOR][/SIZE][/LEFT][SIZE=2][COLOR=#3f7f5f]
    [/COLOR][/SIZE]
    [LEFT][SIZE=2]gradeAverage = ((TestScore1 + TestScore2 + TestScore3 + TestScore4 + TestScore5)/5); [/SIZE][/LEFT]
     
     
     
    [LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//Display Average test Score [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f]
    [/COLOR][/SIZE][SIZE=2]System.out.println([/SIZE][/LEFT][SIZE=2]
    [/SIZE][/LEFT][SIZE=2]
    [/SIZE][LEFT][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"The average score of the 5 tests is "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + gradeAverage); [/SIZE]
     
    [LEFT][SIZE=2]} [/SIZE][/LEFT]
     
    [LEFT][SIZE=2]40 [/SIZE][/LEFT]
     
    [LEFT][SIZE=2]41 } [/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2]}[/SIZE][/LEFT]
     
     
     
    [LEFT][SIZE=2] [/SIZE][/LEFT]
    [/LEFT]



    i have to create a program that computes the grade average of 5 test scores that is given by asking the user and i have to give letter grades for the average calculated. above is what i have so far and its giving me this error....
    java.lang.NoClassDefFoundError: review_pkg/gradeAverage
    Caused by:


    java.lang.ClassNotFoundException: review_pkg.gradeAverage
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(


    Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    Exception in thread "main"

    please help im lost and am used to using textpad not eclipse
    thank you in advandce

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    That code can't be the code you're using as that will not compile...

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

    Default

    Where do all those colours come from in your code? If you did it yourself, please don't do it again, it can introduce errors that weren't present in the original code ...

    kind regards,

    Jos

    ps. the last part of your class doesn't make sense
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    starplayerrob is offline Member
    Join Date
    Apr 2011
    Posts
    37
    Rep Power
    0

    Default

    it did the colors when i put code brackets around it and i know it dont compile thats why i need help. this is what i have to do: Create the program below in a new “package” in your ECLIPSE workspace. Use the same project folder, just create a new package (call it REVIEW_PKG) , and then a new class called REVIEW_Prog_firstname_lastname, substituting your name in the correct area.
    Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. In addition to the main method, write the following methods in the program:
    • calcAverage – This method should accept five test scores as arguments and return the average of the scores.
    • determineGrade – This method should accept a test score as an argument and return a letter grade for the score, based on the following grade scale:
    Score Letter Grade
    90 – 100 A
    80-89 B
    70-79 C
    60-69 D
    Below 60 F
    .. i'm lost and what doesn't make sence? sorry im really new at this and never have used eclipse before, i know people on this forum are really smart and can help me thats why i posted in here. thanks again in advance

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    i know it dont compile
    Please copy and paste the full text of the compiler's error messages here.
    We'll help you get your code to work, but we need to see what the problems are that you are getting.

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

    Default

    Quote Originally Posted by starplayerrob View Post
    .. i'm lost and what doesn't make sence?
    The last part of your class:

    Java Code:
    }  
    40  
    41 } 
    }
    }
    (copied verbatim from your OP) it doesn't make any sense.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    starplayerrob is offline Member
    Join Date
    Apr 2011
    Posts
    37
    Rep Power
    0

    Default

    yes sorry those numbers are not supposed to be there
    }
    40
    41 }
    }
    and the error message it gave me is in red above^^ and thats with out the numbers that werent supposed to be there
    thanks for the quick responces guys

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    The messages in Red look like you tried to execute a class file that does not exist. That could be because the compiler failed to create it. Or it could be in another directory.

  9. #9
    starplayerrob is offline Member
    Join Date
    Apr 2011
    Posts
    37
    Rep Power
    0

    Default

    how would i fix that? i created a package and class in my workspace folder so i dont know what i did wrong.

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    What do you need to fix?
    Does the program compile?
    If it compiles ok, where is the class file? Is it in the review_pkg folder?
    Your class is in a package: review_pkg
    How are you executing the class file?
    If from the command prompt, you need to go to the folder that contains the review_pkg folder and issue this cmd:
    java review_pkg.gradeAverage

  11. #11
    starplayerrob is offline Member
    Join Date
    Apr 2011
    Posts
    37
    Rep Power
    0

    Default

    it wont compile becausde im getting the error message in red.
    and the class file is in review_pkg as far as i know and im using the run fuction in order to execute

  12. #12
    starplayerrob is offline Member
    Join Date
    Apr 2011
    Posts
    37
    Rep Power
    0

    Default

    i mean does my code look even kinda right?

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    it wont compile because im getting the error message in red.
    Those red messages are not from the compiler. There from when you try to execute.

    I have no idea how to use your IDE. You need to figure out how to compile the source and get a copy of the error messages and copy them here.

    There is a looooong way from looking right and being right. The compiler will tell if you have valid syntax.

  14. #14
    starplayerrob is offline Member
    Join Date
    Apr 2011
    Posts
    37
    Rep Power
    0

    Default

    doesnt eclipse compile while your typing in ur code?

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    I have no idea how to use your IDE

    Perhaps you need to go to a forum for your IDE and find out how to use it.

  16. #16
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Quote Originally Posted by starplayerrob View Post
    yes sorry those numbers are not supposed to be there
    }
    40
    41 }
    }
    and the error message it gave me is in red above^^ and thats with out the numbers that werent supposed to be there
    thanks for the quick responces guys
    What is the point of providing us code that isn't the code that has your problem?

    Quote Originally Posted by starplayerrob View Post
    doesnt eclipse compile while your typing in ur code?
    Not sure. It may just scan it to see if there's any potential compilation problems.

    But that code above will not compile, so it will not execute because javac cannot produce a class file from it.

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

    Default

    Quote Originally Posted by Tolls View Post
    Not sure. It may just scan it to see if there's any potential compilation problems.
    Eclipse does a partly compilation while you type: it does syntax analysis and a bit of semantic checking (e.g. it tests for the existence of identifiers and members thereof). To make sure that it does a complete compile do a CTRL-S or a CTRL-SHIFT-S (compiles and save current file or all files respectively). In the package view the failed compilation(s) are shown with a red little cross. Don't attempt to run those ...

    kind regards,

    Jos
    Last edited by JosAH; 07-01-2011 at 10:42 AM.
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Running a java program without eclipse / JAR Files?
    By littledrummerboy in forum New To Java
    Replies: 7
    Last Post: 05-30-2011, 07:38 PM
  2. Replies: 1
    Last Post: 01-18-2011, 07:27 PM
  3. A tab in an eclipse RCP program
    By Drun in forum Eclipse
    Replies: 0
    Last Post: 05-20-2010, 04:56 PM
  4. DB program in Eclipse
    By Unni in forum Eclipse
    Replies: 3
    Last Post: 08-10-2007, 12:07 AM

Posting Permissions

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