Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Helidon Revealed: A Practical Guide to Oracle’s Microservices Framework
this week in the
Java in General
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Liutauras Vilda
Ron McLeod
Sheriffs:
Jeanne Boyarsky
Devaka Cooray
Paul Clapham
Saloon Keepers:
Scott Selikoff
Tim Holloway
Piet Souris
Mikalai Zaikin
Frits Walraven
Bartenders:
Stephan van Hulst
Carey Brown
Forum:
Java in General
Help setting up an array and other issues
mike statham
Greenhorn
Posts: 23
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
What I need is read from a file which it does but I need it to be a file of any size, not just set as I've got set at 15.
Then I need to print out A=2 B=2 C=2 D=2 F=2 just a sample showing how many each student earn what grade.
I know that im probally making things worse than they should, but when you self teaching your self........
Any help is appreciated!
package average; import java.io.FileReader; import java.util.Scanner; /** * * @author Big daddy */ class Grades { static public void main(String[] args) throws Exception { //create scanner for the file Scanner input = new Scanner(new FileReader("grades.txt")); int []numGrade = new int[15]; String[] name = new String[15]; // stores name of each student int[] avgMarks = new int[15]; // stores avg marks of each student String[] letterGrade = new String[15]; // stores grade of each student int totalMarks = 0; // stores total marks int avg =0; for (int i = 0; i < 15; i++) { name[i] = input.next(); avg = 0; for (int j = 0; j<3; j++) { numGrade[j] = input.nextInt(); avg += numGrade[j]; if (j == 2) { avgMarks[i] = avg/3; totalMarks += avgMarks[i]; } } } // get the grade for (int i=0; i<15; i++) { if (avgMarks[i] < 60) { letterGrade[i] = "F"; } else if (avgMarks[i] < 70) { letterGrade[i] = "D"; } else if (avgMarks[i] < 80) { letterGrade[i] = "C"; } else if (avgMarks[i] < 90){ letterGrade[i] = "B"; } else { letterGrade[i] = "A"; // initializing int int inputsProcessed = 0; int A = 0; int B = 0; int C = 0; int D = 0; int F = 0; //process A's if (avgMarks >= 90){ //add each occurence ++A; } //process B's else if (avgMarks >= 80){ //add each occurence ++B; } //process C's else if (avgMarks >= 70){ //add each occurence ++C; } //process D's else if (avgMarks >= 60){ //add each occurence ++D; } //process F's else if (avgMarks >= 0){ //add each occurence ++F; } //else { //System.out.println("Proper input was not input"); System.out.println("Total number of grades:" + inputsProcessed); System.out.println("Number of A's = " + A ); System.out.println("Number of B's = " + B ); System.out.println("Number of C's = " + C ); System.out.println("Number of D's = " + D ); System.out.println("Number of F's = " + F ); } } } for (int i = 0; i<15; i++) { System.out.printf("%s\t has an average grade of %d%%. You will receive a %s in this class. \n", name[i], avgMarks[i], letterGrade[i]); System.out.printf("\nOverall Class Average is %d%%.\n",totalMarks/15); } //generates three random numbers between 0 and 50, calculates the average. int one,two,three; one=(int)(Math.random()*(51)); two=(int)(Math.random()*(51)); three=(int)(Math.random()*(51)); int average=(one+two+three)/3; System.out.println("\n\nThe following program generates 3 random numbers, then averages them."); System.out.println("\nThe average of\t"+one+" "+two+" "+three+" is "+average); } }
Zeeshan Sheikh
Ranch Hand
Posts: 144
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Try ArrayList as it grows dynamically.
MySQL Blog
http://mysqlearner.blogspot.com/
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Changing array I think and the print statement
help in fixing the error
Mistake in Calculation of Percentage
Not passing the value
Actually I'm lost
More...