?
Solved

help in java Programming

Posted on 2005-04-10
12
Medium Priority
?
1,399 Views
Last Modified: 2012-08-14

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));
*/      
   }
}
0
Comment
Question by:Ansary100
  • 5
  • 3
  • 2
10 Comments
 
LVL 16

Expert Comment

by:suprapto45
ID: 13750606
Hi,

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

Regards
Dave
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 13750619
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
0
 

Author Comment

by:Ansary100
ID: 13750834
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
 
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:suprapto45
ID: 13751337
Hi,

Give me your fill Grade and Student class source codes.

Regards
Dave
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 13751418
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.
0
 

Author Comment

by:Ansary100
ID: 13753245
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
0
 

Author Comment

by:Ansary100
ID: 13754458
Could you please explain  more MogalManic Thank you very much
0
 

Author Comment

by:Ansary100
ID: 13754637
Could you please explain how to write   this mothed MogalManic please thank you very much

  public void addStudent(Student student)
   {
   }

 public void roll()
   {
   }
0
 

Author Comment

by:Ansary100
ID: 13754750
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
}
0
 
LVL 21

Accepted Solution

by:
MogalManic earned 2000 total points
ID: 13756117
The key to the addStudent() method is in the instructor's description:
>A course object should keep track of up to five students, as represented by the modified Student class

That means that your Course class should have an Array of Students as a member variable.  To keep track of the # students you have added, you also need an integer.

The addStudent() method will then just append the student to the array and then increment the student count variable.

>I need to provide a method called roll that prints all students in the course.
The roll() method will iterate through the students added and print (to System.out for simplicity) the students enrolled in the Course

>I need to provide a method called average that computes and returns the average of all students’ test score averages.
The average method will iterate through the students added and compute the average grade of all of the students.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question