Write an abstract class “Student” and three concrete classes, “UnderGrad” and “Graduate” both inherit from Student and “PostGraduate” that inherits form “Graduate”.
Write the class definition for the abstract class “Student”. The class definition should include private instance variables of type String to hold the student’s first name, a string for his/her major and an int to hold the number of units taken. Getter and setter methods for each of the variables should be included in the class definition. Also include abstract method “calculateTuition()”
abstract public int calculateTuition(int units);
Write three argument constructor in the student class to initialize student’s name, major, and units taken
Have their constructors call the parent’s constructor
These concrete classes should override the abstract method
Undergrad, multiply by $250
Graduate, multiply by $500
Postgraduate, multiply by $750
Tester class should create objects of each and add them to the arraylist and print out the tuition
import java.io.*; import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.Scanner; abstract class Student{ private String firstName,major; private int units; public Student(String firstName, String major, int units) { this.firstName = firstName; this.major = major; this.units = units; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getMajor() { return major; } public void setMajor(String major) { this.major = major; } public int getUnits() { return units; } public void setUnits(int units) { this.units = units; } abstract public int calculateTution(); @Override public String toString() { return "Student{" + "firstName='" + firstName + '\'' + ", major='" + major + '\'' + ", units=" + units + '}'; } } class UnderGraduate extends Student{ public UnderGraduate(String firstName, String major, int units) { super(firstName, major, units); } @Override public int calculateTution() { return this.getUnits()*250; } } class Graduate extends Student{ public Graduate(String firstName, String major, int units) { super(firstName, major, units); } @Override public int calculateTution() { return this.getUnits()*500; } } class PostGraduate extends Graduate{ public PostGraduate(String firstName, String major, int units) { super(firstName, major, units); } @Override public int calculateTution() { return this.getUnits()*750; } } class Main{ public static void main(String[] args) throws IOException { List<Student> students = new ArrayList(); students.add(new UnderGraduate("Jenny","Electronics",8)); students.add(new Graduate("Raj","CSE",5)); students.add(new PostGraduate("Ramesh","IT",2)); for(Student student : students){ System.out.println(student+" , tution fees : "+student.calculateTution()); } } }
OUTPUT :
Write an abstract class “Student” and three concrete classes, “UnderGrad” and “Graduate” both inherit from Student...
A Java Program Purpose: Work with Abstract classes. Purpose: Abstract classes are import because they ensure than any children which inherit from it must implement certain methods. This is done to enforce consistency across many different classes. Problem: Implement a class called Student. This class needs to be abstract and should contain a String for the name, and a String for the major (and they should be private). The class must have a constructor to set the name and major....
Write code for 3 classes described below. - Write abstract class called AbstractPerson which had two methods. One called getSchool which is implemented and returns String "Rutgers". Another abstract method called getType to be implemented by subclasses. - 5 points - Write Faculty class which inherits AbstractPerson and implements getType to return String "Faculty" . - 3 points - Write Student class which inherits AbstractPerson and implements getType to return String "Student" . - 3 points
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...
PART I: Create an abstract Java class named “Student” in a package named “STUDENTS”. This class has 4 attributes: (1) student ID: protected, an integer of 10 digits (2) student name: protected (3) student group code: protected, an integer (1 for undergraduates, 2 for graduate students) (4) student major: protected (e.g.: Business, Computer Sciences, Engineering) Class Student declaration provides a default constructor, get-methods and set-methods for the attributes, a public abstract method (displayStudentData()). PART II: Create a Java class named...
PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1. What is the output of the program as it is written? (Program begins on p. 2) 2. Why would a programmer choose to define a method in an abstract class (such as the Animal constructor method or the getName()method in the code example) vs. defining a method as abstract (such as the makeSound()method in the example)? /********************************************************************** * Program: PRG/421 Week 1 Analyze Assignment * Purpose: Analyze the coding for...
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...
Write the following program in Java. Create an abstract Vehicle class - Vehicle should have a float Speed and string Name, an abstract method Drive, and include a constructor. Create a Tesla class - Tesla inherits from Vehicle. - Tesla has an int Capacity. - Include a constructor with the variables, and use super to set the parent class members. - Override Drive to increase the speed by 1 each time. - Add a toString to print the name, speed,...
Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will have four instance variables: • An instance variable called “year” which will be of type int • An instance variable called “month” which will be of type int • An instance variable called “day” which will be of type int • An instance variable called “description” which will be of type String The “Appointment” class must also implement the following methods: • A getter...
Java
Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstract method payment. Create concrete classes: SalaryEmployee, CommissionEmployee, HourlyEmployee which extend the Employee class and implements that abstract method. A Salary Employee has a salary, a Commision Employee has a commission rate and total sales, and Hourly Employee as an hourly rate and hours worked Software Architecture: The Employee class is the abstract super class and must be instantiated by one of...
java language
Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectangle, Triangle which extend the Shape class and implements the abstract methods. A circle has a radius, a rectangle has width and height, and a triangle has three sides. Software Architecture: The Shape class is the abstract super class and must be instantiated by one of its concrete subclasses: Circle, Rectangle, or...