Results 1 to 5 of 5
- 07-18-2012, 09:14 PM #1
Member
- Join Date
- Jul 2012
- Posts
- 2
- Rep Power
- 0
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.gif)
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);
}
}
- 07-18-2012, 10:34 PM #2
Member
- Join Date
- Jul 2012
- Posts
- 55
- Rep Power
- 0
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
This will give each student an array of courses.Java Code:private String firstName, lastName; private Address homeAddress, schoolAddress; private int test1, test2,test3; private final int NUMBER_TESTS = 3; private Course[] schedule;
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.
- 07-18-2012, 10:43 PM #3
Re: Need help with Java Project - Array -
Why do they call it rush hour when nothing moves? - Robin Williams
- 07-19-2012, 11:34 PM #4
Member
- Join Date
- Jul 2012
- Posts
- 2
- Rep Power
- 0
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
- 07-20-2012, 02:56 PM #5
Member
- Join Date
- Jul 2012
- Posts
- 55
- Rep Power
- 0
Similar Threads
-
Creating a project in eclipse from existing project
By Suraiya in forum New To JavaReplies: 1Last Post: 10-08-2011, 09:14 AM -
Latest CS Project. Switching values in a Array
By jenxin in forum New To JavaReplies: 0Last Post: 03-14-2011, 01:28 AM -
Array project for class
By circuspeanuts in forum New To JavaReplies: 7Last Post: 04-17-2009, 12:44 AM -
[SOLVED] Errors with project: specify array size by the value in first command-line a
By jhrh95 in forum New To JavaReplies: 22Last Post: 01-05-2009, 01:03 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks