Results 1 to 5 of 5
  1. #1
    Michelle66 is offline Member
    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0

    Default Need help with Java Project - Array -

    I need help with Array in Java, new to Java and having a hard time.... Would really appreciate suggestions, explanation or else... Thank you very much in advance. Below is what it is asked:

    1. Modify the Student class you modified for Lab 7 as follows:
    a. Each student object should also contain an array for a schedule (collection) of courses. The instance variable declaration will look something like this: private Course[] schedule;
    b. A student can register for as many as 6 classes per semester and up to 3 semesters in advance (all of the 2013 Academic Year).
    c. Create a class for a Course that contains the following instance variables (all can be Strings):
    i. Term (e.g., 20131, 20132, 20133)
    ii. Course Number (e.g., 368010)
    iii. Campus or Center (e.g., South, North, West)
    iv. Instructor (Lastname, Firstname as one String with a comma in the middle)
    d. Your Course class will need a constructor that sets all instance values with based on parameter values
    e. Your Course class will need a four of methods to SET the instance variables
    f. Your Course class will need a four of methods to GET the instance variables
    g. Your Course class will need a toString method that prints the Course information in this format (use a tab ď\tĒ between each item):
    Term: 20131 Course Number: 368010 Campus/Center: South Instructor: (instructor name)

    h. Modify the Student toString method so that the Schedule is printed AFTER the studentís name and addresses. Comment out the test scores and average.
    i. Modify the main method to display prompts for
    i. entering a studentís name
    ii. entering a studentís addresses (school and home)
    iii. entering courses to his/her schedule
    iv. ending data entry for a student (print the studentís name, addresses, schedule)
    v. ending data entry for all students (print the number of students, the number of courses for all students, all studentís names and the index)
    j. Modify the main method to use an array to contain all the students entered in one session.

    I know there is something wrong with my code in the Course Class but can see what it is, or maybe in the others. Any help would be really appreciate

    Below is my Student class
    import java.text.DecimalFormat;
    public class Student {
    private String firstName, lastName;
    private Address homeAddress, schoolAddress;
    private int test1, test2,test3;
    private final int NUMBER_TESTS = 3;
    public Student (String first, String last, Address home, Address school, int testScore1, int testScore2, int testScore3) {
    firstName = first;
    lastName = last;
    homeAddress = home;
    schoolAddress = school;
    test1 = testScore1;
    test2 = testScore2;
    test3 = testScore3;
    }
    public Student (String first, String last, Address home, Address school) {
    firstName = first;
    lastName = last;
    homeAddress = home;
    schoolAddress = school;
    test1 = test2 = test3 = 0;
    }
    public void setTestScore (int testNumber, int score) {
    switch (testNumber) {
    case 1 :
    test1 = score;
    break;
    case 2 :
    test2 = score;
    break;
    case 3 :
    test3 = score;
    }
    }

    Below is my Address class
    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;
    }
    }

    Below is StudentBody Main class
    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, 100, 95, 85);

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

    john.setTestScore(1, 85);
    john.setTestScore(2, 100);
    john.setTestScore(3, 90);

    marsha.setTestScore(2, 85);

    System.out.println("John score test 1: " + john.getTestScore(1));
    System.out.println("Marsha score test 2: " + marsha.getTestScore(2));

    System.out.println ();
    System.out.println (john);
    System.out.println (marsha);
    }
    }

    }

    And last the Course Class
    public class Course
    {
    private String courseName;
    private ArrayList<Student> studentList;

    public Course (String courseNameInit)
    {
    courseName = courseNameInit;

    studentList = new ArrayList<Student>();
    }

    public void addStudent (Student newStudent)
    {
    studentList.add (newStudent);
    }

    public double average()
    {
    double averageSum = 0.0, average = 0.0;

    for (Student student : studentList)
    averageSum += student.average();

    if (studentList.size() > 0)
    average = averageSum / studentList.size();

    return average;
    }

    public void roll()
    {
    System.out.println(courseName + " Class Roll");

    for (Student student : studentList)
    System.out.println(student);
    }
    }

  2. #2
    jhuber151 is offline Member
    Join Date
    Jul 2012
    Posts
    55
    Rep Power
    0

    Default Re: Need help with Java Project - Array -

    Do you have a specific question in mind? If we are just talking about the Array, all you need to do is in the Student class add
    Java Code:
    private String firstName, lastName;
    	private Address homeAddress, schoolAddress;
    	private int test1, test2,test3;
    	private final int NUMBER_TESTS = 3;
    private Course[] schedule;
    This will give each student an array of courses.

    Also i would add a toString() method to Student so that you can print out whatever you need to see.
    If you get stuck with any other questions i would be more than happy to help.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: Need help with Java Project - Array -

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Michelle66 is offline Member
    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0

    Default Re: Need help with Java Project - Array -

    Thank you so much, I really appreciate. My Course Class is not working though, but I keep working on it...

    Thanks again

  5. #5
    jhuber151 is offline Member
    Join Date
    Jul 2012
    Posts
    55
    Rep Power
    0

    Default Re: Need help with Java Project - Array -

    What portion of the Course Class is not working?

Similar Threads

  1. Creating a project in eclipse from existing project
    By Suraiya in forum New To Java
    Replies: 1
    Last Post: 10-08-2011, 10:14 AM
  2. Latest CS Project. Switching values in a Array
    By jenxin in forum New To Java
    Replies: 0
    Last Post: 03-14-2011, 02:28 AM
  3. Array project for class
    By circuspeanuts in forum New To Java
    Replies: 7
    Last Post: 04-17-2009, 01:44 AM
  4. Replies: 22
    Last Post: 01-05-2009, 02:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •