Kevin321888999

Homework 5 (incomplete)

Nov 28th, 2022
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.15 KB | None | 0 0
  1.  
  2. class StudentBody
  3.  
  4. {
  5.  
  6.     //Creates some Address and Student objects and prints them
  7.  
  8.     public static void main (String[] args) {
  9.  
  10.         Address school = new Address("800 Lancaster Ave. ", "Villanova", "PA ", 19085);
  11.  
  12.         Address jHome = new Address("21 Jump Street", "Blacksburg", "VA ", 24551);
  13.  
  14.         Student john = new Student("John", "Smith", jHome, school, 1 ,2,3 );
  15.  
  16.  
  17.         Address mHome = new Address("123 Main Street", "Euclid", "OH", 44123);
  18.  
  19.         Student marsha = new Student("Marsha", "Jones", mHome, school, 1,2,3);
  20.         Address MalHome=new Address("348 Ridge Road","Orange","CT",06477);
  21.  
  22.         Student Malachi=new Student("Malachi","Sor",MalHome,school,1,2,3);
  23.  
  24.         System.out.println("All tests are out of 10 points!");
  25.         System.out.println(john);
  26.         john.setTestScore(1,3);
  27.         john.setTestScore(2,10);
  28.         john.setTestScore(3,8);
  29.         john.average(3,10,8);
  30.         System.out.println();
  31.         System.out.println(marsha);
  32.         marsha.setTestScore(1,6);
  33.         marsha.setTestScore(2,6);
  34.         marsha.setTestScore(3,7);
  35.         marsha.average(6,6,7);
  36.         System.out.println();
  37.         System.out.println(Malachi);
  38.         Malachi.setTestScore(1,6);
  39.         Malachi.setTestScore(2,7);
  40.         Malachi.setTestScore(3,7);
  41.  
  42.         course Course=new course("History 101");
  43.         System.out.println();
  44.         System.out.println(Course);
  45.         Course.addStudent(1);
  46.         Course.printStudent();
  47.  
  48.  
  49.  
  50.  
  51.  
  52.     }
  53.  
  54. }
  55. class Address {
  56.  
  57.     private String streetAddress, city, state;
  58.     private long zipCode;
  59.  
  60.  
  61.  
  62.     public Address(String street, String town, String st, long zip)
  63.     {
  64.         streetAddress = street;
  65.         city = town;
  66.         state = st;
  67.         zipCode = zip;
  68.     }
  69.  
  70.  
  71.     public String toString()
  72.     {
  73.         String result;
  74.  
  75.  
  76.         result = streetAddress + "\n";
  77.         result += city + ", " + state + zipCode;
  78.  
  79.  
  80.         return result;
  81.  
  82.     }
  83. }
  84.  class Student
  85.  
  86. {
  87.  
  88.  
  89.     private String firstName, lastName;
  90.     private Address homeAddress, schoolAddress;
  91.     private int test1;
  92.     private int test2;
  93.     private int test3;
  94.  
  95.     public Student(String first, String last, Address home, Address school) {
  96.  
  97.         firstName= first;
  98.         lastName = last;
  99.         homeAddress = home;
  100.         schoolAddress = school;
  101.  
  102.     }
  103.     public Student(String first, String last, Address home, Address school,int testA, int testB, int testC) {
  104.  
  105.         firstName = first;
  106.         lastName = last;
  107.         homeAddress = home;
  108.         schoolAddress = school;
  109.         test1=testA;
  110.         test2=testB;
  111.         test3=testC;
  112.     }
  113.  
  114.     void setTestScore(int testnumber, int testscore){
  115.  
  116.         switch(testnumber){
  117.             case 1:
  118.                 test1=testnumber;
  119.                 System.out.println("Test number: "+testnumber+" Test Score: "+testscore);
  120.                 break;
  121.             case 2:
  122.                 test2=testnumber;
  123.                 System.out.println("Test number: "+testnumber+" Test Score: "+testscore);
  124.                 break;
  125.             case 3:
  126.                 test3=testnumber;
  127.                 System.out.println("Test Number: "+testnumber+" Test Score: "+testscore);
  128.                 break;
  129.         }
  130.     }
  131.     double average(int testscore1,int testscore2, int testscore3){
  132.         double averages=(testscore1+testscore2+testscore3)/3;
  133.         System.out.println("Average test score: "+averages);
  134.         return averages;
  135.     }
  136.  
  137.     public String toString()
  138.  
  139.     {
  140.         String result;
  141.  
  142.  
  143.  
  144.         result = firstName + " " + lastName + "\n";
  145.         result += "Home Address:\n" + homeAddress;
  146.         result += "School Address:\n" + schoolAddress;
  147.  
  148.  
  149.         return result;
  150.     }
  151. }
  152. class course{
  153.     private String Name_Course;
  154.     private int Student1;
  155.     private int Student2;
  156.     private int Student3;
  157.     private int  Student4;
  158.     private int Student5;
  159.     private int count=0;
  160.  
  161.     public course(String Name_course) {
  162.         Name_Course=Name_course;
  163.     }
  164.  
  165.     void addStudent(int StudentA){
  166.         switch(StudentA){
  167.             case 1:
  168.                 Student1=StudentA;
  169.                 count++;
  170.             case 2:
  171.                 Student2=StudentA;
  172.                 count++;
  173.  
  174.             case 3:
  175.                 Student3=StudentA;
  176.                 count++;
  177.             case 4:
  178.                 Student4=StudentA;
  179.                 count++;
  180.             case 5:
  181.                 Student5=StudentA;
  182.                 count++;
  183.         }
  184.         System.out.println("The total number of students in the course: "+count);
  185.     }
  186.     public String toString(){
  187.         String Course;
  188.         Course= Name_Course;
  189.  
  190.         return Course;
  191.     }
  192.     public void printStudent(){
  193.         Student2+=Student1;
  194.         Student3+=Student2;
  195.         Student4+=Student3;
  196.         Student5+=Student4;
  197.         System.out.println("Student Number: "+Student1);
  198.         System.out.println("Student Number: "+Student2);
  199.         System.out.println("Student Number: "+Student3);
  200.         System.out.println("Student Number: "+Student4);
  201.         System.out.println("Student Number: "+Student5);
  202.  
  203.     }
  204. }
Advertisement
Add Comment
Please, Sign In to add comment