473,394 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Java Program calculating student average, class average, and letter grade using array

im struggling with the man/driver class

heres what i have for code

package GradebookProg3;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

public class mainGradeBook {

public static void main(String[] args) throws FileNotFoundException
{
GradeBook [] gradeBook = new GradeBook [10];

String fName, lName;
double[] testScores = new double[5];

double classAverage = 0.0;

Scanner inFile = new Scanner(new FileReader("testScores.txt"));


//STRUGGLING HERE..HOW SHOULD I WRITE THIS?

for (int i = 0; i < 10; i++)
fName = inFile.next();
lName = inFile.next();


gradeBook [a,b,c ] = new GradeBook();



System.out.println("First_Name Last_Name Test1 Test2 "
+ "Test3 Test4 Test5 Average Grade");

for (int i = 0; i < 10; i++)
{
System.out.println(gradeBook[i]);

classAverage = classAverage + gradeBook[i].getAverage();
}

classAverage = classAverage / 10;

System.out.println();

System.out.printf("Class average = %.2f%n", classAverage);
}//end main



}
Apr 10 '17 #1
1 2211
chaarmann
785 Expert 512MB
First: don't use arrays, use ArrayList instead. They are more flexible and you don't need to resize or handle error conditions like ArrayIndexOutOfBounds etc.

Using a for-loop for the data entry is bad.
Maybe the user wants to enter only 3 records instead 10.
You have to give the user the possibility to quit after every record entered.

So use while-loop:
Expand|Select|Wrap|Line Numbers
  1. while(true)
  2. {
  3.   enterRecord(inFile); // you have to write that
  4.   System.out.println("Do you want to enter more records (Y) or quit (N)?");
  5.   String answer = inFile.next();
  6.   if (answer.toUpperCase.equals("N")) break; 
  7. }
Apr 10 '17 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Begreen | last post by:
Hi All, I wrote a java program which outputs a xml file! But I would prefer this program to insert the DTD code on the fly, in the xml file when created! I want the xml file to look like...
2
by: him1979 | last post by:
If i have a class desribing dates from the calendar and second class Student with members: name, date of birth(using the first class) how could i write a method for the second class with...
3
by: blewie07 | last post by:
Create a class named Student. A student has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.