Question

this is a java course class.

Please, I need full an accurate answer. Labeled steps of the solution that comply in addition to the question's parts {A and B}, also comply with:

(Create another file to test the class and output to the screen, not an output file)

please, DO NOT COPY others' solutions. I need a real worked answer that works when I try it on my computer.

Thanks in advance.

Write the definition of the class Tests such that an object of this class 13. a. can store a students first name, last name,

0 0
Add a comment Improve this question Transcribed image text
Answer #1

For (a) refer Tests class.

For (b) refer Students class.

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.

import java.io.*;

class Tests
{
   String firstName;
   String lastName;
   double[] testScores;
   double avg;
   char grade;
  
   //Constructor for the class
   public Tests(String firstName,String lastName,double[] testScores)
   {
       this.firstName=firstName;
       this.lastName=lastName;
       this.testScores=testScores;      
   }
  
   //Calculate the average of the tests
   public double calculateAverage()
   {
       double sum=0;
       for(int i=0;i<5;i++)
           sum+=testScores[i];
       avg=sum/5;
       grade=calculateGrade();
       return avg;
   }
  
   //calculate the grade
   public char calculateGrade()
   {
       if(avg>=90) return 'A';
       if(avg>80) return 'B';
       if(avg>70) return 'C';
       if(avg>60) return 'D';
       return 'F';
   }
  
   //Overload the string
   public String toString()
   {
       return String.format("%1$-10s %2$-10s %3$5.2f %4$5.2f %5$5.2f %6$5.2f %7$5.2f %8$10.2f %9$5c",
       firstName,lastName,testScores[0],testScores[1],testScores[2],testScores[3],testScores[4],avg,grade);
   }
}

public class Students
{
   public static void main(String[] args)
   {
       int count=4,index=0;
       Tests[] t=new Tests[count];
       BufferedReader reader;
       try
       {
           //Read the File
           reader = new BufferedReader(new FileReader("data.txt"));
           String line = reader.readLine();
           while (line != null)
           {              
               //Process the line into separate strings
               String[] student=line.split(" ");
               String firstName=student[0];
               String lastName=student[1];
               double[] testScores=new double[5];
              
               //Store scores into the testScores
               for(int i=0;i<5;i++)
                   testScores[i]=Integer.parseInt(student[i+2]);
              
               t[index++]=new Tests(firstName,lastName,testScores);
                              
               //Read next line
               line = reader.readLine();
           }
           System.out.println(String.format("%1$-10s %2$-10s %3$5s %4$5s %5$5s %6$5s %7$5s %8$10s %9$7s",
           "First_Name","Last_Name","Test1","Test2","Test3","Test4","Test5","Average","Grade"));
           for(Tests test:t)
           {
               //Calculate the AVerage and Grade here
               test.calculateAverage();
               test.calculateGrade();
              
               //Print the object
               System.out.println(test);
           }

double cls_avg=0;
           for(Tests test:t)
           {
               cls_avg+=test.avg;
           }
           System.out.println("Class Average is: "+cls_avg/count);
           reader.close();
       }
       catch (IOException e)
       {
           e.printStackTrace();
       }
   }
}

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

SCREENSHOT FOR THE CODE:

import java.io.; 1 class Tests 3 4 String firstName; double[] testScores; double avg; char grade; 7 9 10 //Constructor for th39 //Overload the string public String toString() 4е 41 return String.format(%1$-10s %2$-10s %3$5 .2f %4$5.2f %5$5.2f %6$5.2System.out.println (String. format (%1$-10s %2$-10s %3$5s %4$5s %5$5s %6$5s %7$5s %8$10s %9$7s, First_Name, Last_Name,

OUTPUT:

GCAWindows System32 cmd.exe C:\Users\HP\Desktop>javac Students.java C: \Users\HP\Desktop>java Students First_Name Last_Name T

If there are any doubts, Happy Lear ning..!! We are right here to help you nment down here. com Please HIT a LIKE if youlike

Add a comment
Know the answer?
Add Answer to:
this is a java course class. Please, I need full an accurate answer. Labeled steps of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Could someone show how to do this in C#? I keep getting errors for mine and...

    Could someone show how to do this in C#? I keep getting errors for mine and the other answers on here that are similar doesn't work. And please make sure it accepts user input. Write the class "Tests". Ensure that it stores a student's first name, last name, all five test scores, the average of those 5 tests' scores and their final letter grade. (Use an array to store test scores.) Add constructors and methods to manipulate the data stored...

  • Write the definition of the class Tests such that an object of this class can store...

    Write the definition of the class Tests such that an object of this class can store a student's first name, last name, five test scores, average test score, and grade. (Use an array to store the test scores.) Add constructors and methods to manipulate data stored in an object. Among other things, your class must contain methods to calculate test averages, return test averages, calculate grades, return grades, and modify individual test scores. The method toString must return test data...

  • Student average array program

    Having a bit of trouble in my c++ class, was wondering if anyone can help.Write a program to calculate students' average test scores and their grades. You may assume the following input data:Johnson 85 83 77 91 76Aniston 80 90 95 93 48Cooper 78 81 11 90 73Gupta 92 83 30 68 87Blair 23 45 96 38 59Clark 60 85 45 39 67Kennedy 77 31 52 74 83Bronson 93 94 89 77 97Sunny 79 85 28 93 82Smith 85 72...

  • Write a program to calculate students’ average test scores and their grades. You may assume the...

    Write a program to calculate students’ average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three...

  • Write a program to calculate students’ average test scores and their grades. You may assume the...

    Write a program to calculate students’ average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three...

  • THIS IS FINAL COURSE ASSIGNMENT, PLEASE FOLLOW ALL REQUIREMENTS. Hello, please help write program in JAVA...

    THIS IS FINAL COURSE ASSIGNMENT, PLEASE FOLLOW ALL REQUIREMENTS. Hello, please help write program in JAVA that reads students’ names followed by their test scores from "data.txt" file. The program should output "out.txt" file where each student’s name is followed by the test scores and the relevant grade, also find and print the highest test score and the name of the students having the highest test score. Student data should be stored in an instance of class variable of type...

  • I want to change this code and need help. I want the code to not use...

    I want to change this code and need help. I want the code to not use parallel arrays, but instead use one array of struct containing the data elements, String for first name, String for last name,Array of integers for five (5) test scores, Character for grade. If you have any idea help would be great. #include #include #include #include using namespace std; const int NUMBER_OF_ROWS = 10; //number of students const int NUMBER_OF_COLUMNS = 5; //number of scores void...

  • use  JOptionPane to display output Can someone please help write a program in Java using loops, not...

    use  JOptionPane to display output Can someone please help write a program in Java using loops, not HashMap Test 1 Grades After the class complete the first exam, I saved all of the grades in a text file called test1.txt. Your job is to do some analysis on the grades for me. Input: There will not be any input for this program. This is called a batch program because there will be no user interaction other than to run the program....

  • Input hello, I need help completing my assignment for java,Use the following test data for input...

    Input hello, I need help completing my assignment for java,Use the following test data for input and fill in missing code, and please screenshot output. 1, John Adam, 3, 93, 91, 100, Letter 2, Raymond Woo, 3, 65, 68, 63, Letter 3, Rick Smith, 3, 50, 58, 53, Letter 4, Ray Bartlett, 3, 62, 64, 69, Letter 5, Mary Russell, 3, 93, 90, 98, Letter 6, Andy Wong, 3, 89,88,84, Letter 7, Jay Russell, 3, 71,73,78, Letter 8, Jimmie Wong,...

  • C++: Create a grade book program that includes a class of up to 20 students each...

    C++: Create a grade book program that includes a class of up to 20 students each with 5 test grades (4 tests plus a Final). The sample gradebook input file (CSCI1306.txt) is attached. The students’ grades should be kept in an array. Once all students and their test scores are read in, calculate each student’s average (4 tests plus Final counts double) and letter grade for the class. The output of this program is a tabular grade report that is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT