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...
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 PROJECT Step 1: Create an application named YourInitials_Project 3 that uses a class to convert...
JAVA PROJECT Step 1: Create an application named YourInitials_Project 3 that uses a class to convert number grades to letter grades and another class for data validation. Make comments including your name, date, and project name as well as appropriate comments throughout your application that include the step number. Step 2: Create code to print Titles Step 3: Create a variable to hold user’s choice. Remember that all variables must begin with your initials and should be descriptive. Step 4:...
IN JAVA PLEASE Create a class called Child with an instance data values: name and age....
IN JAVA PLEASE Create a class called Child with an instance data values: name and age. a. Define a constructor to accept and initialize instance data b. include setter and getter methods for instance data c. include a toString method that returns a one line description of the child
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A private String to represent the first name. • A private String to represent the last name. • A public constructor that accepts two values and assigns them to the above properties. • Public methods named getProperty (e.g. getFirstName) to return the value of the property. • Public methods named setProperty ( e.g. setFirstName)to assign values to each property by using a single argument passed...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT