jaredec18

Untitled

Sep 24th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. // Mammal.java
  2.  
  3. public class Mammal{
  4. private int age;
  5. private double weight;
  6. Mammal(double weight, int age){
  7. this.age = age;
  8. this.weight = weight;
  9. }
  10. public double getWeight(){
  11. return weight;
  12. }
  13. public int getAge(){
  14. return age;
  15. }
  16. }
  17.  
  18. // Human.java
  19.  
  20. public class Human extends Mammal{
  21. double height;
  22. Human(double h, double w, int a) {
  23. super(w, a);
  24. height = h;
  25. }
  26. double getHeight(){
  27. return height;
  28. }
  29. }
  30.  
  31. // Student.java
  32.  
  33. public class Student extends Human{
  34. String major;
  35. double gpa;
  36. int creditHours;
  37. Student(String m, double g, int ch, double h, double w, int a){
  38. super(h, w, a);
  39. major = m;
  40. gpa = g;
  41. creditHours = ch;
  42. }
  43. String getMajor(){
  44. return major;
  45. }
  46. double getGpa(){
  47. return gpa;
  48. }
  49. String getYear(){
  50. if(creditHours < 32) return "Freshman";
  51. else if(creditHours < 64) return "Sophomore";
  52. else if(creditHours < 96) return "Junior";
  53. else return "Senior";
  54. }
  55. }
  56.  
  57. // Doctor.java
  58.  
  59. public class Doctor extends Human{
  60. int years;
  61. String Speciality;
  62. Doctor(int y, String s, double h, double w, int a){
  63. super(h, w, a);
  64. years = y;
  65. Speciality = s;
  66. }
  67. int getYears(){
  68. return years;
  69. }
  70. String getSpecialty(){
  71. return Speciality;
  72. }
  73. double getSalary(){
  74. return 40000 + (years - 1) * 5000;
  75. }
  76. }
  77.  
  78. // Lab4.java
  79.  
  80. public class Lab4{
  81. public static void main(String args[]){
  82. Student alex = new Student("CS", 3.4, 54, 170, 150, 18);
  83. Doctor jack = new Doctor(4, "Dermatology", 173, 179, 40);
  84. System.out.println(alex.getMajor() + ", " + alex.getGpa() + ", " + alex.getYear() + ", " + alex.getAge());
  85. System.out.println(jack.getSpecialty() + ", " + jack.getHeight() + ", " + jack.getWeight() + ", " + jack.getSalary());
  86.  
  87. }
  88. }
  89.  
  90. https://d2vlcm61l7u1fs.cloudfront.net/media%2F6f4%2F6f478b1b-1f18-46ee-a681-1f628c2a7339%2FphpMUbs9J.png
Advertisement
Add Comment
Please, Sign In to add comment