Question

In: Computer Science

The Instructor class consists of a firstname (String), lastname (String), office building (String) and room number...

The Instructor class consists of a firstname (String), lastname (String), office building (String) and room number (int). There is a no-arg constructor that initializes the properties to “Albert”, “Einstein”, “McNair”, 420. There is also a constructor with a parameter for each class property. Finally, there is a toString() method that returns each property separated by an asterisk * .

  1. Create a Netbeans project and name it CourseScheduler.
  2. Implement the Instructor class in Java. Declare and instantiate two Instructor objects in the main() method of your project (one object using each constructor). Output the object properties to the console using the toString() method. When you are finished.

Problem 2 (5 points)

The Textbook class consists of a title (String), publisher (String) and edition (int). There is a no-arg constructor that initializes Strings to “” and numeric values to zero. A second constructor has formal parameters for each property. The class toString() method returns a String with each property separated by a System.lineSeparator() char.

  1. Implement the Textbook class in the CourseScheduler project. Declare and instantiate Textbook objects in the main() using both constructors. Output the object properties using the toString() method. When you are finished, get the TA to check your code to get the lab points.

Problem 3 (5 points)

The Course class consists of a name (String), semester (String), instructor (Instructor) and textbook (Textbook). As with the previous classes, there are two constructors: one no-arg constructor and one constructor with formal parameters for each property. The no-arg constructor initializes reference variables to null. The toString() method separates the name and semester by a comma (‘,’). There is a System.lineSeparator() char after the semester property and between the Instructor and Textbook properties. The Instructor and Textbook properties are formatted using the toString() method from their respective classes.

  1. Implement the Course class in the CourseScheduler project. Instantiate Instructor and Textbook objects and use them along with the course name and semester as parameters to the Course constructor. Output the properties of the Course object using the toString() method. You can verify the format of the toString() by comparing it with the file input format described in Problem 4 below. When you are finished, get the TA to check your code to get the lab points.

Problem 4 (5 points)

  1. Declare and instantiate an ArrayList in the main() method. Name it courses.
  2. Implement the following method in the same class as the main(): public static void readCourseData( ArrayList courses, String filename )
  3. Make a call to readCourseData() from the main() passing the ArrayList and the filename as parameters. Write a loop under the call to readCourseData to output all the course data to the console by calling toString() for each Course object in the ArrayList.

if you could show which part was based off of which problem, that would be helpful.

Solutions

Expert Solution

Note: Copuld u provide the input file link for the 4th Question.So that I can develop program

Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// Instructor.java

public class Instructor {
   //Declaring instance variables
   private String firstname;
   private String lastname;
   private String officebuilding;
   private int roomNumber;

   //Zero argumented constructor
   public Instructor() {
       this.firstname = "Albert";
       this.lastname = "Einstein";
       this.officebuilding = "McNair";
       this.roomNumber = 420;

   }

   //Parameterized constructor
   public Instructor(String firstname, String lastname, String officebuilding,
           int roomNumber) {
       this.firstname = firstname;
       this.lastname = lastname;
       this.officebuilding = officebuilding;
       this.roomNumber = roomNumber;
   }

   // getters and setters
   public String getFirstname() {
       return firstname;
   }

   public void setFirstname(String firstname) {
       this.firstname = firstname;
   }

   public String getLastname() {
       return lastname;
   }

   public void setLastname(String lastname) {
       this.lastname = lastname;
   }

   public String getOfficebuilding() {
       return officebuilding;
   }

   public void setOfficebuilding(String officebuilding) {
       this.officebuilding = officebuilding;
   }

   public int getRoomNumber() {
       return roomNumber;
   }

   public void setRoomNumber(int roomNumber) {
       this.roomNumber = roomNumber;
   }

   //toString method is used to display the contents of an object inside it
   @Override
   public String toString() {
       return firstname + " * " + lastname + " * " + officebuilding + " * "+ roomNumber;
   }

}
___________________________

// CourseScheduler.java

public class CourseScheduler {
   public static void main(String[] args) {
       //Creating two Instances of Instructor class objects
Instructor ins1=new Instructor("Robin","Utappa","SunShine",315);
Instructor ins2=new Instructor();
System.out.println(ins1);
System.out.println(ins2);
   }

}
___________________________

Output:

Robin * Utappa * SunShine * 315
Albert * Einstein * McNair * 420

___________________________

2)

// TextBook.java

public class TextBook {
   //Declaring instance variables
   private String title;
   private String publisher;
   private int edition;

   //Zero argumented constructor
   public TextBook() {
       this.title = "";
       this.publisher = "";
       this.edition = 0;
   }

   //Parameterized constructor
   public TextBook(String title, String publisher, int edition) {
       this.title = title;
       this.publisher = publisher;
       this.edition = edition;
   }

   // getters and setters
   public String getTitle() {
       return title;
   }

   public void setTitle(String title) {
       this.title = title;
   }

   public String getPublisher() {
       return publisher;
   }

   public void setPublisher(String publisher) {
       this.publisher = publisher;
   }

   public int getEdition() {
       return edition;
   }

   public void setEdition(int edition) {
       this.edition = edition;
   }

   //toString method is used to display the contents of an object inside it
   @Override
   public String toString() {
       return title + System.lineSeparator()+ publisher
               +System.lineSeparator()+ "" + edition;
   }

}
_____________________________

// CourseScheduler.java

public class CourseScheduler {

   public static void main(String[] args) {
TextBook tb1=new TextBook("Let Us C","Brooklyn Publishers",5);
TextBook tb2=new TextBook("Ansi C","RedBook Publishers",11);
System.out.println(tb1);
System.out.println(tb2);
   }

}
_____________________________

Output:

Let Us C
Brooklyn Publishers
5
Ansi C
RedBook Publishers
11

_____________________________

3)

// Course.java

public class Course {
   //Declaring instance variables
   private String name;
   private String semester;
   private Instructor instructor;
   private TextBook textbook;

   //Zero argumented constructor
   public Course() {
       this.name = null;
       this.semester = null;
       this.instructor = null;
       this.textbook = null;
   }

   //Parameterized constructor
   public Course(String name, String semester, Instructor instructor,
           TextBook textbook) {
       this.name = name;
       this.semester = semester;
       this.instructor = instructor;
       this.textbook = textbook;
   }

   // getters and setters
   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }

   public String getSemester() {
       return semester;
   }

   public void setSemester(String semester) {
       this.semester = semester;
   }

   public Instructor getInstructor() {
       return instructor;
   }

   public void setInstructor(Instructor instructor) {
       this.instructor = instructor;
   }

   public TextBook getTextbook() {
       return textbook;
   }

   public void setTextbook(TextBook textbook) {
       this.textbook = textbook;
   }

   //toString method is used to display the contents of an object inside it
   @Override
   public String toString() {
       return name + "," + semester + System.lineSeparator() + instructor
               + System.lineSeparator() + textbook;
   }

}
__________________________

// CourseScheduler2.java

public class CourseScheduler2 {

   public static void main(String[] args) {
  
       Course c1=new Course("Computer Science","Second",new Instructor("James","Patinson","Brooklyn Building",213),new TextBook("Database Management Systems","Litmus Publishers",12));
       Course c2=new Course("Electronics","Fifth",new Instructor("Sachin","Tendulkar","Vasavi Building",240),new TextBook("Operating Systems","Pearson Publishers",9));
       System.out.println(c1);
       System.out.println(c2);

   }

}
___________________________

Output:

Computer Science,Second
James * Patinson * Brooklyn Building * 213
Database Management Systems
Litmus Publishers
12
Electronics,Fifth
Sachin * Tendulkar * Vasavi Building * 240
Operating Systems
Pearson Publishers
9

___________________________Thank You


Related Solutions

A person has a firstname, lastname, ID, and email. A phone number is of the form...
A person has a firstname, lastname, ID, and email. A phone number is of the form countrycode, number. A person may have several related telephone numbers, and a telephone number may be associated with multiple people. The possible relationships are: home, work, and mobile. A person may have at most one phone number for each type of relationship. Draw schema diagram and define and create the tables that implement the model and enforce the given constraints.
Consider a class called Building. This class consists of a number of floors (numberOfFloors) for the...
Consider a class called Building. This class consists of a number of floors (numberOfFloors) for the building, a current floor for the elevator (current), a requested floor of a person waiting for the elevator (requestedFloor), and methods for constructing the building object, for moving the elevator one floor up, for moving the elevator one floor down, for requesting the elevator and for starting the elevator going. Assume that requestedFloor will be set to 0 if there are currently no requests...
***IN JAVA*** Write a program contained a class Student which has firstName, lastName, mark, grade. The...
***IN JAVA*** Write a program contained a class Student which has firstName, lastName, mark, grade. The program should allow creation an array of object instances to assign firstName, lastName and mark from input user and perform and assign grade based on mark’s criteria displayed below. MARKS INTERVAL 95 - 100 90 - <95 85 - <90 80 - <85 75 - <80 70 - <75 65 - <70 60 - <65 0 - <60 LETTER GRADE A+ A B+ B...
java programing Q: Given the following class: public class Student { private String firstName; private String...
java programing Q: Given the following class: public class Student { private String firstName; private String lastName; private int age; private University university; public Student(String firstName, String lastName, int age, University university) { this.firstName = fisrtName; this.lastName = lastName; this.age = age; this.university = university; } public String getFirstName(){ return firstName; } public String getLastName(){ return lastName; } public int getAge(){ return age; } public University getUniversity(){ return university; } public String toString() { return "\nFirst name:" + firstName +...
How would I setup this dictionary for Python 3? class Student(object): def __init__(self, id, firstName, lastName,...
How would I setup this dictionary for Python 3? class Student(object): def __init__(self, id, firstName, lastName, courses = None): The “id”, “firstName” and “lastName” parameters are to be directly assigned to member variables (ie: self.id = id) The “courses” parameter is handled differently. If it is None, assign dict() to self.courses, otherwise assign courses directly to the member variable. Note: The “courses” dictionary contains key/value pairs where the key is a string that is the course number (like “course1”) and...
This lab uses a Student class with the following fields: private final String firstName; private final...
This lab uses a Student class with the following fields: private final String firstName; private final String lastName; private final String major; private final int zipcode; private final String studentID; private final double gpa; A TestData class has been provided that contains a createStudents() method that returns an array of populated Student objects. Assignmen The Main method prints the list of Students sorted by last name. It uses the Arrays.sort() method and an anonymous Comparator object to sort the array...
C++ Classes & Objects Create a class named Student that has three private member: string firstName...
C++ Classes & Objects Create a class named Student that has three private member: string firstName string lastName int studentID Write the required mutator and accessor methods/functions (get/set methods) to display or modify the objects. In the 'main' function do the following (1) Create a student object "student1". (2) Use set methods to assign StudentID: 6337130 firstName: Sandy lastName: Santos (3) Display the students detail using get functions in standard output using cout: Sandy Santos 6337130
Java programming. ** Create Account class include: 1/ private long   accountNumber; 2/ private String firstName; 3/...
Java programming. ** Create Account class include: 1/ private long   accountNumber; 2/ private String firstName; 3/ private String lastName; 4/ private double balance; 5/ public Account(long accountNumber, String firstName, String lastName, double balance); 6/ get/set methods for all attributes. 7/ public boolean deposit(double amount);   • deposit only if amount is greater than 10 but   less than 200, add the deposit   amount   to the   currentbalance. • if deposit is   successful return true,   otherwise return false; 8/ public boolean withdrawal(double amount); •...
Room.java: public class Room { // fields private String roomNumber; private String buildingName; private int capacity;...
Room.java: public class Room { // fields private String roomNumber; private String buildingName; private int capacity; public Room() { this.capacity = 0; } /** * Constructor for objects of class Room * * @param rN the room number * @param bN the building name * @param c the room capacity */ public Room(String rN, String bN, int c) { setRoomNumber(rN); setBuildingName(bN); setCapacity(c); }    /** * Mutator method (setter) for room number. * * @param rN a new room number...
Room.java: public class Room { // fields private String roomNumber; private String buildingName; private int capacity;...
Room.java: public class Room { // fields private String roomNumber; private String buildingName; private int capacity; public Room() { this.capacity = 0; } /** * Constructor for objects of class Room * * @param rN the room number * @param bN the building name * @param c the room capacity */ public Room(String rN, String bN, int c) { setRoomNumber(rN); setBuildingName(bN); setCapacity(c); }    /** * Mutator method (setter) for room number. * * @param rN a new room number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT