Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help me write this code in java please!!! Topics: for loops nested for loops computing min, max, and average using a loop formatting string writing

Help me write this code in java please!!!

Topics:

for loops

nested for loops

computing min, max, and average using a loop

formatting string

writing to a text file

Write a program that given student names and their scores, compute their grades and write the result to a file named grades.txt.

The program will prompt for the number of students and the number of scores and then proceed to read the name of each student, and his or her scores. It does this for all the students. Once all students and their scores have been read, the program writes to a file, a table containing the student names, their scores, and their computed grade. In addition, it also writes the class statistics such as the class min, the class max, and the class average.

Formatting table

In this example, there are three students and four scores. The lowest grade is 69.00, the highest grade is 91.00 and the average of all grades is 79.25.

Name Score1 Score2 Score3 Score4 Grade

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

Frank Lopez 99 88 77 100 91.00

Ryan Reynolds 77 79 75 80 77.75

George Smith 55 67 71 83 69.00

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

Class Min = 69.00

Class Max = 91.00

Class Avg = 79.25

I use the following column with for my table.

Name column is 10 characters wide

Each score column is 6 characters wide

Grade column is 8 character wide, 2 decimal places

The horizontal lines are optional. The horizontal lines enclosing student data is computed based on the length of each column. You can use String.format()to create a specific number of blanks and then replace the result with a dash (-). For example, to create a line of ten dashes, I would do the following:

String line = String.format("%10s", " ").replace(" ", "-");

Compute dash lines for each column and concatenate them into a line that is the length of the table. The table contains the name column, the column for each score, and the grade column. Once, the line is constructed, simply output it to the file.

Your program should not make use array or arraylist

Sample run 1.

Enter number of students: 2

Enter number of scores : 2

Enter name of student 1: Frank Lopez

Enter score1 for Frank Lopez: 99

Enter score2 for Frank Lopez: 87

Enter name of student 2: Ryan Reynolds

Enter score1 for Ryan Reynolds: 79

Enter score2 for Ryan Reynolds: 81

See grades.txt for output.

Content of grades.txt

Name Score1 Score2 Grade

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

Frank Lopez 99 87 93.00

Ryan Reynolds 79 81 80.00

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

Class Min = 80.00

Class Max = 93.00

Class Avg = 86.50

Sample run 2.

Enter number of students: 3

Enter number of scores : 4

Enter name of student 1: Frank Lopez

Enter score1 for Frank Lopez: 99

Enter score2 for Frank Lopez: 88

Enter score3 for Frank Lopez: 77

Enter score4 for Frank Lopez: 100

Enter name of student 2: Ryan Reynolds

Enter score1 for Ryan Reynolds: 77

Enter score2 for Ryan Reynolds: 79

Enter score3 for Ryan Reynolds: 75

Enter score4 for Ryan Reynolds: 80

Enter name of student 3: George Smith

Enter score1 for George Smith: 55

Enter score2 for George Smith: 67

Enter score3 for George Smith: 71

Enter score4 for George Smith: 83

See grades.txt for output.

Content of grades.txt

Name Score1 Score2 Score3 Score4 Grade

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

Frank Lopez 99 88 77 100 91.00

Ryan Reynolds 77 79 75 80 77.75

George Smith 55 67 71 83 69.00

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

Class Min = 69.00

Class Max = 91.00

Class Avg = 79.25

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

Recommended Textbook for

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions