Results 1 to 17 of 17
- 06-30-2011, 06:10 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 37
- Rep Power
- 0
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)Exception in thread "main"
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
please help im lost and am used to using textpad not eclipse
thank you in advandce
- 06-30-2011, 06:27 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
That code can't be the code you're using as that will not compile...
- 06-30-2011, 06:34 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
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 senseWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-30-2011, 07:07 PM #4
Member
- Join Date
- Apr 2011
- Posts
- 37
- Rep Power
- 0
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
- 06-30-2011, 07:36 PM #5
Please copy and paste the full text of the compiler's error messages here.i know it dont compile
We'll help you get your code to work, but we need to see what the problems are that you are getting.
- 06-30-2011, 08:06 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
- 06-30-2011, 10:12 PM #7
Member
- Join Date
- Apr 2011
- Posts
- 37
- Rep Power
- 0
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
- 06-30-2011, 10:14 PM #8
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.
- 06-30-2011, 10:17 PM #9
Member
- Join Date
- Apr 2011
- Posts
- 37
- Rep Power
- 0
how would i fix that? i created a package and class in my workspace folder so i dont know what i did wrong.
- 06-30-2011, 10:20 PM #10
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
- 06-30-2011, 10:24 PM #11
Member
- Join Date
- Apr 2011
- Posts
- 37
- Rep Power
- 0
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
- 06-30-2011, 10:24 PM #12
Member
- Join Date
- Apr 2011
- Posts
- 37
- Rep Power
- 0
i mean does my code look even kinda right?
- 06-30-2011, 10:28 PM #13
Those red messages are not from the compiler. There from when you try to execute.it wont compile because im getting the error message in red.
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.
- 06-30-2011, 10:30 PM #14
Member
- Join Date
- Apr 2011
- Posts
- 37
- Rep Power
- 0
doesnt eclipse compile while your typing in ur code?
- 06-30-2011, 10:34 PM #15
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.
- 07-01-2011, 09:19 AM #16
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
What is the point of providing us code that isn't the code that has your problem?
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.
- 07-01-2011, 09:34 AM #17
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
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,
JosLast edited by JosAH; 07-01-2011 at 09:42 AM.
When people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Running a java program without eclipse / JAR Files?
By littledrummerboy in forum New To JavaReplies: 7Last Post: 05-30-2011, 06:38 PM -
Start Swing GUI program by Java Web Start with IE in Eclipse debug mode
By albertkao in forum EclipseReplies: 1Last Post: 01-18-2011, 06:27 PM -
A tab in an eclipse RCP program
By Drun in forum EclipseReplies: 0Last Post: 05-20-2010, 03:56 PM -
DB program in Eclipse
By Unni in forum EclipseReplies: 3Last Post: 08-09-2007, 11:07 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks