Description of the student

Assignment Help Basic Computer Science
Reference no: EM132184124

Modify the Student class from the chapter 7 source files as follows. Each student object should also contain the scores for three tests. Provide a constructor that sets all instance values based on parameter values. Overload the constructor such that each test score is assumed to be initially zero. Provide a method called setTestScore that accepts two parameters: the test number (1 through 3) and the score. Also provide a method called getTestScore that accepts the test number and returns the appropriate score. Provide a method called average that computes and returns the average test score for this student. Modify the toString method such that the test scores and average are included in the description of the student.  

PP 7.3 - Write a class called Course that represents a course taken at a school. Represent each student using the modified Student class from the previous programming project. Use an ArrayList in the Course to store the students taking that course. The constructor of the Course class should accept only the name of the course. Provide a method called addStudent that accepts one Student parameter. Provide a method called average that computes and returns the average of all students' test score averages. Provide a method called roll that prints all students in the course. Create a driver class named School with a main method that creates a course and several students, adds the students to the course, prints a roll, and prints the overall course test average.

address.java

public class Address {

   private String streetAddress, city, state;
   private long zipCode;

   // -----------------------------------------------------------------
   // Constructor: Sets up this address with the specified data.
   // -----------------------------------------------------------------
   public Address(String street, String town, String st, long zip) {

       streetAddress = street;
       city = town;
       state = st;
       zipCode = zip;
   }

   // -----------------------------------------------------------------
   // Returns a description of this Address object.
   // -----------------------------------------------------------------
   public String toString() {
       String result;
       result = streetAddress + "n";
       result += city + ", " + state + " " + zipCode;
       return result;
   }
}

Course.java

public class Course {
   private int test1;
   private int test2;
   private int test3;

   public Course(int t1, int t2, int t3) {
       test1 = t1;
       test2 = t2;
       test3 = t3;
   }

   public String toString() {
       String result;

       result = "Test 1 Score: " + test1 + "n";
       result += "Test 2 Score: " + test2 + "n";
       result += "Test 3 Score: " + test3 + "n";
       ;

       return result;
   }

   // All getter and setter methods
   public int getTest1() {
       return test1;
   }

   public void setTest1(int test1) {
       this.test1 = test1;
   }

   public int getTest2() {
       return test2;
   }

   public void setTest2(int test2) {
       this.test2 = test2;
   }

   public int getTest3() {
       return test3;
   }

   public void setTest3(int test3) {
       this.test3 = test3;
   }

}

School.java

public class School {
   
   // Main method that creates a course and seceral students
   
   public static void main(String[] args) {

       Address school = new Address("82 College Cir.", "Dahlonega", "GA", 30597);
       Address jHome = new Address("1234 Main Street", "Cumming", "GA", 30041);
       Student john = new Student("John", "Smith", jHome, school);
       Address mHome = new Address("123 Main Street", "Gainseville", "GA", 30501);
       Student matt = new Student("Matt", "Smith", mHome, school, 90, 87, 94);

       System.out.println(john);
       System.out.println(matt);

       john.setTestScore(1, 87);
       john.setTestScore(2, 90);
       john.setTestScore(3, 85);
       matt.setTestScore(2, 89);

       System.out.println("John Smith - Test 1: " + john.getTestScore(1));
       System.out.println("Matt Smith - Test 2: " + matt.getTestScore(2));

       System.out.println();
       System.out.println(john);
       System.out.println(matt);
   }
}

Student.java

public class Student {

   private String firstName, lastName;
   private Address homeAddress, schoolAddress;
   private Course testScores;

   // -----------------------------------------------------------------
   // Constructor: Sets up this student with the specified values.
   // -----------------------------------------------------------------
   public Student(String first, String last, Address home, Address school) {
       firstName = first;
       lastName = last;
       homeAddress = home;
       schoolAddress = school;
      
       //Crate testScore with default test score of zero
       testScores = new Course(0, 0, 0);
   }

   //Overloaded constructor
   public Student(String first, String last, Address home, Address school,int test1,int test2,int test3 ) {
       firstName = first;
       lastName = last;
       homeAddress = home;
       schoolAddress = school;
      
       //Crate testScore with given test scores
       testScores = new Course(test1, test2, test3);
   }

   //Method to set test score
   public void setTestScore(int testNumber,int testScore) {
      
       if(testNumber==1) {
           testScores.setTest1(testScore);
       }
       else if(testNumber==2) {
           testScores.setTest2(testScore);
       }
       else if(testNumber==3) {
           testScores.setTest3(testScore);
       }
   }
 
   //Method to return test score by test number
   public int getTestScore(int testNumber) {
      
       if(testNumber==1) {
           return testScores.getTest1();
       }
       else if(testNumber==2) {
           return testScores.getTest2();
       }
       else if(testNumber==3) {
           return testScores.getTest3();
       } else {
           return 0;
       }
   }
 
   //Method to get average test score
   public double getAverageTestScores() {
      
       double avg;
      
       avg = (testScores.getTest1() + testScores.getTest2() + testScores.getTest3())/3.0;
      
       return avg;
   }
 
   public String toString() {
       String result;
       result = "------------- "+firstName + " " + lastName + " -------------n";
       result += "Home Address:" + homeAddress + "n";
       result += "School Address:" + schoolAddress+ "n";
       result += "Test 1 score:" + testScores.getTest1() + "n";
       result += "Test 2 score:" + testScores.getTest2() + "n";
       result += "Test 3 score:" + testScores.getTest3() + "n";
       result += "Average test score:" + getAverageTestScores() + "n";

       return result;
   }
}

Reference no: EM132184124

Questions Cloud

What is the role in leading the initiatives : What is their role in leading the initiatives? What actions are important to communicate and establish alignment across the merged organization?
Prepare journal entries to record the march transactions : ACCT 212 - Prepare journal entries to record the March transactions in the General Journal below. Remember that Debits must equal Credits
How the conflicting beliefs can lead to feelings : In 1991 the American with Disabilities Act was implemented across the United States. Deaf individuals do not consider themselves disabled; however.
How the activity applies the new reading comprehension : Explain how the activity applies the new reading comprehension strategy and addresses the issues in the scenario.
Description of the student : Modify the Student class from the chapter 7 source files as follows. Each student object should also contain the scores for three tests.
Explain any key terms or definitions relevant to discussion : Explain any key terms or definitions relevant to the discussion. Include research on the issue to see what other experts are saying.
Requires significant portion of the product franchisee : Very often, Franchisor requires a significant portion of the product a Franchisee to be purchased either from Franchisor directly or from "approved" supplier.
Explain two alternative approaches to phonics instruction : Explain 2 alternative approaches to phonics instruction that you could use to help this student instead of using the synthetic approach.
Bottom up model and see the big picture of the system : What are your thoughts on the possibility to use the bottom up model and see the big picture of the system (is it possible ... why or why not)?

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Under what conditions does the splay tree actually save time

Compare your splay tree against an implementation of the standard BST over a wide variety of input data. Under what conditions does the splay tree actually save time?

  What percentage of the common space

What percentage of the common space do they successfully clean? Please show your work and explain your answers

  Explain the operation of the device from a physics perspec

Explain the operation of the device from a physics perspective and discuss the main features or specifications. Explain how the packaging, assembly, or housing makes the device appropriate for the unique environmental conditions. Be sure to provide a..

  Discuss how a successful organization

Discuss how a successful organization should have the following multiple layers of security in place for the protection of its operations:

  Discuss some of the expected trends that will continue

discuss some of the expected trends that will continue or emerge in the coming years

  Memory allocation errors

The application should display all daily. Use a user-defined function as handler of memory allocation errors. The user-defined function should be registered as a default handler of new failures temperatures as well as average weekly temperatures in a..

  What is the g-efficiency of each design

Calculate the V-efficiency of each design relative to the best design that you found in part (d).

  What is a reversal of fortune

a) What is a 'reversal of fortune'? Explain briefly. b) At what specific point in time does it happen?

  Which served as a point-of-sale cash register and terminal

ABC was launched as a retail dive shop with 10 employees in Turkey by Mr Beans. As a small business owner, Beans wanted to offer the e-commerce capabilities of a large firm using a small company's budget. Within a year, he had installed an Ethernet L..

  Compute the data rate of the human eye using information

Compute the data rate of the human eye using the following information. The visual field consists of about 106 elements (pixels). Each pixel can be reduced to a superposition of the three primary colors.

  How well the above data are predicted by correlation

Express your results in terms of the percent difference between the experimentally determined Nusselt number and that calculated from the equation.

  Research the internet to determine

Research the internet to determine if there are any DDBMSs that follow all 12 rules. Explain on examples.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd