3 Replies - 6728 Views - Last Post: 11 September 2007 - 05:48 PM Rate Topic: -----

#1 allican57  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 02-October 06

more array stuff

Posted 11 September 2007 - 01:41 PM

Sorry for the new post. I'm still getting two compiler errors on this line


GradedActivity.grades[],[] = new int grades.grades[4];


the messages are "not a statement" and "; expected"

Course Grades
In a course, a teacher gives the following tests and assignments:
l A lab activity that is observed by the teacher and assigned a numeric score.
l A pass/fail exam that has 10 questions. The minimum passing score is 70.
l An essay that is assigned a numeric score.
l A final exam that has 50 questions.
Write a class named CourseGrades.
The class should have a GradedActivity array named grades as a field.
The array should have four elements, one for each of the assignments previously described.
The class should have the following methods: setLab: This method should accept a GradedActivity object as its argument. This object should already hold the studentís score for the lab activity. Element 0 of the grades ?eld should reference this object. setPassFailExam: This method should accept a PassFailExam object as its argument. This object should already hold the studentís score for the pass/fail exam. Element 1 of the grades ?eld should reference this object. setEssay: This method should accept an Essay object as its argument. (See
Programming Challenge 4 for the Essay class.
If you have not completed Programming Challenge 4, use a GradedActivity object instead.)
This object should already hold the studentís score for the essay.
Element 2 of the grades ?eld should reference this object.
setFinalExam: This method should accept a FinalExam object as its argument.
This object should already hold the studentís score for the ?nal exam.
Element 3 of the grades ?eld 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.



import java.util.Scanner;

public class CourseGrades {


 public static void main(String[] args){
 
 	int grades,FinalExam,essay,PassFailExam,GradedActivity;
	
   // Create an array of GradedActivity references.

		
   GradedActivity.grades[],[] = new int grades.grades[4];
  
  // The first grades is a regular exam with a
  // numeric score of 95.
 grades[0] = new grades();
 grades[0].setLab(95);

  // The second grade is a pass/fail test. The
  // student missed 3 out of 10 questions, and the
  // minimum passing grade is 70.
grades[1] = new PassFailExam(10, 3, 70);

  // The third grade is an essay with an 
  //assigned  numeric score
   grades[2] = new grades();
 grades[2].essay(95);


  // The fourth grade is the final exam.
  // There were 50 questions.
  grades[3] = new FinalExam(50);

  // Display the grades.
  for (int index = 0; index < grades.length; index++);

		
  /**
  * A class that holds a grade for a graded activity.
  */
  class GradedActivity {
  
  
  private double score;  // Numeric score
 
  /**
  * The setLab method stores its argument in
  * thesetLabfield.
  */
 
  public void setLab(double s)
  {
  score = s;
  }
 
  /**
  * The getLab method returns the score field.
  */
 
  public double getLab()
  {
  return score;
  }
 
  /**
  * The getGrade method returns a letter grade 
  * determined from the score field.
  */
 
  public char getGrade()
  {
  char letterGrade;  // To hold the grade
  
  if (score >= 90)
  letterGrade = 'A';
  else if (score >= 80)
  letterGrade = 'B';
  else if (score >= 70)
  letterGrade = 'C';
  else if (score >= 60)
  letterGrade = 'D';
  else  letterGrade = 'F';

  return letterGrade;
  }
  }
  }
  }


BTW Thanks for the links!

Is This A Good Question/Topic? 0
  • +

Replies To: more array stuff

#2 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: more array stuff

Posted 11 September 2007 - 01:47 PM

Hi what are you trying to accomplish with this line:

Quote

GradedActivity.grades[],[] = new int grades.grades[4];


Is GradeActivity a class?

and what is grades?

you do not need the colon between the [][], pls explain more on what you are trying to do with the line.
Was This Post Helpful? 0
  • +
  • -

#3 allican57  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 02-October 06

Re: more array stuff

Posted 11 September 2007 - 02:29 PM

Write a class named CourseGrades.
The class should have a GradedActivity array named grades as a field.
The array should have four elements, one for each of the assignments previously described.

1.
// Create an array of GradedActivity references.

2.grades isn't that the name of the array?

I removed the , and it made no difference.

I'm so lost. THANKS FOR YOUR PATIENCE AND HELP!
Was This Post Helpful? 0
  • +
  • -

#4 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: more array stuff

Posted 11 September 2007 - 05:48 PM

Well there are more issues with your code than I thought.
First you declare grades as an int.
Then you want to declare again grades as an array of CourseGrades objects.

then you are instantiating an object grades[0] = new grades();
but grades was a variable in your code which actually should have been an object of the class CourseGrades, but that will not work in neither case.

then you have a for loop that does nothing.
and then you're doing the same kind of "instantiating" objects.
I highly recommend you get back on the notes, on how to declare and create an object, on how to declare and create an array, how to access the functions of a certain class and so on.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1