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);
- 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);
- john.average(3,10,8);
- System.out.println();
- System.out.println(marsha);
- marsha.setTestScore(1,6);
- marsha.setTestScore(2,6);
- marsha.setTestScore(3,7);
- marsha.average(6,6,7);
- System.out.println();
- System.out.println(Malachi);
- Malachi.setTestScore(1,6);
- Malachi.setTestScore(2,7);
- Malachi.setTestScore(3,7);
- course Course=new course("History 101");
- System.out.println();
- System.out.println(Course);
- Course.addStudent(1);
- Course.printStudent();
- }
- }
- 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;
- }
- }
- double average(int testscore1,int testscore2, int testscore3){
- double averages=(testscore1+testscore2+testscore3)/3;
- System.out.println("Average test score: "+averages);
- return averages;
- }
- 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 int Student1;
- private int Student2;
- private int Student3;
- private int Student4;
- private int Student5;
- private int count=0;
- public course(String Name_course) {
- Name_Course=Name_course;
- }
- void addStudent(int StudentA){
- switch(StudentA){
- case 1:
- Student1=StudentA;
- count++;
- case 2:
- Student2=StudentA;
- count++;
- case 3:
- Student3=StudentA;
- count++;
- case 4:
- Student4=StudentA;
- count++;
- case 5:
- 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(){
- Student2+=Student1;
- Student3+=Student2;
- Student4+=Student3;
- Student5+=Student4;
- System.out.println("Student Number: "+Student1);
- System.out.println("Student Number: "+Student2);
- System.out.println("Student Number: "+Student3);
- System.out.println("Student Number: "+Student4);
- System.out.println("Student Number: "+Student5);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment