I'll say that I'm impressed by those of you who have completed the Chapter 4 programming assignments. I have spent so much time reading, re-reading, browsing documents on the web, etc., and I know something still isn't clicking. I THINK I'm getting somewhere on 4.7 but it isn't working yet. Would someone mind looking at this and letting me know what you think??? If you see stupid mistakes (which I'm sure there are), please point me in the right direction!!
COURSE CLASS:
public class Course
{
// --------------------------------------------------------------------
// Declare class variables
// --------------------------------------------------------------------
String CourseName;
private int numStudents;
String StudentName;
private int average;
private int classaverage;
//---------------------------------------------------------------------
// Class constructor - sets up course name.
//---------------------------------------------------------------------
public Course (String course)
{
CourseName = course;
}
//---------------------------------------------------------------------
// METHOD: addStudent
//---------------------------------------------------------------------
public String addStudent (String name, int studentaverage)
{
StudentName = name;
average = studentaverage;
return StudentName;
}
// --------------------------------------------------------------------
// METHOD: setNumStudents. Sets number of students in the class.
// --------------------------------------------------------------------
public void setNumStudents ()
{
if (numStudents < 5)
numStudents++;
else;
}
// --------------------------------------------------------------------
// METHOD: calcClassAvg
//
// Reads the array of scores, adds the values, computes average.
// --------------------------------------------------------------------
public int calcClassAvg ()
{
classaverage = average/numStudents;
return average;
}
// --------------------------------------------------------------------
// METHOD: Prints all students in course.
//
// --------------------------------------------------------------------
public String roll ()
{
for (int count=0; count
System.out.print (StudentName);
return (StudentName);
}
}
DRIVER:
public class Driver
{
// ---------------------------------------------------------------------
// Creates a course, adds students, prints a roll and prints the overall
// course test average
// ---------------------------------------------------------------------
public static void main (String[] args)
{
Course course1 = new Course ("Economics");
course1.addStudent ("Christine Moody", 85);
course1.addStudent ("Jerry Ross", 87);
System.out.println (course1);
}
}