Question

In: Computer Science

Java Create a Project named Chap4b 1. Create a Student class with instance data as follows:...

Java

Create a Project named Chap4b

1. Create a Student class with instance data as follows: student id, test1, test2, and test3.

2. Create one constructor with parameter values for all instance data fields.

3. Create getters and setters for all instance data fields.

4. Provide a method called calcAverage that computes and returns the average test score for an object to the driver program.

5. Create a displayInfo method that receives the average from the driver program and displays student ID, all test scores, and the average test score. Create a driver program named TestScores

1. Create 2 student objects as follows: Student FC123 is created with test scores: 100, 80, 94 Student FC456 is created with test scores: 78, 92, 80

2. Call calcAverage() and displayInfo() for both student objects from the driver program.

Expected Output:

Student ID: FC123

Test 1 score: 100

Test 2 score: 80

Test 3 score: 94

Average test score: 91.33

Student ID: FC456

Test 1 score: 78

Test 2 score: 92

Test 3 score: 80

Average test score: 83.33

Solutions

Expert Solution

Project named Chap4b


public class Student {

   private static final String FC123 = "FC123"; // student id's
   private static final String FC456 = "FC456"; // student id's

   private static String Student_id;
  
   private int test1;
   private int test2;
   private int test3;

  

   public Student(String id) {
       // TODO Auto-generated constructor stub
      
       this.setStudent_id(id); // constructor where student id's will come
      
      
   }
  
   public double calcAverage(String id, int i, int j,int k) {
      
       double sum = (i + j + k);
       //System.out.println("Sum: "+sum);         
       double Avg = sum/3;
         
         
         
       String student_id = (String) id;

       displayInfo(student_id, i, j, k,Avg);  
      

       return Avg;
      
   }
  
   public double displayInfo(String student_id,int i,int j,int k,double avg) {
      
      
       System.out.println("Student ID: "+student_id);
       System.out.println("Test 1 score: "+i);
       System.out.println("Test 2 score: "+j);
       System.out.println("Test 3 score: "+k);
       System.out.println("Average :"+avg);
  
       //System.out.println("Student ID: "+student_id2);
      
       return 0;
   }

   public static void main(String[] args) {
       // TODO Auto-generated method stub
      
String std1 = (String) FC123;
String std2 = (String) FC456;
  
       Student FC123 = new Student(std1);
       FC123.calcAverage(std1,100,80,94);
      
       Student FC456 = new Student(std2);
       FC456.calcAverage(std2,78,92,80);
   }

   public int getTest3() {
       return test3;
   }

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

   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 String getStudent_id() {
       return Student_id;
   }

   public void setStudent_id(String id) {
       Student_id = (String) id;
   }

}

my output :

Student ID: FC123
Test 1 score: 100
Test 2 score: 80
Test 3 score: 94
Average :91.33333333333333
Student ID: FC456
Test 1 score: 78
Test 2 score: 92
Test 3 score: 80
Average :83.33333333333333


Related Solutions

1. Create a new Java project called L2 and a class named L2 2. Create a...
1. Create a new Java project called L2 and a class named L2 2. Create a second class called ArrayExaminer. 3. In the ArrayExaminer class declare the following instance variables: a. String named textFileName b. Array of 20 integers named numArray (Only do the 1st half of the declaration here: int [] numArray; ) c. Integer variable named largest d. Integer value named largestIndex 4. Add the following methods to this class: a. A constructor with one String parameter that...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class named Book. In the Book class: Add the following private instance variables: title (String) author (String) rating (int) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. Add a second constructor that receives only 2 String parameters, inTitle and inAuthor. This constructor should only assign input parameter values to title and...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class named Employee. In the Employee class: Add the following private instance variables: name (String) job (String) salary (double) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. (Refer to the Tutorial3 program constructor if needed to remember how to do this.) Add a public String method named getName (no parameter) that...
Create a Java project called 5 and a class named 5 Create a second new class...
Create a Java project called 5 and a class named 5 Create a second new class named CoinFlipper Add 2 int instance variables named headsCount and tailsCount Add a constructor with no parameters that sets both instance variables to 0; Add a public int method named flipCoin (no parameters). It should generate a random number between 0 & 1 and return that number. (Important note: put the Random randomNumbers = new Random(); statement before all the methods, just under the...
Create a new Java project called lab1 and a class named Lab1 Create a second class...
Create a new Java project called lab1 and a class named Lab1 Create a second class called VolumeCalculator. Add a static field named PI which = 1415 Add the following static methods: double static method named sphere that receives 1 double parameter (radius) and returns the volume of a sphere. double static method named cylinder that receives 2 double parameters (radius & height) and returns the volume of a cylinder. double static method named cube that receives 1 double parameter...
Create a Java class named Trivia that contains three instance variables, question of type String that...
Create a Java class named Trivia that contains three instance variables, question of type String that stores the question of the trivia, answer of type String that stores the answer to the question, and points of type integer that stores the points’ value between 1 and 3 based on the difficulty of the question. Also create the following methods: getQuestion( ) – it will return the question. getAnswer( ) – it will return the answer. getPoints( ) – it will...
This is 1 java question with its parts. Thanks so much! Create a class named Student...
This is 1 java question with its parts. Thanks so much! Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average....
In java: -Create a class named Animal
In java: -Create a class named Animal
Create a Java class named Package that contains the following: Package should have three private instance...
Create a Java class named Package that contains the following: Package should have three private instance variables of type double named length, width, and height. Package should have one private instance variable of the type Scanner named input, initialized to System.in. No-args (explicit default) public constructor, which initializes all three double instance variables to 1.0.   Initial (parameterized) public constructor, which defines three parameters of type double, named length, width, and height, which are used to initialize the instance variables of...
Java Implement a class MyInteger that contains: • An int data field/instance variable named value that...
Java Implement a class MyInteger that contains: • An int data field/instance variable named value that stores the int value represented by this object. • A constructor that creates a MyInteger object for a default int value. What default value did you choose? What other values did you consider? Why did you make this choice? • A constructor that creates a MyInteger object for a specified int value. • A getter method, valueOf(), that returns value. • A setter method,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT