In: Computer Science
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 * .
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.
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.
Problem 4 (5 points)
if you could show which part was based off of which problem, that would be helpful.
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