Question: (1a) DESCRIPITION Write a Java program that will compute and display the final grades for students in a class. A student's final grade is determined

(1a)

DESCRIPITION

Write a Java program that will compute and display the final grades for students in a class. A student's final grade is determined from the scores obtained in the class test. Each student in the class may be given a different number of tests as determined by the instructor. The final grade is determined by the average of the scores in all the tests given.

For each student, the program will input student id, name, the number of tests given and scores in each of the tests. The scores in each of the tests will vary from 0 to 100. Each test will carry the same weight. The final grade will be computed by taking the average of the scores in all the tests given (i.e. by adding the scores in all the tests and dividing it with the number of tests given). The final grade will be assigned depending upon the percentage of total points in the tests given as follows:

A 90 to 100%

B 80 to 89%

C 70 to 79%

D 60 to 69%

F 0 to 59%

INSTRUTIONS

Use a String variable for keeping final grade. For comparing two strings use the method: equals( ) or equalsIgnoreCase ( ).

For this assignment create the following classes.

Student class

Create a class Student that provides the following:

Private instance variables for holding student id (int), name (String), test scores (an int array).

A public constructor with parameters for initializing student id (int), name (String) and test scores. The test scores are passed as an array of int.

A public method for returning the final grade as a String ( A, B etc).

Accessor (getter) methods for getting student id and name.

TestStudent class

Write a class TestStudent containing the main method.

Method main

The method main will do the following:

Prompt the user to enter the total number of students (say n).

Create an array of n references (for holding n Student object references). (The Student objects will be created in the next step).

Create n Student objects. Do this by setting up an n count loop. In each pass through the loop, do the following:

a. Ask the user to enter data for one student in a single dialog box.

b. Separate data elements using a StringTokenizer object.

c. Create a Student object initialized with data provided by the user and store its reference in the appropriate element of the array of student references created above.

Display the student results by grade type. First display all students with grade A, then all students with grade B etc. Do this using one of the following two methods. (It is suggested that you use method II as it will help you to learn about String arrays).

Method to use:

Create a String array out of 5 Strings. Use out [0] for accumulating output relating to A students, out[1] for B students etc. Write a static method displayRestult to display output. Call the static method displayResult and pass it the array out.

displayResult

For method II above, write a static method displayResult. This method will receive a String array and display the contents of all elements of the String array one by one. Here is a proposed header for the method:

public static void displayResult (String [ ] s)

{

}

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

(1b)

DESCRIPTION

Write a Java program that will compute and display the final grades for a list of students. A students final grade is determined from the scores obtained in the class tests. Each student in the class may be given a different number of tests as determined by the instructor. The final grade is determined by the average of the scores in all the tests given.

This program is an enhancement of a previous exercise that did the same. However, this exercise will additionally provide for assigning a CR or NCR (Credit or No Credit) grade.

For each student, the program will input student id, name, the number of tests given and scores in each of the tests.

Additionally, it will input the grade type: Letter or Credit. The grade type of Letter will indicate that student will receive a grade of A, B, C, D, or F. The grade type of Credit will indicate that the student will receive a grade of CR or NCR.

The scores in each of the tests will vary from 0 to 100. Each test will carry the same weight. The final grade will be computed by taking the average of the scores in all the tests given (i.e. by adding the scores in all the tests and dividing it with the number of tests given). The final grade will be assigned depending upon the percentage of total points in the tests given as follows:

A 90 to 100%

B 80 to 89%

C 70 to 79%

D 60 to 69%

F 0 to 59%

Additionally, for a grade type of Credit, the grade will be determined as follows:

If the student qualifies for a C or better grade, the student will be assigned a CR (Credit) grade. Otherwise, the student will be assigned an NCR (No Credit) grade.

INSTRUCTIONS

Use a String variable for keeping final grade.

Use a String variable for keeping grade type.

Comparing Strings

For comparing two Strings for equality, use one of the following two String methods:

equals

equalsIgnoreCase

IMPLEMENTATION

For this assignment create the following classes.

Student class

Create a class Student that provides the following:

Private instance variables for holding student id (int), name (String), test scores (an int array).

A public constructor with parameters for initializing student id (int), name (String) and test scores. The test scores are passed as an array of int.

A public method for returning the final grade.

Accessor (getter) methods for getting student id, name, test scores .

Instead of rewriting this class, you may copy the contents of the same class from a previous exercise.

StudentExt class.

Create a class StudentExt that extends the class Student above. This class will extend the class Student in order to provide additional functionality for assigning a CR or NCR grade.

The class will provide the following:

A private String instance variable gradeType for indicating the grade type (Letter or Credit). The variable gradeType will record Letter for a letter grade type and Credit for Credit/No Credit grade type.

A public constructor for initializing student id (int), name (String), test scores (an int array) and grade type (String). This constructor will call the parent class constructor for initializing student id, name and test scores. It will initialize the grade type itself directly.

A public method for returning the final grade. This method will over ride the parent class method used for computing the grade. This method will have the same name and the same parameter profile as the parent class method. This new method will call the parent class method (of the same name) to compute the student letter grade. After return from the parent class method, in the case of grade type Credit, it will change the letter grade returned by the parent class method to either CR or NCR.

TestStudentExt class

Write a class TestStudentExt containing the main method. The method main will do the following:

Prompt the user to enter the total number of students (say n).

Create an array of n references (for holding n StudentExt object references). (The StudentExt objects will be created in the next step).

Create n StudentExt objects. Do this by setting up an n count loop. In each pass through the loop, do the following:

a. Ask the user to enter data for one student.

b. Create a StudentExt object and initialize it with data provided by the user. Store the object reference in the array of StudentExt references created above.

Display the student results by grade type. First display students receiving grade A, followed by those receiving B, followed by those receiving C, followed by those receiving D, followed by those receiving F, followed by those receiving Cr, followed by those receiving NCR.

You may do this in a number of ways including the following:

Method:

Create a String array out of 7 Strings. Use out [0] for accumulating output relating to A students, out[1] for B students etc. Write a static method displayRestult to display output. Call the static method displayResult and pass it the array out.

displayResult

For the method above, write a static method displayResult. This method will receive a String array and display the contents of all elements of the String array one by one. Here is a proposed header for the method:

public static void displayResult (String [ ] s)

{

}

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

(1c)

DESCRIPTION

This assignment is a modification of the last assignment. In this assignment, you will input from a file called in.txt and output to a file called out.txt. Otherwise, the assignment will behave the same way as the last assignment.

In this assignment, each input and output statement will be changed. Otherwise, the code will mostly remain unchanged.

DISCUSSION

Creating File IO Objects

For doing this assignment, you will create a BufferedReader object to input data from the text file line at a time. Also, you will create a PrintWriter object to write data to the file a String at a time.

Getting Student Count

It is suggested that you put student count as the first line of data in the input file. Different methods of determining the total number of students are described below.

Prompt the User for the Count

Prompt the user for entering the total number of students in the file using JOptionPane.showInputDialog.

Put the Count in the File

Put the total number of students as the first line of data in the input file. Input this value from the file and create a StudentExtarray of that size. Then input and process student data from the file.

Read File Twice

Create a file io object encapsulating the input file. Input data from the file line by line using the file io object. Keep a count of the number of lines read. Issue a close on the file io object. Create an array of StudentExt references of size above. Create a file io object encapsulating the input file a second time. Input data from the file line at a time. Each line will contain one student data. For each line read, create a StudentExt object and save its reference in the array created above. After all data is read and StudentExt objects are created, issue a close on the file io object. This will result in closing the file.

Here are the steps in detail.

Create the BufferedReader object (encapsulating the input file).

Input the file line by line using the BufferReader object. Keep a count of the number of lines read.

Close the BufferReader object.

Create an array of StudentExt references of size equal to count determined above.

Create the BufferedReader object (encapsulating the input file) a second time. (This will put the read pointer at the start of the file).

Read the file one line at a time. Each line contains one student data.

Create a StudentExt object according to student data read.

Save its reference in the array above.

When all student data is read, close the BufferedReader object.

Creating Text IO Files

It is suggested that you use JBuilder for creating the in.txt file.

Thanks a lot!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!