Link to home
Start Free TrialLog in
Avatar of Ansary100
Ansary100

asked on

help in java Programming


Hi
Guys, I need your help I am trying to improve my java programming skills I find this question I am confident of my half way answer her is the question and her is my answer to it so far could you please help (this not a homework)

I need to design and implement a class called Course that represents a course taken at a school. A course object should keep track of up to five students, as represented by the modified Student class The constructor of the Course class should accept only the name of the course, provide a method called addStudent that accepts one Student parameter (the Course object should keep track of how many valid students have been added to the course). I need to provide a method called average that computes and returns the average of all students’ test score averages. I need to provide a method called roll that prints all students in the course. And a need to create a driver class with a main method that creates a course, and adds several students, prints a roll and prints the overall course test average.  

here is my code

public class Address
{
   private String streetAddress, city, state;
   private long zipCode;

   public Address (String street, String town, String st, long zip)
   {
      streetAddress = street;
      city = town;
      state = st;
      zipCode = zip;
   }

   
   public String toString()
   {
      String result;

      result = streetAddress + "\n";
      result += city + ", " + state + "  " + zipCode;

      return result;
   }
}

------------------------------------------------------------------------------------------
public class Grade
{
   private int grade1, grade2, grade3;
   private float average;

 
    public Grade (int gr1, int grade2, int grade3)
   {
      grade1 = gr1;
      this.grade2 = grade2;
      this.grade3 = grade3;

   }


   public void setTestScore ( int testNum, int newGrade)
   {
       switch (testNum) {
      case 1: grade1 = newGrade;
            break;
      case 2: grade2 = newGrade;
            break;
      case 3: grade3 = newGrade;
            break;
      default: System.out.println("Horrible ERROR!!!!");
      }
    }

    public int getTestScore(int testNum)
    {
     int testScore = -1;
---------------------------------------------------------------------------------------------------------------
public class Student
{
   private String firstName, lastName;
   private Address homeAddress, schoolAddress;
   private int grade1, grade2, grade3;
   private float average;

   
   public Student (String first, String last, Address home,
                   Address school)
   {
      firstName = first;
      lastName = last;
      homeAddress = home;
      schoolAddress = school;
      grade1 = 0;
      grade2 = 0;
      grade3 =0;
   }

   public Student (String first, String last, Address home, Address school, int gr1, int grade2, int grade3)
   {
      firstName = first;
      lastName = last;
      homeAddress = home;
      schoolAddress = school;
      grade1 = gr1;
      this.grade2 = grade2;
      this.grade3 = grade3;

   }


   public void setTestScore ( int testNum, int newGrade)
   {
-------------------------------------------------------------------------------------------------------------
public class StudentBody
{
 
   public static void main (String[] args)
   {
      Address school = new Address ("800 Lancaster Ave.", "Villanova",
                                    "PA", 19085);

      Address jHome = new Address ("21 Jump Street", "Lynchburg",
                                   "VA", 24551);
      Student john = new Student ("John", "Smith", jHome, school);


      Address mHome = new Address ("123 Main Street", "Euclid", "OH",
                                   44132);
      Student marsha = new Student ("Marsha", "Jones", mHome, school,75,87,98);
   
     

      System.out.println (john);
/*      System.out.println ();
      System.out.println (marsha);

      System.out.println( "\n\n\nMarsha's average: " + marsha.calcAverage());
marsha.setTestScore(2,50);
      System.out.println("Marsha's second test score : " + marsha.getTestScore(2));
*/      
   }
}
Avatar of suprapto45
suprapto45
Flag of Singapore image

Hi,

What help do you want? I can offer you some hints and solutions though.

Regards
Dave
Hi,

You override the .toString() methods. That is a brilliant idea, you should not consider yourself as the beginner as you know that tricks already :). Perhaps, you could consider some setter or getter methods as javabeans convention. Each of the field in the class should have its own setter and getter.

Thanks and regards
Dave
Avatar of Ansary100
Ansary100

ASKER

Thank You all...I got stuck in the last requirement...to complete the program written above I need to provide a method called roll that prints all students in the course. And a need to create a driver class with a main method that creates a course, and adds several students, prints a roll and prints the overall course test average.  I know there are alot of smart people out there who could help me finish this program
 
Hi,

Give me your fill Grade and Student class source codes.

Regards
Dave
The code you supplied doesn't match the requirements!  It has Student, Address, Grade and StudentBody.  According to the requirements you only need three classes, Student, Course and "Driver".  The student class represents a person who enroles in a Course.  The "Driver" class is just the class that is uesed to test that the Student and Course work correctly together.

The Student class you have will work fine, to create a Course class, just create a new class and add the attributes describe by the teacher.  Next add the methods.  At the first pass just stub them out like this:

public class Course
{
//private attributes go here
....

   public Course(....Constructor parameters...)
   {
   }

   /**
    * Add a student to the course
    * @param student - Student to add to course
    **/
   public void addStudent(Student student)
   {
   }

    /**
     * Print out the list of students enrolled in the course
     **/
   public void roll()
   {
   }

....The rest of the methods
}


For each method you need to plan and then write the code on how to do each task.  If you need help on a specific task, then we would be glad to help.
Thank You all...I got stuck in the last ...to complete the program written above I need to provide a method called roll that prints all students in the course. And a need to create a driver class with a main method that creates a course, and adds several students, prints a roll and prints the overall course test average.  I know there are alot of smart people out there who could help me finish this program
Could you please explain  more MogalManic Thank you very much
Could you please explain how to write   this mothed MogalManic please thank you very much

  public void addStudent(Student student)
   {
   }

 public void roll()
   {
   }
hi every one I wroit this cod is there any one can help to finsh this cod

public class Course
{


   private String math, writing, reading, history, computer;
   
   private float average;

   //-----------------------------------------------------------------
   //  Constructor: Sets up this cours with the specified values.
   //-----------------------------------------------------------------

   public Course(string ma,string writ, string read,string hist,string compu)
   {
     math = ma;
     writing = writ;
     reading = read;
     history = hist;
     computer = compu;
   }

   /**
    * Add a student to the course
    * @param student - Student to add to course
    **/
   public void addStudent(Student student)
   {
   }

    /**
     * Print out the list of students enrolled in the course
     **/
   public void roll()
   {
   }

....The rest of the methods
}
ASKER CERTIFIED SOLUTION
Avatar of MogalManic
MogalManic
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial