Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Help starting program, need done by Nov 4

  1. #1
    Banned
    Join Date
    Sep 2009
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Help starting program, need done by Nov 4

    Write a program that reads in a set of test scores, computes their average, and finds out how many scores are above the average. Use a sentinel value of -1 to indicate the end of the set of scores. Assume that the number of test scores is less or equal to 30. Your solution should include two methods in addition to the main method. One to compute the average and one to print all scores above the average. (This is an expanded version of problem 6.1 on page 222 of the book.)


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Help starting program, need done by Nov 4

    What have you done?

  3. #3
    Banned
    Join Date
    Sep 2009
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Red face Re: Help starting program, need done by Nov 4

    This is what i have im lost on how to keep track of the testscores entered. I also need help creating a method for the average and for printing those scores above average!!!!!!!!
    import java.util.Scanner;
    public class ComputeAverage{
    public static void main(String [] args){
     
    	Scanner input = new Scanner(System.in);
     
    	Sysetm.out.println("Enter test scores, enter in -1 when you are done: ");
     
    	int testScores = input.nextInt();
       int total = 0;
    	while (testScores != -1){
    		total += testScores;
     
    		System.out.println("Enter test scores, enter in -1 when you are done: ");
     
    		testScores= input.nextInt();
    	}	
    	int N = 0; // number input values 
       double sum = 0.0; // sum of input values
     
    	while (!StdIn.isEmpty()) {
    		testScores = StdIn.readDouble();
       	N = N + 1; 
    		sum = sum + testScores; 
    	} 
       public static void getAverage(int testScores){
    		if (testScore <= 100){
    			double average = sum / N;
             return;
    	   }
    	}
    	public static void printAboveAverage(int testScores){
    		if (testScores >= average){
    Last edited by helloworld922; November 3rd, 2009 at 04:10 PM.

  4. #4
    Banned
    Join Date
    Sep 2009
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Re: Help starting program, need done by Nov 4

    What i really need is to create an array to store the test scores but im very new to java and unfamiliar with arrays..

  5. #5
    Member
    Join Date
    Jul 2009
    Posts
    31
    Thanks
    3
    Thanked 6 Times in 5 Posts

    Default Re: Help starting program, need done by Nov 4

    problem statement doesn't state that testscores are integers.

  6. #6
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Help starting program, need done by Nov 4

    A simple guide to arrays:

    Arrays are declared like this:
    type[] var_name;
    type is any type you want, and var_name is any variable name you want (just like any other variables).

    To create an array of ints:
    some_array = new int[length];
    where length is the length of the array you want. NOTE: Once you create an array, it's length cannot be changed! If you need an array of a different size (usually larger), you must create a new array and move stuff from the old array to the new array.

    How to access the elements of an array:

    Array's are accessed by using the var_name and the index. The index is which element inside that array you want to get. In Java, array indices run from 0 to one less than the length.
    some_array[index];
    this gives you the element stored at index in some_array.

  7. #7
    Banned
    Join Date
    Sep 2009
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help starting program, need done by Nov 4

    here is what i have revised, im not sor wheather the for loop or the while loop is better to use
    the for loop seems to save test scores to array where as while loop just has that sentinal value yo stop the loop.
    import java.util.Scanner;
    public class ComputeAverage{
    public static void main(String [] args){
    * *
    * *Scanner input = new Scanner(System.in);
    **// Determine number of test scores to be computed 
    * *System.out.println("Enter number of test scores, less than 30: ");
    * *int n = input.nextInt();
    * *// Create array to store test scores 
    * *int [] scores = new int [n]
    * *// Enter test scores
    * * * *System.out.println("Enter test scores, enter in -1 when you are done: ");
    * * **int testScores = input.nextInt();
    * *// Create sentinal value when done with inputing scores
    * *int total = 0;
    * *while (testScores != -1){
    * * * *total += testScores;
    * * * *System.out.println("Enter test scores, enter in -1 when you are done: ");
    * * * *
    * * * *testScores = input.nextInt();
    * *}
    * *for (int i = 0; i < scores.length; i++){
    * * * *System.out.println("Enter a score: ");
    * * * *scores[i] = input.nextInt();
    * *
    * * * *if (testScores == -1) * *break;
    * *} * *
    * *
    * *// Method to compute average
    **public static void getAverage(int testScores){
    * * * *if (n < 30){
    * * * * * *int average = scores[i]/n;
    ********return;
    * * **
    * *}
    * *// Method to print scores above the Average
    * *public static void printAboveAverage(int testScores){
    * * * *if (testScores >= average){
    * * * *return;
    * *} * *
    }
    }
    Last edited by helloworld922; November 4th, 2009 at 04:26 PM.

  8. #8
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Help starting program, need done by Nov 4

    what's with all the *'s?

Similar Threads

  1. Need help starting a program
    By Mickey2315 in forum Java Theory & Questions
    Replies: 2
    Last Post: September 7th, 2009, 02:21 PM
  2. Starting a java programming career
    By oss_2008 in forum The Cafe
    Replies: 3
    Last Post: July 8th, 2009, 07:45 AM