1. Calculate the test averages 2. Return test averages 3. Calculate grades, 4. return grades. 5. And modify individual test scores .  6.The method toString must return test data (including student,s name, five test scores, average test score, and grade) as a string. Note: I also don't know or understand the concept of creating an array to store the test scores--is this asking you to create the array to store the test scores in Class Tests or is this questions asking me to create an array to store the test scores in the Main Program/Driver program. Well here is my messed up code; I am confused, I had Java in 2012 and 2013, and still we really didn't go over user-defined calsses with creating arrays. Please help me.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 7PE
icon
Related questions
Question
100%

In Java Only, write the definition if the class Tests such that an object of this class can store a student's first name, last name, 5 test scores, average tests 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

1. Calculate the test averages 2. Return test averages 3. Calculate grades, 4. return grades. 5. And modify individual test scores .  6.The method toString must return test data (including student,s name, five test scores, average test score, and grade) as a string. Note: I also don't know or understand the concept of creating an array to store the test scores--is this asking you to create the array to store the test scores in Class Tests or is this questions asking me to create an array to store the test scores in the Main Program/Driver program. Well here is my messed up code; I am confused, I had Java in 2012 and 2013, and still we really didn't go over user-defined calsses with creating arrays. Please help me.

 

* Chapter 9 Arrays. Programming problem #13 Part A, page
* Create a Tests Class
*/
public class Tests {
private String firstName;
private String lastName;
private double[] testScores;
private double averageScores;
private double classAverage;
private char grade;
//private int numberOfScores;

private double numbers;
private int size;
//Default Constructor
public Tests(){
firstName = " No Name";
lastName = "duffy ";
size = 0;
// numbers = 0;
testScores = new double[5];
}
//Constructor with parameters

public Tests(String firstname, String lastname, int numOfScores)//, int[] tscores)
{
firstName = firstname;
lastName = lastname;
size = numOfScores;
// testScores;
//numbers = scores;
}

public void setFirstName(String firstname){
firstName = firstname;

}

public void setLastName(String lastname){
lastName = lastname;

}
public void setScores(double scores){
numbers = scores;

}

public void setTestScores(double[] tscores){


testScores[5] = tscores[5];
}


public String getFirstName(){
return firstName;
}
public String getLastName(){
return lastName;
}

public double getScores(double scores){
return numbers;

}

public double[] getTestScores() {
return testScores;
}


public double getAverage(){
double sum = 0;
double saverage = 0.0;
for( int i = 0; i < 5; i++)
{ sum = sum + testScores.length;
saverage = sum / 5;

} saverage = sum / testScores.length;
return saverage;
}
public double getClassAverage(){
double sum = 0;
double caverage = 0;
for( int i = 0; i < 10; i++)
{ sum = sum + 10;
caverage = sum / 10;

} //average = sum / testScore.length;
return caverage;
}
// public char getGrade(){
// double saverage = getAverage();
// if(saverage >= 90) {
// grade = 'A' ;
// }

//else if(saverage >= 80) {
// grade = 'B';
//}

//else if(saverage >= 70) {

//grade = 'C';
// }

// else if(saverage >= 60) {
// grade = 'D';
//}

// else {
// grade = 'F';
// }


//return grade;
//}

@Override
public String toString()
{
String str = String.format("%-10s %-5s", firstName, lastName);

for(int i = 0; i < testScores.length; i++) {
str = String.format("%2f", testScores);

// str = str + String.format("%2.2f", averageScores);
// str = str + " " + grade;
// str = str + String.format("%2.2f", classAverage);
}

return str;
}

}

//Driver /Main Class

public class TestStudentData {
static Scanner console = new Scanner(System.in);
/**
* @param args the command line arguments
*/
public static void main(String[] args)throws FileNotFoundException, IOException{

String firstname;
String lastname;
int numOfStudents = 10;
int numberOfScores = 5;
int i, j;
double [] scores = new double[numberOfScores];

Scanner inFile = new Scanner(new FileReader("e:\\studentData.txt"));

PrintWriter outFile = new PrintWriter("studentoutput.dat");

//declare & create the Object of Arrays to hold 10 different student objects in each slot
Tests[] student = new Tests[numOfStudents];
// String[] score = new String[numOfStudents];

//You need instantiate Tests objects for each array elment

// for(i = 0; i < student.length; i++)
// student[i] = new Tests();

int tempScores;
for( i = 0; i < student.length; i++)//student is the object of arrays
{
firstname = inFile.next();

lastname = inFile.next();
System.out.println(firstname + " " + lastname);

for(i = 0; i < scores.length; i++){
// while(inFile.hasNextInt()){
tempScores = inFile.nextInt();
// scores[i] = inFile.nextDouble();
System.out.println(tempScores);
// System.out.println(scores[i] );
}
}
//student[i] = new Tests(firstname, lastname, tempScores);
//student[i].setFirstName(firstname);
//student[i].setLastName(lastname);
//student[i].setTestScores(scores);

//}

// for(i = 0; i < student.length; i++)
//{
// System.out.println(student[i].getFirstName() + student[i].getLastName() + student[i].getTestScores().toString());
// System.out.println(student[i]);
//}

inFile.close();
outFile.close();

//System.out.println("First_Name\tLast_Name\tTest1\tTest2\tTest3\tTest4\tTest5\t"
// + "Average\tGrade");

}//end of Main

}//end of the testStudentData Class

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
void method
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,