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

Thread: Java help

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java help

    I need help writing this class:
    Write a class named CourseGrades. the class should have a gradedactivity array named grades as a field. the array should have 4 elements, one for each of the assignments previously described (lab activity that is observed by the teacher and assigned a numeric score, a pass/fail exam that has 10 questions, min. passing score of 70, an essay that is assigned a numeric score, a final exam that has 50 questions.) the class should have the following methods:

    setLab: this method should accept a gradedactivity object as its argument. this object should already hold the students scores for the lab act. element 0 of the grades should reference this object.

    setPassFailExam: this method should accept a passfailexam object as its argument. this object should already hold the students score for the pass/fail exam. element 1 of the grades field should reference this object.

    setEssay: this method should accept an essay object as its arguments. this object should already hold the students score for the essay. element 2 of the grades field should reference this object

    setFinalExam: this method should accept a finalexam object as its arguement. thes object should already hold the students score for the final exam. element 3 of the grades field should reference this object.

    toString: this method should return a string that contains the numeric scores and grades for each element in the grades array.

    Demonstrate the class in a program.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,972
    My Mood
    Hungover
    Thanks
    133
    Thanked 554 Times in 475 Posts

    Default Re: Java help

    Did you have a specific technical question, or did you just want to dump your homework here?

    Please read the link in my signature on asking questions the smart way, then try again.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java help

    Can you help with this? I can't get this to compile properly. Basically, I need it to take 3 test scores and display the average and it has to display an error if a negative # or if something over 100 is input?

    import java.io.*; 
    import java.util.Scanner;// For Keyboard input
    public class TestScores {
        public static void main(String[] args){
     
            //Variable Declarations
            Scanner keyboard = new Scanner(System.in);
            int TestScore =0;
            int testScore1=0;
            int testScore2=0;
            int testScore3=0;
            int averageScore;
            int userInput; 
     
     
     
                //User Prompts
                System.out.print("Please enter your 1st test score: ");
                testScore1 = keyboard.nextInt();
                System.out.print("Please enter your 2nd test score: ");
                testScore2 = keyboard.nextInt();
                System.out.print("Please enter your 3rd test score: ");
                testScore3 = keyboard.nextInt();
     
     
     
                //Array to hold user input
                 int []TestScore1 = new int (testScore1,testScore2,testScore3);           
                int max = 100 ;
     
     
     
     
                    /**
                * Constructor
                     */
                public TestScores(int testScore) {
     
                if ( testScore < 0 || testScore > 100)
                     testScore = userInput;
                else
                TestScore1 = testScore ;
        }
     
     
              // Try to assign a negative number to the TestScores field.
                  try
                  {
                  TestScores  = new int ("testScores ",-1);
     
                  catch (IllegalArgumentException e)
                  }
     
                        finally
                        {
     
                 System.out.println(IllegalArgumentException);
     
                //To calculate Average Score
                averageScore = (testScore1 + testScore2 + testScore3)/3;
     
     
                //To display average score and letter grade
                 if(testScore < 0) 
                  System.out.println("\nError invalid Score!");
     
                else if (averageScore < 60)
                    System.out.println("\nYour average score is " + averageScore + " and your grade is an F");
     
                else if(averageScore < 70)
                    System.out.println("\nYour average score is " + averageScore + " and your grade is an D");
     
                else if(averageScore <80)
                    System.out.println("\nYour average score is " + averageScore + " and your grade is an C");
     
                else if(averageScore<90)
                    System.out.println("\nYour average score is " + averageScore + " and your grade is an B");
     
                else if(averageScore <=100)
                    System.out.println("\nYour average score is " + averageScore +" and your grade is an A");
     
                else (testScore > 100)
                   System.out.println("\nError invalid Score!");
    }
    }
    }
    Last edited by mdodson; April 24th, 2013 at 03:03 PM. Reason: code

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,576
    Thanks
    45
    Thanked 1,954 Times in 1,928 Posts

    Default Re: Java help

    I can't get this to compile properly.
    Please copy the full text of the error messages and paste it here.

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java help

    Error message:

    Syntax error, insert ";" to complete Statement
    Syntax error on token "int", invalid ClassType
    Syntax error, insert "}" to complete Block
    Syntax error on token ")", { expected after this token
    Syntax error, insert "AssignmentOperator Expression" to complete Assignment
    Syntax error, insert ";" to complete Statement

    at TestScores.main(TestScores.java:28)

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,576
    Thanks
    45
    Thanked 1,954 Times in 1,928 Posts

    Default Re: Java help

    The error messages that were posted don't show the source lines where the errors are located.
    Hard to suggest coding changes without the source line with the error.

    The message should show the source with a ^ under the location of the error.
    Here is a sample from the javac compiler:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java help

    Ive found this in Eclipse:

    Description Resource Path Location Type
    Syntax error on token "int", invalid ClassType TestScores.java /Test Scores/src line 49 Java Problem
    Syntax error, insert "}" to complete Block TestScores.java /Test Scores/src line 49 Java Problem
    Syntax error on token "int", delete this token TestScores.java /Test Scores/src line 37 Java Problem
    Syntax error, insert ";" to complete Statement TestScores.java /Test Scores/src line 37 Java Problem
    Syntax error on token "int", invalid ClassType TestScores.java /Test Scores/src line 28 Java Problem
    Syntax error on token(s), misplaced construct(s) TestScores.java /Test Scores/src line 37 Java Problem
    Syntax error, insert ";" to complete Statement TestScores.java /Test Scores/src line 82 Java Problem
    Syntax error on token ")", { expected after this token TestScores.java /Test Scores/src line 51 Java Problem
    Syntax error, insert "AssignmentOperator Expression" to complete Assignment TestScores.java /Test Scores/src line 82 Java Problem

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,576
    Thanks
    45
    Thanked 1,954 Times in 1,928 Posts

    Default Re: Java help

    There is more information in those messages, but they do not include the text of the source line with the error.
    In the error message I posted the source was:
      var = 2;


    Try using the javac command to compile the code. It gives good error messages.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,972
    My Mood
    Hungover
    Thanks
    133
    Thanked 554 Times in 475 Posts

    Default Re: Java help

    Also, I really suggest fixing your formatting and indentation. You've got some pretty basic problems going on, and correct formatting would make them obvious.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!