Results 1 to 8 of 8
- 02-21-2009, 09:14 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 19
- Rep Power
- 0
Really need help with an assignment... counter control loop...
I need help with an assignment...
I need to:
Write a stand-alone application that calculates the average of quiz scores. The number of quiz scores is specified by the user; thus, use a counter-controlled loop. Also, enter the student's name and calculate the student's grade based upon:
A: 90 to 100
B: 80 to 89
C: 70 to 79
D: 60 to 69
F: 0 to 59
Thus, the output should look like:
Student: Scott
# Quizzes: 4
Quiz 1: 82
Quiz 2: 94
Quiz 3: 90
Quiz 4: 94
Average: 90
Grade: A
-------------------------------------------------
Here is what I have:
-------
import java.io.*;
import java.util.*;
public class exampleStudentGrade
{
public static void main(String[] args) throws IOException,
FileNotFoundException
{
//declare and initialize the variables //Step 1
double test1, test2, test3, test4, test5;
double average;
String firstName;
String lastName;
Scanner inFile =
new Scanner (System.in); //Step 2
PrintWriter outFile = new
PrintWriter("testavg.out"); //Step 3
firstName = inFile.next(); //Step 4
lastName = inFile.next(); //Step 4
outFile.println("Student Name: "
+ firstName + " " + lastName); //Step 5
//Step 6 - retrieve the five test scores
test1 = inFile.nextDouble();
test2 = inFile.nextDouble();
test3 = inFile.nextDouble();
test4 = inFile.nextDouble();
test5 = inFile.nextDouble();
outFile.printf("Test scores: %5.2f %5.2f %5.2f "
+ "%5.2f %5.2f %n", test1, test2,
test3, test4, test5); //Step 7
average = (test1 + test2 + test3 + test4
+ test5) / 5.0; //Step 8
outFile.printf("Average test score: %5.2f %n",
average); //Step 9
if (average>=90)System.out.println("A");
else if (average>=80)System.out.print("B");
else if (average>=70)System.out.print("C");
else if (average>=60)System.out.print("D");
else if (average<=50)System.out.print("F");
inFile.close(); //Step 10
outFile.close(); //Step 10
}
}
--------------
- 02-21-2009, 09:32 PM #2
Put your code in CODE tags, and tell me specifically what isn't working or what part you are stuck on, and I'll be glad to help as well as many others.
-MK12Tell me if you want a cool Java logo avatar like mine and I'll make you one.
-
It's good that you made an effort to solve it first before posting here. Thanks. Now, please clarify exactly what problems you are having. Is your code not compiling? If so, please post the error messages. Is it compiling but throwing an exception? Again, post the exception message, and indicate somehow for both the above which lines are causing the problem.
Is it that your current code does not fulfill your requirements and if so how, and why do you think it's not working, etc,...
The more qualit info you give us the greater our ability to help you.
Good luck.
- 02-21-2009, 09:41 PM #4
Member
- Join Date
- Feb 2009
- Posts
- 19
- Rep Power
- 0
right now it runs but it is not exactly what i want - - - - - - I do not know how to: tell the computer (when i am prompted) The number of quiz scores i want to enter - specified by the user; thus, use a counter-controlled loop - and get the read out to read the average ie. the letter grade... it reads out the percentage point but not the letter grde.
-
You'll use your Scanner object, inFile to get this input. Scanner has a method for getting integer input that's similar to what you're using to get double input. I'd use that to get from the user the test-count, place that into a testCount or similar int variable, and then have a for loop use that variable as part of its ending condition. Good luck.
- 02-21-2009, 10:19 PM #6
Member
- Join Date
- Feb 2009
- Posts
- 19
- Rep Power
- 0
ya i dont know a thing u just said... i am not trying to be an ass or anything i just dont understand anything like that... i need major help
- 02-21-2009, 10:36 PM #7
If you don't understand this, you should do things you can understand to work up to being able to code this. Try googling sun java tutorial. That will get you started.
-MK12Tell me if you want a cool Java logo avatar like mine and I'll make you one.
-
Similar Threads
-
Counter
By ks1615 in forum New To JavaReplies: 6Last Post: 02-20-2009, 03:02 AM -
control app width based on certain control
By thebillybobjr in forum SWT / JFaceReplies: 0Last Post: 05-15-2008, 04:52 PM -
Frequency Counter
By justlearning in forum New To JavaReplies: 0Last Post: 05-07-2008, 10:50 PM -
[SOLVED] BST Frequency Counter
By theonly in forum Advanced JavaReplies: 7Last Post: 04-29-2008, 11:33 PM -
Help with static variable counter
By silvia in forum New To JavaReplies: 1Last Post: 07-19-2007, 07:53 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks