Question

Write a class called Course_xxx that represents a course taken at a school. Represent each student...

Write a class called Course_xxx that represents a course taken at a school. Represent each student using the Student class from the Chapter 7 source files, Student.java. Use an ArrayList in the Course to store the students taking that course. The constructor of the Course class should accept only the name of the course. Provide a method called addStudent that accepts one Student parameter. Provide a method called roll that prints all students in the course. Create a driver class School_xxx with a main method that creates a course, adds several students, and prints a roll.

Submit School_xxx.java and Course_xxx.java where xxx are your initials.

Student.java

//********************************************************************
// Student.java Author: Lewis/Loftus
//
// Represents a college student.
//********************************************************************

public class Student
{
private String firstName, lastName;
private Address homeAddress, schoolAddress;

//-----------------------------------------------------------------
// Constructor: Sets up this student with the specified values.
//-----------------------------------------------------------------
public Student(String first, String last, Address home,
Address school)
{
firstName = first;
lastName = last;
homeAddress = home;
schoolAddress = school;
}

//-----------------------------------------------------------------
// Returns a string description of this Student object.
//-----------------------------------------------------------------
public String toString()
{
String result;

result = firstName + " " + lastName + "\n";
result += "Home Address:\n" + homeAddress + "\n";
result += "School Address:\n" + schoolAddress;

return result;
}
}

Please include commentary/documentation for me to better understand the code. Thank you!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

COURSE.JAVA

package abc;

import java.util.ArrayList;

import java.util.List;

public class Course {

private String courseName;

private List<Student> students= new ArrayList();

//constructor of the Course class that accepts only course name

public Course(String courseName) {

super();

this.courseName = courseName;

}

//addStudent method accepts one Student parameter

public void addStudent(Student student) {

students.add(student);

}

//roll method that prints all students in the course

public void roll(Course course) {

System.out.println("Course name: "+course.courseName);

System.out.println("Students registered for the course "+course.courseName+" :");

System.out.println("======================================");

for (Student student : course.students) { //looping through all the students enrolled for that course

System.out.println(student);// calls to string method of student class

System.out.println("======================================");

}

}

}

================================

STUDENT.JAVA

package abc;

public class Student
{
private String firstName, lastName;
private Address homeAddress, schoolAddress;

//-----------------------------------------------------------------
// Constructor: Sets up this student with the specified values.
//-----------------------------------------------------------------
public Student(String first, String last, Address home,
Address school)
{
firstName = first;
lastName = last;
homeAddress = home;
schoolAddress = school;
}

//-----------------------------------------------------------------
// Returns a string description of this Student object.
//-----------------------------------------------------------------
public String toString()
{
String result;

result = firstName + " " + lastName + "\n";
result += "Home Address:\n" + homeAddress.getAddress() + "\n";
result += "School Address:\n" + schoolAddress.getAddress();

return result;
}
}

=======================================================

ADRESS.JAVA

package abc;

public class Address {

private String address ;

// setters and getters for address

public String getAddress() {

return address;

}

public void setAddress(String address) {

this.address = address;

}

}

===============================================================

SCHOOL.JAVA:

package abc;

public class School {

public static void main(String[] args) {

Course course1 = new Course("Java"); // Creating course java

// Details of student1

Address homeAddress = new Address();

Address schoolAddress = new Address();

homeAddress.setAddress("3-33, SR nagar,hyderabad, Telangana");

schoolAddress.setAddress("3-4, 5th phase KPHB, Hyderabad, Telangana");

Student s = new Student("Robert", "D", homeAddress, schoolAddress);

course1.addStudent(s); // Robert is added to java course

// Details of student2

Address homeAddress1 = new Address();

Address schoolAddress1 = new Address();

homeAddress1.setAddress("4-33, chanda nagar,hyderabad, Telangana");

schoolAddress1.setAddress("3-4/3, 6th phase KPHB, Hyderabad, Telangana");

Student s1 = new Student("Andrew", "K", homeAddress1, schoolAddress1);

course1.addStudent(s1); //andrew is added to java course

//calling roll method of course to print the students enrolled for the course

course1.roll(course1);

}

}

Add a comment
Know the answer?
Add Answer to:
Write a class called Course_xxx that represents a course taken at a school. Represent each student...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Java Programming Complete the Code that remains to be implemented follow the guide lines here...

    In Java Programming Complete the Code that remains to be implemented follow the guide lines here and finish what code remains name of program class Student.java package course; public class Student { private String firstName; private String lastName; private Address homeAddress; private Address schoolAddress; private double[] testScores; // Four parameter constructor public Student(String firstName, String lastName, Address homeAddress, Address schoolAddress) { // Call the seven parameter constructor. Pass zeros for the three grades } // Five parameter constructor public Student(String...

  • Given a class called Student and a class called Course that contains an ArrayList of Student....

    Given a class called Student and a class called Course that contains an ArrayList of Student. Write a method called getDeansList() as described below. Refer to Student.java below to learn what methods are available. I will paste both of the simple .JAVA codes below COURSE.JAVA import java.util.*; import java.io.*; /****************************************************** * A list of students in a course *****************************************************/ public class Course{     /** collection of Students */     private ArrayList<Student> roster; /***************************************************** Constructor for objects of class Course *****************************************************/...

  • Here is the code from the previous three steps: #include <iostream> using namespace std; class Student...

    Here is the code from the previous three steps: #include <iostream> using namespace std; class Student { private: //class variables int ID; string firstName,lastName; public: Student(int ID,string firstName,string lastName) //constructor { this->ID=ID; this->firstName=firstName; this->lastName=lastName; } int getID() //getter method { return ID; } virtual string getType() = 0; //pure virtual function virtual void printInfo() //virtual function to print basic details of a student { cout << "Student type: " << getType() << endl; cout << "Student ID: " << ID...

  • JAVA PROGRAMMING In this final review lab from our intro course, use the Name class you...

    JAVA PROGRAMMING In this final review lab from our intro course, use the Name class you created in the previous lab. In this lab, create a Student class with the following class variable: Student name: Name (Note: Name is a datatype) Student Id: String Create the getter and setter methods. In addition to these methods, create a toString() method, which overrides the object class toString() method. This override method prints the current value of any of this class object. Complete...

  • Language Java Step 1: Design a class called Student. The Student class should contain the following...

    Language Java Step 1: Design a class called Student. The Student class should contain the following data: firstName lastName studentID totalCredits gpa Your class should implement the “sets” and “gets” for the class. Include methods: equals, compareTo, toString. Change the toString method (from class) to put each member variable on a new line. Step 2: Write a driver program to test that Student works correctly. Test is with 3 students as given in class. Step 3: Write a “registration” program...

  • Given the following Student class, write an equals method to determine if two instances of Student...

    Given the following Student class, write an equals method to determine if two instances of Student are the same person. The equals method should base it's comparison on the student's M number. public class Student { String firstName = ""; String lastName = ""; String mNumber = ""; Student(String firstName, String lastName, String mNumber) { this.firstName = firstName; this.lastName = lastName; this.mNumber = mNumber; } private String getMNumber() { return mNumber; } <other methods are imlemented here> }

  • using basic c++ please!!! 6. (21%) Consider the following definitions class Student { class Section public:...

    using basic c++ please!!! 6. (21%) Consider the following definitions class Student { class Section public: string getFirst (); string getLast (); intgetGrade () void setFirst (string s); void setLast (string s); void setGrade(int g); numStudents (); in Student getNthStudent (int n); string getCourse (); string getInstructor (); private: private: string firstName; string lastName; int Student students [SIZE]; string course; string instructor; grade ; Write a function, honorRoll that returns a dynamic array containing only those students in section sec...

  • Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person...

    Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person and Student represent individuals with a first and last name as String class variables, and Student has an additional int class variable that represents a ID number. The Roster class represents a group of people that are objects of either the Person or Student class. It contains an ArrayList. The Person class has been completed for you with class variables, a constructor, and a...

  • please use java do what u can 1. Modify the Student class presented to you as...

    please use java do what u can 1. Modify the Student class presented to you as follows. Each student object should also contain the scores for three tests. Provide a constructor that sets all instance values based on parameter values. Overload the constructor such that each test score is assumed to be initially zero. Provide a method called set Test Score that accepts two parameters: the test number (1 through 3) and the score. Also provide a method called get...

  • CSCI 135 Test 2 Name: 6, (21%) Consider the following definitions: class Student class Section public:...

    CSCI 135 Test 2 Name: 6, (21%) Consider the following definitions: class Student class Section public: string getFirst ) string getLast () int getGrade) void set First (string s) void setLast (string ) void setGrade (nt g): numStudents () Student getNthStudent (int n) string getCourse ) string getInstructor ); private: private: string firstName string lastName Student students [SIZE: string course; string structor; grade; Write a function, honorRoll that returns a dynamic array containing only those students in section sec with...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT