Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Mammal.java
- public class Mammal{
- private int age;
- private double weight;
- Mammal(double weight, int age){
- this.age = age;
- this.weight = weight;
- }
- public double getWeight(){
- return weight;
- }
- public int getAge(){
- return age;
- }
- }
- // Human.java
- public class Human extends Mammal{
- double height;
- Human(double h, double w, int a) {
- super(w, a);
- height = h;
- }
- double getHeight(){
- return height;
- }
- }
- // Student.java
- public class Student extends Human{
- String major;
- double gpa;
- int creditHours;
- Student(String m, double g, int ch, double h, double w, int a){
- super(h, w, a);
- major = m;
- gpa = g;
- creditHours = ch;
- }
- String getMajor(){
- return major;
- }
- double getGpa(){
- return gpa;
- }
- String getYear(){
- if(creditHours < 32) return "Freshman";
- else if(creditHours < 64) return "Sophomore";
- else if(creditHours < 96) return "Junior";
- else return "Senior";
- }
- }
- // Doctor.java
- public class Doctor extends Human{
- int years;
- String Speciality;
- Doctor(int y, String s, double h, double w, int a){
- super(h, w, a);
- years = y;
- Speciality = s;
- }
- int getYears(){
- return years;
- }
- String getSpecialty(){
- return Speciality;
- }
- double getSalary(){
- return 40000 + (years - 1) * 5000;
- }
- }
- // Lab4.java
- public class Lab4{
- public static void main(String args[]){
- Student alex = new Student("CS", 3.4, 54, 170, 150, 18);
- Doctor jack = new Doctor(4, "Dermatology", 173, 179, 40);
- System.out.println(alex.getMajor() + ", " + alex.getGpa() + ", " + alex.getYear() + ", " + alex.getAge());
- System.out.println(jack.getSpecialty() + ", " + jack.getHeight() + ", " + jack.getWeight() + ", " + jack.getSalary());
- }
- }
- https://d2vlcm61l7u1fs.cloudfront.net/media%2F6f4%2F6f478b1b-1f18-46ee-a681-1f628c2a7339%2FphpMUbs9J.png
Advertisement
Add Comment
Please, Sign In to add comment