Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. given the following class: public class Student implements Serializable { private int id; private String name; private int birthYear; private char gender; //value 'M'

1. given the following class: public class Student implements Serializable { private int id; private String name; private int birthYear; private char gender; //value 'M' or 'F' private double gpa; Student(int id, String name, int birthYear, char gender) { this.id = id; this.name = name; this.birthYear = birthYear; this.gender = gender; } public int getBitrhYear() { return birthYear; } public double getGPA() { return gpa; } public char getGender() { return gender; } }

Create a separate test class with name test having the following: a) A static method printFile that takes a string f1 representing a serial file name of Student objects and print all objects inside that file. b) A static int method countRecord that takes a string f1 representing a serial file name of Student objects and return number of objects inside that file. c) A static method filterStudents that takes a string f1 representing a serial file name of Student objects and separate male and female students into separate binary files with names male.ser and female.ser. d) A static double method sumGPA that takes a string f1 representing a serial file name of Student objects and return sum of GPA for all students inside that file. e) A main method that creates a binary file with name student.ser of seven Student objects. Then i. Print the file student.ser (using a call to printFile method). ii. Call method filterStudents. iii. Print files male.ser and female.ser (using two calls to printFile method). iv. Calculate GPA average for males and female (using methods countRecord and sumGPA).

================================ ========================= 2. Using class Student on Q1, a) Update class Student with name Student1 and do the following: i. Implement inner private class Subject which has o Three instance variables: id, name, credit. o A constructor. ii. Add to Student1 as an instance variable an array of subjects of size 5. iii. Add a boolean method addSubject that takes an id, name and credit and add a subject to the array. Dont add if the array is full and return false. iv. Add a toString method that return student info with all his/her subjects. b) Create test class HW04Q2 then: i. Create an object of student. Test methods addSubject and toString . Note: include both classes Student1 and HW04Q2 in one java file.

(in java program language) pls solve number 2 also

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

User Defined Tensor Data Analysis

Authors: Bin Dong ,Kesheng Wu ,Suren Byna

1st Edition

3030707490, 978-3030707491

More Books

Students also viewed these Databases questions