Question

In: Computer Science

This project will be an exercise in using all that we have covered in these past...

This project will be an exercise in using all that we have covered in these past two weeks: Arrays (one and multidimensional arrays), branching, and input and output files.

Components:

A class called YourLastNameGradebook (Yes, YourLastName IS  your last name!!!)

And an external class called SomeNeatExternalSoundingName. This external class will have at least 2 methods: readData and writeData

This project will include

The class with the main method and the other useful methods that will 1) display the arrays, 2) find the averages and store them, 3) find the grades and store them, 4) and display a chart of the final array results to the terminal window.

The external class will 1) read from the input file and 2) write to an output file.

YourLastNameGradebook class's main method will be made up of declarations and method calls. There should be no other code in the main method. (Except for one single print statement stating that the program is finished!)

Declarations:

  • Declare a one-dimensional array that contains the names of 5 students (the names will be read in as first and last and be concatenated into a one-dimensional names array in the order of last, first with a comma between the names)
  • Create a multidimensional array that contains 3 test scores PLUS one more element (this extra element will be used later to store the computed average of these 3 test scores) for each of the 5 students.
  • Declare a one-dimensional array that will contain the letter grades for each of the 5 students.

Actions needed: Note - Do use the size of the array for your for loops, notthe value 5.

1) Read in (Invoke the readData method in the external class ):

The input file looks like this:   project2IN.txt

Leia Organa 98.0 95.5 100.0
Fred Flintstone 65.0 74.5 76.25
Sheldon Cooper 100.0 100.0 99.0
Stan Marsh 89.0 84.0 80.5
Lisa Simpson 93.0 94.5 92.0

When you open the input file, echo this to the terminal window.

The array of names will be read in from the input file. (The names will be read in as first last but need to be rearranged to last, first when being read in)
This array of scores will be read in from the input file.

The last element in the scores array will have a zero in it. This will be reserved for the averages (later).

When you close the input file, echo this to the terminal window.

After reading in the data: Row zero from the names array corresponds to row zero from the scores array:

names array contains 5 names:

element: Contents:

0

Organa, Leia

1

Flintstone, Fred

2

Cooper, Sheldon

3

Marsh, Stan

4

Simpson, Lisa

Scores array contains 5 rows of 4 elements each

row

column 0

column 1

column 2

column 3

0

98.0

95.5

100.0

1

65.0

74.5

76.25

2

100.0

100.0

99.0

3

89.0

84.0

80.5

4

93.0

94.5

92.0

2) In YourLastNameGradebook class, invoke the method to display the data using a displayData method:

Display the data (using a displayData method) in the terminal window as it is stored in both of the arrays.

Data read in:

last, first: score1, score2, score3

last, first: score1, score2, score3

last, first: score1, score2, score3

last, first: score1, score2, score3

last, first: score1, score2, score3

(Formatting at this point is not important. Include at least one space! This is just echoing what was entered!)

3) Invoke a method that will compute the average in the scores array

  • Store the computed averages into the last column element of each row of the scores array.

4) Invoke a method that will compute the grade for each student

For each student, determine the average score from the three grades and the grade of A, B, C, D, or F   

  • Store the letter grade into a one-dimensional array called letterGrade that corresponds to that student. (I used: to get an A, they need 89.5 and so on – use the full letter grade percentages from the class syllabus)

5) Invoke another displayData method that will print out the names, scores, and grades for each student in the terminal window.

6) Invoke the method in the External class that will write the clean chart to the output file project2OUT.txt

  • When you open the output file, echo this to the terminal window.
  • Write a neat chart of the names, the scores, and the grades received.
  • When you close the output file, echo this to the terminal window.

7) When done, the last statement of the main is to be an output statement telling the user that the program is finished.


Output is to be neat and clean. Use blank spaces for readability in both the output file and in the terminal window.

Upload (to one of your pairs’ Canvas account) ALL the files that are needed for grading including BOTH .java files and both .txt files:

  • include the input file: project2IN.txt
  • and the output file: project2OUT.txt
  • also the .java file that contains your main method as well as the .java file that contains the external method.

Extra Credit:
1) Use printf to create a neat chart with a chart title (centered above the output) and headers for the data similar to the following.  (2 points)

==========================================================================
                        Student Grades

Name                        Score1     Score2       Score3       Average    Grade
==========================================================================
Organa, Leia             98.00         95.50 100.00     .00              x
Flintstone, Fred        65.00         74.50   76.25     .00               x

and so on...

2) Insert a first new line into your input file. Alter this first line to include an integer value to represent the number of rows to be read in as a reference that will declare the sizes of the arrays to be of that size.

(2 points)

Be SURE that both names appear in the beginning comments!  Otherwise only one of you will get credit.
This is what will be displayed to the terminal window:  This could be cleaned up to be more readable.

Reading from input file: project2IN.txt

Closing input file: project2IN.txt

Displaying data as stored:

Organa, Leia 98.0 95.5 100.0 0.0

Flintstone, Fred 65.0 74.5 76.25 0.0

Cooper, Sheldon 100.0 100.0 99.0 0.0

Marsh, Stan 89.0 84.0 80.5 0.0

Simpson, Lisa 93.0 94.5 92.0 0.0

Computing Averages...

Average for Organa, Leia is 97.83333333333333

Average for Flintstone, Fred is 71.91666666666667

Average for Cooper, Sheldon is 99.66666666666667

Average for Marsh, Stan is 84.5

Average for Simpson, Lisa is 93.16666666666667

=================================================================

            Name        Score1 Score2  Score3  Average Grade

=================================================================

          Organa, Leia   98.00  95.50  100.00   97.83    A

      Flintstone, Fred   65.00  74.50   76.25   71.92    C

       Cooper, Sheldon  100.00 100.00   99.00   99.67    A

           Marsh, Stan   89.00  84.00   80.50   84.50    B

         Simpson, Lisa   93.00  94.50   92.00   93.17    A

Opening the output file: project2OUT.txt

Writing data to the output file.

Closing the output file project2OUT.txt

This program is now terminating. Have a nice day.

Output file: project2OUT.txt

=================================================================

            Name        Score1 Score2  Score3  Average Grade

=================================================================

          Organa, Leia   98.00  95.50  100.00   97.83    A

      Flintstone, Fred   65.00  74.50   76.25   71.92    C

       Cooper, Sheldon  100.00 100.00   99.00   99.67    A

           Marsh, Stan   89.00  84.00   80.50   84.50    B

         Simpson, Lisa   93.00  94.50   92.00   93.17    A

Solutions

Expert Solution

Program Code :

-----------

//import io package

import java.io.*;

//main class

class YourLastNameGradeBook

{

//main method

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

{

//create an object to GetStuff

GetStuff ob = new GetStuff();

//invoke cal() method

ob.cal();

//invoke displayData() to print the data

ob.displayData();

}

}

public class GetStuff

{

//local declarations

private String st[] = new String [5];

private String Lnames[] = new String[5];

private String Fnames[] = new String[5];

private double marks[][] = new double [5][4];

private int j = 0;

private int row = 0, col = 0;

private double avg = 0;

private int i;

char [] grade = new char[5];

//cal method

public void cal()

{

try {

// Open the file that is the first

// command line parameter

FileInputStream fstream = new FileInputStream("input.txt");

// Get the object of DataInputStream

DataInputStream in = new DataInputStream(fstream);

BufferedReader br = new BufferedReader(new InputStreamReader(in));

String strLine;

// Read File Line By Line

while ((strLine = br.readLine()) != null)

{

// Print the content on the console

//split the line basing on space delimiter

st= strLine.split("\\s+");

//read the First name

Fnames[j] = st[0];

//read the First name

Lnames[j] = st[1];

//intialize sum to 0

double sum =0;

//loop runs for 3 times for each subject

for( i=0;i<3;i++)

{

//convert the marks(in String format) to double

marks[row][i] = Double.parseDouble(st[i+2]);

//add the marks to total

sum += marks[row][i];

}

//calculate the average

avg = (double)sum / (i);

//assign the avg to last column of the array

marks[row][i]= avg;

//increment the row

//if avg>90 then grade is A

if(avg > 90)

grade[j]='A';

//if avg>80 then grade is B

else if(avg>80)

grade[j]='B';

//if avg>70 then grade is C

else if(avg>70)

grade[j]='C';

//if avg>60 then grade is D

else if(avg>60)

grade[j]='D';

//if avg>50 then grade is E

else if(avg>50)

grade[j]='E';

//else grade is F

else

grade[j]='F';

//increment the row

row++;

//increment the j

j++;

}

// Close the input stream

in.close();

}

catch (Exception e)

{

// Catch exception if any

System.err.println("Error: " + e.getMessage());

}

}

public void displayData() throws IOException

{

//create an object to file writer

FileWriter fstream = new FileWriter("output.txt");

//create an object to BufferedWriter

BufferedWriter br = new BufferedWriter(fstream);

//print the headings

System.out.println("LastName FirstName\tMarks1 \tMarks2 \tMarks3\t Average\t Grade");

//write the names into file

br.write(Lnames[1]+""+Fnames[1]);

//for each student

for(row=0;row<5;row++)

{

//print a new line

System.out.println();

br.write("\n");

//write the names into output file

br.write(Lnames[row]+","+Fnames[row]);

//print the marks

System.out.print(""+Lnames[row]+","+Fnames[row]);

for(col=0;col<4;col++)

{

//print the marks

System.out.print("\t\t"+marks[row][col]);

//write the marks

br.write("\t\t"+marks[row][col]);

}

//print the grade

System.out.println("\t\t"+grade[row]+"\t\t");

//write the grade in to file

br.write(grade[row]);

}

}

}

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

input

output


Related Solutions

Using your knowledge from all the topics we have covered: a. Discuss the potential short-term and...
Using your knowledge from all the topics we have covered: a. Discuss the potential short-term and long-term economic implications of the COVID-19 pandemic in Australia. b. Outline the responses of monetary and fiscal policies to the pandemic, and express your views regarding their effects. If you were the policymaker, how would YOU design and implement these policies? (most importantly, would you have done anything differently?)
Consider all the things we have covered in the last and fast 8 weeks in Course...
Consider all the things we have covered in the last and fast 8 weeks in Course Code: BE-205 Course Title: Principles of Microeconomics. In a 500+ WORD post, List and explain three items/concepts/theories that you have picked up/developed in Microeconomics that you can now apply in the workplace or your personal life.
1. All of the economic thinkers that we have covered so far, including the mercantilists, the...
1. All of the economic thinkers that we have covered so far, including the mercantilists, the physiocrats, Adam Smith, Malthus, and Ricardo, have dealt with the topic of international trade as well as international trade policy. With the exception of Malthus, discuss the evolution of their ideas regarding those topics. You should mention their ideological leanings as well as the substance of their views. Do not forget to mention their policy recommendations.
We have a project related with Peltier. We are trying to heat water by using almost...
We have a project related with Peltier. We are trying to heat water by using almost 10 peltiers. However, we have problems about driving the Peltier. What should we do to drive the Peltier? What is needed?
We have all given some type of presentation in the past. What has gone well for...
We have all given some type of presentation in the past. What has gone well for you in a past presentation and what has not gone well? How can you improve? If you do not have experience giving a presentation, you have probably seen a presentation, what was good about it and could you utilize this technique in your presentation?
Summarize all the rules, including formulae (not PhStat), of the following topics that we covered (and...
Summarize all the rules, including formulae (not PhStat), of the following topics that we covered (and will still cover) in the course. a. Binomial distribution b. Poisson distribution c. Normal distribution d. Sampling Distribution e. Confidence Interval e (1). Estimation for the Mean, Sigma Known e (2). Estimation for the Mean, Sigma Unknown e (3). Estimation for the Proportion e (4). Required Sample Size PREFERRABLY TYPED PLEASE. EASIER TO UNDERSTAND.
please reflect upon all the medications we covered this week and how they relate to the...
please reflect upon all the medications we covered this week and how they relate to the urinary and reproductive systems. In your own words, please answer the following questions. What are some common medications to help with urinary tract infections? Are there also natural methods that are as effective? What about an expecting mother with high blood pressure? Why is this important to understand?
please reflect upon all the medications we covered this week and how they relate to the...
please reflect upon all the medications we covered this week and how they relate to the gastrointestinal and psychiatric systems. In your own words, please answer the following questions. What are some examples of medications that people with Alzheimer’s use to help their symptoms? What is the cause of Alzheimer’s? Why is it important to have a working understanding of these medications?
The assignment for this week builds on what we covered in Chapter 3 using functions, as...
The assignment for this week builds on what we covered in Chapter 3 using functions, as well as introduces Conditional Statements. I have created your HTML file for you, along with some starter JavaScript to get you started. The HTML contains 3 text boxes and a button, and you'll recognize it as a simple registration form. Typically when you complete a form online, the data is sent to a server to be processed. If we are must send data across...
We are working on a project. Two companies have bid on the project and we are...
We are working on a project. Two companies have bid on the project and we are choosing from two machines. This is a mutually exclusive project, we must pick one machine or the other but cannot pick both. Machine A has an initial cost of $19,500 and a salvage value of $7500 (today's value) at the end of its 12 year life. Machine B has an initial cost of $17,900 and a salvage value of $2300 (today's value) at the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT