Kevin321888999

Homework5 (incomplete)

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