Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are to create a class called MyStudent .java. This class will compute the Grade Point Average (gpa) for a given student using the formula.

You are to create a class called MyStudent.java. This class will compute the Grade Point Average (gpa) for a given student using the formula. That is, the gpa will be computed as follows:

gpa = Total Grade Point Hours Total Possible Hours,

Total Grade Point Hours = Sum of the (Numeric Grade * Course Hours)

Total Possible Hours = Sum of the Course Hours

The input will come from a file that has the following format:

Letter Grade Course Hours

You are to change the MyStudent.java class as follows:

Create six instance variables:

totalGradePointHours

totalPossibleHours

gpa

studId // Holds Student id

fname // Holds Student First Name

lname // Holds Student Last Name

Add a Constructor:MyStudent(String inStudID, String inFName, String inLName)

The constructor receives three parameters. These parameters will be used to initialize the corresponding instance variables.

Add a MethodsloadGradeInfo(String inGrade, int inCoursehours)

This method will convert the letter grade (inGrade) to a numeric grade (i.e., A is 4.0, B+ is 3.5, etc.) and compute the earned grade point value for a course as follows:

earned grade points = Numeric Grade * inCoursehours

Then, add the earned grade points to totalGradePointHours and add the hours to totalPossibleHours.

Note: This method does not return a value.

computeGPA()

You will need to add the code to this method to compute the gpa using the following calculation:

gpa = Total Grade Point Hours Total Possible Hours

This method should update the gpa instance variable.

Note: This method does not return a value.

getGPA() : double

This is a getter method for the gpa. That is, this method will return the value of the gpa instance variable.

toString() : string

This method is called when printing is done. You will need to construct an output string (strOutput) via concatenation to produced the following output:

Student Id: 111111111

First Name: Alice

Last Name: Jones

GPA: 3.25

-----------------------------------------------------

myInput.txt

B+ 3 C 3 A 4 B 3 A 1

-----------------------------------------------------

//******************************************************************** // MyStudent.java // // The class will compute be used to manage student // information. // //********************************************************************

import java.text.NumberFormat; import java.text.DecimalFormat;

public class MyStudent { //Instance variables

// Class constructor // Methods }

//******************************************************************** // TestMyStudent.java // // This program will test the MyStudent class. // //******************************************************************** import java.util.Scanner; import java.io.*;

public class TestMyStudent { public static void main(String[] args) throws IOException {

MyStudent student = new MyStudent("111111111", "Alice", "Jones");

Scanner fileScan, lineScan; String inputLine;

fileScan = new Scanner(new File("myInput.txt"));

// Read and process each line of the file while (fileScan.hasNext()) { inputLine = fileScan.nextLine();

lineScan = new Scanner(inputLine); lineScan.useDelimiter("\t");

// Print each line String grade; int hours; while (lineScan.hasNext()){ grade = lineScan.next(); // Read the letter grade hours = lineScan.nextInt(); // Read the number of hours student.loadGradeInfo(grade, hours); }// while

}

student.computeGPA(); System.out.println(student);

System.out.println(" \t End of program!!!!"); } }

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

DISCUSS the drivers and outcomes of each turnover method.

Answered: 1 week ago