How do I create this java/computer science program?
-
This is my first school course in computer science. I am utterly lost and can't get the information of java to stick. I have an assignment due tomorrow that I have no idea how to do. Maybe some computer programmers out there can offer me some help! I use the program jgrasp... "In this assignment, you are to input integer test scores. The scores are in the range 0..100. Scores are input until the sentinel value 999 is entered. No other score terminates the input. If a number outside of the allowed range of 0..100 is entered (except 999), the user is told that the number is not an allowed number and prompted for a new one. The program outputs the lowest (legal) score, the highest (legal) score and the average (to two decimal places), and number of scores." The output should look as follows: Enter test scores, and get the lowest score, the highest score, and the average. Enter 999 to quit. Enter a score [0..100] (999 to quit): 70 Enter a score [0..100] (999 to quit): 808 Enter only 0..100 (999 to quit): 800 Enter only 0..100 (999 to quit): -47 Enter only 0..100 (999 to quit): 80 Enter a score [0..100] (999 to quit): 90 Enter a score [0..100] (999 to quit): 999 RESULTS The lowest score is 70. The highest score is 90. The average score is 80.00. There were 3 scores. The numbers in the output arent the real numbers, I have to enter 22 values given to me so I need a general program where I can substitue the numbers. We are suppose to use a Scanner object for input, declared constants for literal values such as the prompts, and use only whiles or do-whiles loops. For the average I am to use the DecimalFormat class. the code I've made (and doesn't work I am veryyyy bad and new to this): import java.util.Scanner; public class Score_Averages { public static void main(String[] args) { //instruct System.out.println("Enter test scores, and get the lowest score, the highest score, and the e. \nEnter 999 to quit.\n\n"); //create scanner class final int MAX_SCORE = 100; final int MIN_SCORE = 0; int score; Scanner kbd = new Scanner(System.in); while (score < MAX_SCORE || score > MIN_SCORE) { System.out.print("Enter a score [0..100] (999 to quit): "); score = kbd.nextInt(); } while (score > MAX_SCORE) { System.out.print("Enter only 0..100 (999 to quit): "); score = kbd.nextInt(); } } }
-
Answer:
See Use.: int total=0,min=0,max=0;//total, min and max scores int cnt=0;//counter to scores entered fload avg; Now inside the 1st while:- while (score !=999) { System.out.print("Enter a score [0..100] (999 to quit): "); score = kbd.nextInt(); } if( (score < MAX_SCORE || score > MIN_SCORE) { System.out.print("Enter only 0..100 (999 to quit): "); } else if(score==999) break; else { total+=score; if(score>max) max=score; if(score<min) min=score; } }//ENd of while System.out.println("The lowest score is "+min); System.out.println("The highest score is"+max); System.out.println("The average score is "+total); if(count>0) avg=total/count; else avg=0; System.out.println("There were "+ count+" scores."); } Note:ur 2n while is useless!
Dresden at Yahoo! Answers Visit the source
Related Q & A:
- What should I do with my Computer Science degree?Best solution by Quora
- Where should I work as a computer science major?Best solution by Yahoo! Answers
- What kind of jobs can I get with a computer science degree?Best solution by Yahoo! Answers
- How should I prepare for a computer science career?Best solution by cs.ucdavis.edu
- What can I do with a computer science degree besides web development or IT?Best solution by worldwidelearn.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.