This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
It will mean so much to me if any of you guys can help me. I'm so stupid at this.I learn real quick when I look at them. i don't want to waste any of you guys time by explaining it to me. The fact that anyone can do this is amazing. Here it is:
1.)Write a program that asks the user for 5 test scores in a loop and keeps track of their sum. You should NOT store all of the individual test scores. (do not make 5 variables)
Sample: Enter a test:99 Enter a test:100 Enter a test:101 Enter a test:50 Enter a test:55 The total is 405
2.) Modify the program so that it prints the average instead of the sum.
Sample: Enter a test:99 Enter a test:100 Enter a test:101 Enter a test:50 Enter a test:50 The Your average is 80.0
3.) Modify the program so that it asks for 10 test scores, then 15 test scores. Can you make this any number?
4.) Modify the program so that in the beginning of the program it asks the user "How many tests did you take" and then will ask the user for THAT many test scores.
Sample: Enter a test:99 Enter a test:98 Enter a test:98 Your test average is 98.3333333333333.
Sample: How many tests did you take? 6 Enter a test:80 Enter a test:80 Enter a test:80 Enter a test:80 Enter a test:81 Enter a test:81 Your test average is 80.5
Please Do Your Own Homework. We will guide you where needed but we will not give you full solutions.
I'll give you a few hints: - solution 2 is basically solution 1 with a divide operation added (average == sum / count). Take care though that integer division may not result in what you expect. You may need to cast some values to float or double.
- use a loop; for is probably the easiest
- if you are allowed to, check out java.util.Scanner for reading the values. Otherwise you will need to use System.in combined with Integer.parseInt. You can make life a bit easier by wrapping System.in in an InputStreamReader in a BufferedReader.