java Help! i keep getting this error. ----jGRASP exec: javac -g Lab6.java ϼ§ÏLa
ID: 3835621 • Letter: J
Question
java
Help! i keep getting this error.
----jGRASP exec: javac -g Lab6.java
ϼ§ÏLab6.java:52: error: cannot find symbol
ÏÏ§Ï StudentGrades students = new StudentGrades(id,scores);
ÏÏ§Ï ^
ÏÏ§Ï symbol: class StudentGrades
ÏÏ§Ï location: class Lab6
ϼ§ÏLab6.java:52: error: cannot find symbol
ÏÏ§Ï StudentGrades students = new StudentGrades(id,scores);
ÏÏ§Ï ^
ÏÏ§Ï symbol: class StudentGrades
ÏÏ§Ï location: class Lab6
ÏϧÏ2 errors
ÏϧÏ
ÏÏ§Ï ----jGRASP wedge: exit code for process is 1.
ÏÏ©Ï ----jGRASP: operation complete.
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.Scanner;
public class Lab6 {
public static void main(String[]args) throws FileNotFoundException{
int[] scores = new int[10];
int id;
int studentCount = 0;
int ID;
String studentName;
//StudentGrades [] arrayStudent = new StudentGrades[16];
Scanner fileArrayIn = new Scanner(new FileReader("Lab06Names.txt"));
Scanner fileIn = new Scanner(new FileReader("Lab06StudentFile.txt"));
PrintWriter reportFile = new PrintWriter("Lab06Report.txt");
int totalRecords = 20;
int p = 0;
int[] idA = new int[totalRecords];
String[] nameA = new String[totalRecords];
while (fileArrayIn.hasNext()) {
ID = fileArrayIn.nextInt();
studentName = fileArrayIn.nextLine().trim();
idA[p] = ID;
nameA[p] = studentName;
p++;
}
reportFile.printf("%s", "Student Grade Report"+" "+" ");
reportFile.printf("%-7s","ID#");
reportFile.printf("%-20s","Name");
String s ="/-----------------TEST Scores-----------------/ ";
reportFile.printf("%50s%7s%7s%7s",s,"Total","Adj Total", "Avg"+" "+" ");
while(fileIn.hasNextLine()){
id= fileIn.nextInt();
for(int i=0; i< 10;i++)
{ scores[i]= fileIn.nextInt();
}
int StudentGrades;
StudentGrades students = new StudentGrades(id,scores);
studentName =seqSearch(students.getStudentID(),nameA,idA);
studentCount ++;
reportFile.printf("%-7d",id);
reportFile.printf("%-20s",studentName);
for(int i=0; i< 10; i++){
reportFile.printf("%5d", scores[i]);
}
reportFile.printf("%7d%7d%7d", students.getTotalGrade(),students.getAdjTotal(),students.getAverage());
reportFile.println("");
}
reportFile.println("");
reportFile.printf("%s%d","Total Students =",studentCount);
reportFile.println("");
reportFile.printf("%s", "Report by ");
fileIn.close();
reportFile.close();
}
public static String seqSearch(int t, String[] nameA, int[] idA) {
String studentName = "Invalid Name";
for (int i = 0; i < nameA.length; i++) {
if (t == idA[i])
studentName = nameA[i];
}
return studentName;
}
}
Explanation / Answer
You do not have a StduentGrades file
I created one
StudentGrades.java
public class StudentGrades {
public StudentGrades(int studentid, int[] grades) {
setStudentid(studentid);
setGrades(grades);
}
public StudentGrades() {
setStudentid(0);
setGrades(null);
}
public int getStudentID()
{
return studentid;
}
private int studentid;
private int[] grades = new int[10];
public int getStudentid() {
return studentid;
}
public void setStudentid(int studentid) {
this.studentid = studentid;
}
public int[] getGrades() {
return grades;
}
public void setGrades(int[] grades) {
this.grades = grades;
}
public int getTotalGrade()
{
int total = 0;
for(int i = 0; i < grades.length; i++)
{
total += grades[i];
}
return total;
}
public int getAdjTotal()
{
int min = grades[0];
int max = grades[0];
for(int i = 1; i < grades.length; i++)
{
if (min > grades[i])
{
min = grades[i];
}
if (max < grades[i])
{
max = grades[i];
}
}
int total = getTotalGrade() - min + max;
return total;
}
public int getAverage()
{
int total = getAdjTotal();
double avg = total/grades.length;
return (int)Math.rint(avg);
}
}
Lab6.java
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.Scanner;
public class Lab6 {
public static void main(String[]args) throws FileNotFoundException{
int[] scores = new int[10];
int id;
int studentCount = 0;
int ID;
String studentName;
//StudentGrades [] arrayStudent = new StudentGrades[16];
Scanner fileArrayIn = new Scanner(new FileReader("Lab06Names.txt"));
Scanner fileIn = new Scanner(new FileReader("Lab06StudentFile.txt"));
PrintWriter reportFile = new PrintWriter("Lab06Report.txt");
int totalRecords = 20;
int p = 0;
int[] idA = new int[totalRecords];
String[] nameA = new String[totalRecords];
while (fileArrayIn.hasNext()) {
ID = fileArrayIn.nextInt();
studentName = fileArrayIn.nextLine().trim();
idA[p] = ID;
nameA[p] = studentName;
p++;
}
reportFile.printf("%s", "Student Grade Report"+" "+" ");
reportFile.printf("%-7s","ID#");
reportFile.printf("%-20s","Name");
String s ="/-----------------TEST Scores-----------------/ ";
reportFile.printf("%50s%7s%7s%7s",s,"Total","Adj Total", "Avg"+" "+" ");
while(fileIn.hasNextLine()){
id= fileIn.nextInt();
for(int i=0; i< 10;i++)
{ scores[i]= fileIn.nextInt();
}
int StudentGrades;
StudentGrades students = new StudentGrades(id,scores);
studentName =seqSearch(students.getStudentID(),nameA,idA);
studentCount ++;
reportFile.printf("%-7d",id);
reportFile.printf("%-20s",studentName);
for(int i=0; i< 10; i++){
reportFile.printf("%5d", scores[i]);
}
reportFile.printf("%7d%7d%7d", students.getTotalGrade(),students.getAdjTotal(),students.getAverage());
reportFile.println("");
}
reportFile.println("");
reportFile.printf("%s%d","Total Students =",studentCount);
reportFile.println("");
reportFile.printf("%s", "Report by ");
fileIn.close();
reportFile.close();
}
public static String seqSearch(int t, String[] nameA, int[] idA) {
String studentName = "Invalid Name";
for (int i = 0; i < nameA.length; i++) {
if (t == idA[i])
studentName = nameA[i];
}
return studentName;
}
}
Try with these in same src folder
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.