JAVA
/**
* This class stores information about an instructor.
*/
public class Instructor
{
private String lastName, // Last name
firstName, // First name
officeNumber; // Office number
/**
* This constructor accepts arguments for the
* last name, first name, and office number.
*/
public Instructor(String lname, String fname,
String office)
{
lastName = lname;
firstName = fname;
officeNumber = office;
}
/**
* The set method sets each field.
*/
public void set(String lname, String fname,
String office)
{
lastName = lname;
firstName = fname;
officeNumber = office;
}
/**
* The toString method returns a string containing
* the instructor information.
*/
public String toString()
{
// Create a string representing the object.
String str = "Last Name: " + lastName
+ "\nFirst Name: " + firstName
+ "\nOffice Number: " + officeNumber;
// Return the string.
return str;
}
}
-------------------------------------------------------------------------------------------------------------------------------------------
/**
* This program demonstrates the Course class.
*/
public class CourseDemo
{
public static void main(String[] args)
{
// Create an Instructor object.
Instructor myInstructor =
new Instructor("Kramer", "Shawn", "RH3010");
// Create a TextBook object.
TextBook myTextBook =
new TextBook("Starting Out with Java",
"Gaddis", "Addison-Wesley");
// Create a Course object.
Course myCourse =
new Course("Intro to Java", myInstructor,
myTextBook);
// Display the course information.
System.out.println(myCourse);
}
}
-------------------------------------------------------------------------------------------------------------------------------------------
/**
* This class stores information about a textbook.
*/
public class TextBook
{
private String title, // Title of the book
author, // Author's last name
publisher; // Name of publisher
/**
* This constructor accepts arguments for the
* title, author, and publisher.
*/
public TextBook(String textTitle, String auth,
String pub)
{
title = textTitle;
author = auth;
publisher = pub;
}
/**
* The set method sets each field.
*/
public void set(String textTitle, String auth,
String pub)
{
title = textTitle;
author = auth;
publisher = pub;
}
/**
* The toString method returns a string containing
* the textbook information.
*/
public String toString()
{
// Create a string representing the object.
String str = "Title: " + title
+ "\nAuthor: " + author
+ "\nPublisher: " + publisher;
// Return the string.
return str;
}
}
-------------------------------------------------------------------------------------------------------------------------------------------
/**
* This class stores information about a course.
*/
public class Course
{
private String courseName; // Name of the course
private Instructor instructor; // The instructor
private TextBook textBook;
public Course(String name, Instructor instr,
TextBook text)
{
// Assign the courseName.
courseName = name;
// Create a new Instructor object, passing
// instr as an argument to the copy constructor.
instructor = instr;
// Create a new TextBook object, passing
// text as an argument to the copy constructor.
textBook = text;
}
/**
* getName method
*/
public String getName()
{
return courseName;
}
/**
* getInstructor method
*/
public Instructor getInstructor()
{
// Return a copy of the instructor object.
return instructor;
}
/**
* getTextBook method
*/
public TextBook getTextBook()
{
// Return a copy of the textBook object.
return textBook;
}
/**
* The toString method returns a string containing
* the course information.
*/
public String toString()
{
// Create a string representing the object.
String str = "Course name: " + courseName
+ "\nInstructor Information:\n"
+ instructor
+ "\nTextbook Information:\n"
+ textBook;
// Return the string.
return str;
}
}
-------------------------------------------------------------------------------------------------------------------------------------------
First run the attached classes and see what the output is then examine the code and see how composition works. Complete the following steps to modify some of these classes so that it will also print out the information on the SI of the class too.
Add SI class that has three instance variables (first name, Last name, Office hours)
Add all the methods required for this class (including toString() method)
Modify the course class toString() method so that it will also print out the information on SI.
Modify the client so that it works with the additional class.
Hi, Please find my implementation.
Please let me know in case of any issue.
############## Instructor.java #############
public class Instructor
{
private String lastName, // Last name
firstName, // First name
officeNumber; // Office number
/**
* This constructor accepts arguments for the
* last name, first name, and office number.
*/
public Instructor(String lname, String fname,
String office)
{
lastName = lname;
firstName = fname;
officeNumber = office;
}
/**
* The set method sets each field.
*/
public void set(String lname, String fname,
String office)
{
lastName = lname;
firstName = fname;
officeNumber = office;
}
/**
* The toString method returns a string containing
* the instructor information.
*/
public String toString()
{
// Create a string representing the object.
String str = "Last Name: " + lastName
+ "\nFirst Name: " + firstName
+ "\nOffice Number: " + officeNumber;
// Return the string.
return str;
}
}
############## TextBook.java ##################
public class TextBook
{
private String title, // Title of the book
author, // Author's last name
publisher; // Name of publisher
/**
* This constructor accepts arguments for the
* title, author, and publisher.
*/
public TextBook(String textTitle, String auth,
String pub)
{
title = textTitle;
author = auth;
publisher = pub;
}
/**
* The set method sets each field.
*/
public void set(String textTitle, String auth,
String pub)
{
title = textTitle;
author = auth;
publisher = pub;
}
/**
* The toString method returns a string containing
* the textbook information.
*/
public String toString()
{
// Create a string representing the object.
String str = "Title: " + title
+ "\nAuthor: " + author
+ "\nPublisher: " + publisher;
// Return the string.
return str;
}
}
############### SI.java ############
public class SI {
private String firstName;
private String lastName;
private int officeHours;
public SI(String firstName, String lastName, int officeHours) {
super();
this.firstName = firstName;
this.lastName = lastName;
this.officeHours = officeHours;
}
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 int getOfficeHours() {
return officeHours;
}
public void setOfficeHours(int officeHours) {
this.officeHours = officeHours;
}
@Override
public String toString() {
return "First Name: "+firstName+"\n"+
"Last Name: "+lastName+"\n"+
"Office Hours: "+officeHours;
}
}
################## Course.java ###################
public class Course
{
private String courseName; // Name of the course
private Instructor instructor; // The instructor
private TextBook textBook;
private SI si;
public Course(String name, Instructor instr,
TextBook text, SI s)
{
// Assign the courseName.
courseName = name;
// Create a new Instructor object, passing
// instr as an argument to the copy constructor.
instructor = instr;
// Create a new TextBook object, passing
// text as an argument to the copy constructor.
textBook = text;
si = s;
}
/**
* getName method
*/
public String getName()
{
return courseName;
}
/**
* getInstructor method
*/
public Instructor getInstructor()
{
// Return a copy of the instructor object.
return instructor;
}
/**
* getTextBook method
*/
public TextBook getTextBook()
{
// Return a copy of the textBook object.
return textBook;
}
public SI getSI(){
return si;
}
/**
* The toString method returns a string containing
* the course information.
*/
public String toString()
{
// Create a string representing the object.
String str = "Course name: " + courseName
+ "\nInstructor Information:\n"
+ instructor
+ "\nTextbook Information:\n"
+ textBook
+ "\nSI Information:\n"
+ si;
// Return the string.
return str;
}
}
################### CourseDemo.java #####################
public class CourseDemo
{
public static void main(String[] args)
{
// Create an Instructor object.
Instructor myInstructor =
new Instructor("Kramer", "Shawn", "RH3010");
// Create a TextBook object.
TextBook myTextBook =
new TextBook("Starting Out with Java",
"Gaddis", "Addison-Wesley");
SI si = new SI("Pravesh", "Kumar", 6);
// Create a Course object.
Course myCourse =
new Course("Intro to Java", myInstructor,
myTextBook, si);
// Display the course information.
System.out.println(myCourse);
}
}
/*
Sample run:
Course name: Intro to Java
Instructor Information:
Last Name: Kramer
First Name: Shawn
Office Number: RH3010
Textbook Information:
Title: Starting Out with Java
Author: Gaddis
Publisher: Addison-Wesley
SI Information:
First Name: Pravesh
Last Name: Kumar
Office Hours: 6
*/
JAVA /** * This class stores information about an instructor. */ public class Instructor { private...
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...
Writing 3 Java Classes for Student registration /** * A class which maintains basic information about an academic course. */ public class Course { /** * Attributes. */ private String code; private String title; private String dept; // name of department offering the course private int credits; /** * Constructor. */ public Course(String code, String title, int credits) { // TODO : initialize instance variables, use the static method defined in // Registrar to initialize the dept name variable...
JAVA This PoD, builds off the Book class that you created on Monday (you may copy your previously used code). For today’s problem, you will add a new method to the class called lastName() that will print the last name of the author (you can assume there are only two names in the author name – first and last). You can use the String spilt (“\s”) method that will split the String by the space and will return an array...
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...
(JAVA NetBeans)
Write programs in java
Example 9.13~9.15
//Book.Java
public class Book {
private String title;
private String author;
private double price;
/**
* default constructor
*/
public Book() {
title = "";
author = "";
price = 0.0;
}
/**
* overloaded constructor
*
* @param newTitle the value to assign to title
* @param newAuthor the value to assign to author
* @param newPrice the value to assign to price
*/
public Book(String newTitle, String newAuthor, double newPrice)...
pls write psuedocode
write UML CODE
ALSO
example 3 files 1 for abstract 1 for bank account and
1 for savings accounts due in 12 hours
Lab Assignment 4a Due: June 13th by 9:00 pm Complete the following Programming Assignment. Use good programming style and all the concepts previously covered. Submit the java files electronically through Canvas by the above due date in 1 Zip file Lab4.Zip. (This is from the chapter on Inheritance.) 9. BankAccount and SavingsAccount Classes Design...
The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...
I Need Help with this using Java Programming
:
Class name
fname
lname
Class variable
total Number
Constructor (no arguments)
Constructor (takes two arguments, fname and lname)
One getter method to return the fname and lname
One setter method for fname and lname
Inside Main:
Create three objects with the following
names
Jill Doe
John James
Jack Smith
When creating the first object (Should
not be an anonymous object)
use the argument-less constructor
Then use the setter method to assign...
I have a little problem about my code. when i'm working on "toString method" in "Course" class, it always say there is a mistake, but i can not fix it: Student class: public class Student { private String firstName; private String lastName; private String id; private boolean tuitionPaid; public Student(String firstName, String lastName, String id, boolean tuitionPaid) { this.firstName=firstName; this.lastName=lastName; this.id=id; this.tuitionPaid=tuitionPaid; } ...
Rewrite the Course class in Listing 10.6 to implement the comparable and the cloneable interfaces. The clone method must allow a deep copy on the students field. In addition, add the equals(Object o) and the toString() methods. Write a test program to invoke the compareTo, clone, equals, and toString methods in a meaningful way. Below is the Listing from the book that needs to be rewritten public class Course { private String courseName; private String[] students = new...