Documente Academic
Documente Profesional
Documente Cultură
package q1.pkgfinal;
import java.util.*;
public class Q1Final {
public static void main(String[] args) {
double amount;
double interest;
int months;
double Total =0;
Inheritance
Main page
public class InheritanceExercise {
public static void main(String[] args) {
employee a = new employee("phat","2206",1000);
graduateStudent b = new graduateStudent("phat","2206",4.00);
undergraduateStudent c = new undergraduateStudent("phat","2208",3.99);
People
package inheritanceexercise;
public abstract class people {
private String name;
@Override
public String toString()
{
return String.format("Name: %s\n", getName());
}
public people(String n)
{
name = n;
}
Employee
public class employee extends people {
private String employeeID;
private double salary;
public employee(String n, String ID, double s)
{
super(n);
employeeID = ID;
salary = s;
}
@Override
public String toString()
{
return String.format("Employee:\n %s EmployeeID: %s \n Salary:
%.2f\n",super.toString(), getEmployeeID(), getSalary());
}
public String getEmployeeID() {
return employeeID;
}
public void setEmployeeID(String employeeID) {
this.employeeID = employeeID;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
Student
public class student extends people {
private String studentID;
private double GPA;
public student(String n, String ID, double G)
{
super(n);
studentID = ID;
GPA = G;
}
@Override
public String toString()
{
return String.format("%s StudentID: %s\n GPA: %.2f\n",super.toString(),
getStudentID(), getGPA());
}
public String getStudentID() {
return studentID;
}
public void setStudentID(String studentID) {
this.studentID = studentID;
}
public double getGPA() {
return GPA;
}
public void setGPA(double GPA) {
this.GPA = GPA;
}
}
Graduate Student
public class graduateStudent extends student {
private String Status = "Graduate";
private String thesisGrade = "Incomplete";
public graduateStudent(String n, String ID , double G)
{
super(n,ID,G);
}
@Override
public String toString()
{
return String.format("Graduate Student:\n %s Status: %s\n Thesis Grade:
%s\n",super.toString() , getStatus(), getThesisGrade());
}
public String getThesisGrade() {
return thesisGrade;
}
public void setThesisGrade(String thesisGrade) {
this.thesisGrade = thesisGrade;
}
public String getStatus() {
return Status;
}
public void setStatus(String Status) {
this.Status = Status;
}
Undergraduate Student
Interface
package q4.pkgfinal;
public interface Payable {
public void Pay();
}
@Override
public void Pay()
{
System.out.println("Employeee needs to pay tax");
}
@Override
public void Pay()
{
System.out.println("Student needs to pay tuition");
}
Arrays.sort(num);
Arrays.sort(num);
System.out.println("The decreasing order of the number is:");
for (int j = 2; j >= 0; j --)
{
System.out.println(num[j]);
}
}