Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class StudentBody
- {
- //Creates some Address and Student objects and prints them
- public static void main (String[] args) {
- Address school = new Address("800 Lancaster Ave. ", "Villanova", "PA ", 19085);
- Address jHome = new Address("21 Jump Street", "Blacksburg", "VA ", 24551);
- Student John = new Student("John", "Smith", jHome, school, 1 ,2,3 );
- Address mHome = new Address("123 Main Street", "Euclid", "OH", 44123);
- Student Marsha = new Student("Marsha", "Jones", mHome, school, 1,2,3);
- Address MalHome=new Address("348 Ridge Road","Orange","CT",06477);
- Student Malachi=new Student("Malachi","Sor",MalHome,school,1,2,3);
- Address DevonHome=new Address("332 Beagle Street","Milford","CT",78999);
- Student Devon=new Student("Devon","Smear",DevonHome,school,1,2,3 );
- Address SherryHome=new Address("555 Orange Grove Street", "Bridgeport","CT",89999);
- Student Sherry=new Student("Sherry","White",SherryHome,school,1,2,3);
- System.out.println("All tests are out of 10 points!");
- System.out.println(John);
- John.setTestScore(1,3);
- John.setTestScore(2,10);
- John.setTestScore(3,8);
- System.out.println();
- System.out.println(Marsha);
- Marsha.setTestScore(1,6);
- Marsha.setTestScore(2,6);
- Marsha.setTestScore(3,7);
- System.out.println();
- System.out.println(Malachi);
- Malachi.setTestScore(1,6);
- Malachi.setTestScore(2,7);
- Malachi.setTestScore(3,7);
- System.out.println();
- System.out.println(Devon);
- Devon.setTestScore(1,7);
- Devon.setTestScore(2,8);
- Devon.setTestScore(3,9);
- System.out.println();
- System.out.println(Sherry);
- Sherry.setTestScore(1,9);
- Sherry.setTestScore(2,8);
- Sherry.setTestScore(3,8);
- course Course=new course("History 101");
- System.out.println();
- System.out.println(Course);
- Course.addStudent("John");
- System.out.println("\nThe list of Student names in class: ");
- Course.printStudent("John");
- }
- }
- class Address {
- private String streetAddress, city, state;
- private long zipCode;
- public Address(String street, String town, String st, long zip)
- {
- streetAddress = street;
- city = town;
- state = st;
- zipCode = zip;
- }
- public String toString()
- {
- String result;
- result = streetAddress + "\n";
- result += city + ", " + state + zipCode;
- return result;
- }
- }
- class Student {
- private String firstName, lastName;
- private Address homeAddress, schoolAddress;
- private int test1;
- private int test2;
- private int test3;
- public Student(String first, String last, Address home, Address school) {
- firstName= first;
- lastName = last;
- homeAddress = home;
- schoolAddress = school;
- }
- public Student(String first, String last, Address home, Address school,int testA, int testB, int testC) {
- firstName = first;
- lastName = last;
- homeAddress = home;
- schoolAddress = school;
- test1=testA;
- test2=testB;
- test3=testC;
- }
- void setTestScore(int testnumber, int testscore){
- switch(testnumber){
- case 1:
- test1=testnumber;
- System.out.println("Test number: "+testnumber+" Test Score: "+testscore);
- break;
- case 2:
- test2=testnumber;
- System.out.println("Test number: "+testnumber+" Test Score: "+testscore);
- break;
- case 3:
- test3=testnumber;
- System.out.println("Test Number: "+testnumber+" Test Score: "+testscore);
- break;
- }
- }
- public String toString()
- {
- String result;
- result = firstName + " " + lastName + "\n";
- result += "Home Address:\n" + homeAddress;
- result += "School Address:\n" + schoolAddress;
- return result;
- }
- }
- class course{
- private String Name_Course;
- private String Student1;
- private String Student2;
- private String Student3;
- private String Student4;
- private String Student5;
- private int count=0;
- public course(String Name_course) {
- Name_Course=Name_course;
- }
- void addStudent(String StudentA){
- switch(StudentA){
- case "John":
- Student1=StudentA;
- count++;
- case "Marsha":
- Student2=StudentA;
- count++;
- case "Malachi":
- Student3=StudentA;
- count++;
- case "Devon":
- Student4=StudentA;
- count++;
- case "Sherry":
- Student5=StudentA;
- count++;
- }
- System.out.println("The total number of students in the course: "+count);
- }
- public String toString(){
- String Course;
- Course= Name_Course;
- return Course;
- }
- public void printStudent(String Student_NameS){
- switch(Student_NameS){
- case "John":
- Student1=Student_NameS;
- System.out.println("John");
- case "Marsha":
- Student2=Student_NameS;
- System.out.println("Marsha");
- case "Malachi":
- Student3=Student_NameS;
- System.out.println("Malachi");
- case "Devon":
- Student4=Student_NameS;
- System.out.println("Devon");
- case "Sherry":
- Student5=Student_NameS;
- System.out.println("Sherry");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment