Answer 3:
(a) The updated classes are as follows:
class Academic {
private:
string name;
string id;
public:
Academic(string name,
string id);
};
class Lecturer : public Academic {
public:
Lecturer(string name,
string id);
void
giveLecture();
};
class Student : public Academic {
public:
Student(string name,
string id);
void
attendLecture();
};
(b): The constructors for the three classes are given below:
Academic::Academic(string _name, string _id)
: name(_name), id(_id)
{
}
Student::Student(string name, string id)
: Academic(name, id)
{
}
Lecturer::Lecturer(string name, string id)
: Academic(name, id)
{
}
Answer 4:
(a) It is assumed that the Person will have a name but id is specific is academics only. The corresponding classes is as follows:
class Person {
private:
string name;
public:
Person(string
name);
};
class Academic : public Person {
private:
string id;
public:
Academic(string name,
string id);
};
(b): The constructors are as follows:
Person::Person(string _name)
: name(_name)
{
}
Academic::Academic(string _name, string _id)
: Person(_name), id(_id)
{
}
(c):
If all the methods are declared private, the code would not compile. This would be because the private constructors of the base class would not be accessible by the derived class. Thus, the constructor for Academic could not call the constructor for Person, and the constructors for Student and Lecturer would not be able to call the constructor for Academic. This would cause a compilation error.
When the constructor is private, it also implies that only member functions can create its objects.
If all the variables were declared public, the member variables of the base class would be accessible from the derived classes as well as functions that are not its members. Thus, the string name which is a member of Person, would be accessible by Academic and other classes as well as outside the derived classes as well. Similarly, string id in class Academic, if made public would be accessible anywhere.
3. Suppose the University has two types of academics: students and lecturers. Both of these have...
3. Suppose the University has two types of academics: students and lecturers. Both of these have names and ids, but students attend lectures while lecturers give them class Studentí private: string name; string id; public: Student(string name, string id); string getName O; string getIDO; void attendLecture (); class Lecturer< private: string name; string id; publiC: Lecturer (string name, string id); string getName (); string getIDO; void giveLecture(); ti (a) Write the header for a class called Academic and update the...
PLEASE DO IN JAVA 3) Add the following method to College: 1. sort(): moves all students to the first positions of the array, and all faculties after that. As an example, let fn indicate faculty n and sn indicate student n. If the array contains s1|f1|f2|s2|s3|f3|s4, after invoking sort the array will contain s1|s2|s3|s4|f1|f2|f3 (this does not have to be done “in place”). Students and faculty are sorted by last name. You can use any number of auxiliary (private) methods, if needed....
A teacher wants to create a list of students in her class. Using the existing Student class in this exercise. Create a static ArrayList called classList that adds a student to the classList whenever a new Student is created. In the constructor, you will have to add that Student to the ArrayList. Coding below was given to edit and use public class ClassListTester { public static void main(String[] args) { //You don't need to change anything here, but feel free...
A teacher wants to create a list of students in her class. Using the existing Student class in this exercise. Create a static ArrayList called classList that adds a student to the classList whenever a new Student is created. In the constructor, you will have to add that Student to the ArrayList. Coding below was given to edit and use public class ClassListTester { public static void main(String[] args) { //You don't need to change anything here, but feel free...
Create an abstract Student class for Parker University. The
class contains fields for student ID number, last name, and annual
tuition. Include a constructor that requires parameters for the ID
number and name. Include get and set methods for each field; the
setTuition() method is abstract.
Create three Student subclasses named UndergraduateStudent,
GraduateStudent, and StudentAtLarge, each with a unique
setTuition() method. Tuition for an UndergraduateStudent is
$4,000 per semester, tuition for a GraduateStudent
is $6,000 per semester, and tuition for...
In this exercise, we will be refactoring a working program. Code refactoring is a process to improve an existing code in term of its internal structure without changing its external behavior. In this particular example, we have three classes Course, Student, Instructor in addition to Main. All classes are well documented. Read through them to understand their structure. In brief, Course models a course that has a title, max capacity an instructor and students. Instructor models a course instructor who...
Write a program in Java that prompts a user for Name and id number. and then the program outputs students GPA MAIN import java.util.StringTokenizer; import javax.swing.JOptionPane; public class Main { public static void main(String[] args) { String thedata = JOptionPane.showInputDialog(null, "Please type in Student Name. ", "Student OOP Program", JOptionPane.INFORMATION_MESSAGE); String name = thedata; Student pupil = new Student(name); //add code here ...
I need help for part B and C
1) Create a new project in NetBeans called Lab6Inheritance. Add a new Java class to the project called Person. 2) The UML class diagram for Person is as follows: Person - name: String - id: int + Person( String name, int id) + getName(): String + getido: int + display(): void 3) Add fields to Person class. 4) Add the constructor and the getters to person class. 5) Add the display() method,...
I need code in java
The Student class:
CODE IN JAVA:
Student.java file:
public class Student {
private String name;
private double gpa;
private int idNumber;
public Student() {
this.name = "";
this.gpa = 0;
this.idNumber = 0;
}
public Student(String name, double gpa, int
idNumber) {
this.name = name;
this.gpa = gpa;
this.idNumber = idNumber;
}
public Student(Student s)...
How to create a constructor that uses parameters from different classes? I have to create a constructor for the PrefferedCustomer class that takes parameters(name, address,phone number, customer id, mailing list status, purchase amount) but these parameters are in superclasses Person and Customer. I have to create an object like the example below....... PreferredCustomer preferredcustomer1 = new PreferredCustomer("John Adams", "Los Angeles, CA", "3235331234", 933, true, 400); System.out.println(preferredcustomer1.toString() + "\n"); public class Person { private String name; private String address; private long...