Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8570813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:38:37+00:00 2026-06-11T18:38:37+00:00

I have two programs: Score.java set to do the following: read scores from the

  • 0

I have two programs:

Score.java set to do the following:

  • read scores from the keyboard and print their average.
  • The scores will be numeric and may include a decimal part.

For example a score might be 8.73 or some such. Different contests will have different numbers of judges. It will keep asking for and reading in scores until the user types ‘done’. The program will then print the total score, the number of scores and the average score. The program will then prompt the user to see if there are any more contestants. If there are begin prompting for scores again. If there are no more then exit the program.” I have it set to stop the program when you enter “N”, and set to add future entries to the calculation after entering “Y”.

import java.util.Scanner;

// This is the Score program
// Written by me

public class Score
{
    public static void main(String args[])
    {
        Scanner game = new Scanner(System.in);
        double num = 0.0;
        double sum = 0.0;
        int cnt = 0;

        while (true)
        {
            System.out.println("Enter as many non-negative integers as you like ");
            System.out.println("one at a time and I will find the average");
            System.out.println("Enter done to stop entering numbers");

            System.out.print("enter number: ");
            String ans = game.next();
            while (!ans.equals("done"))
            {
                num = Double.parseDouble(ans);
                sum = sum + num;
                cnt = cnt + 1;

                System.out.print("enter number: ");
                ans = game.next();
            }
            System.out.println(cnt);
            System.out.println(sum);

            System.out.println("Total Score " + sum + " count scores " + cnt + " avg score " + sum / cnt);

            System.out.println("Enter another contestant (Y/N)?");
            String str = game.next();
            if (!str.equals("Y"))
                break;
        }
    }
}

While the above process works, I cannot get my second program, Olympic.java, to work properly after typing “Y” to add more scores. Instead, it starts a whole new calculation of average instead of adding to the previous calculations:

import java.util.Scanner;

// This is the Olympic program
// Written by me

public class Olympic
{
    public static void main(String args[])
    {
        Scanner game = new Scanner(System.in);
        double num = 0.0;
        double sum = 0.0;
        int cnt = 0;
        double highscore = Double.MAX_VALUE;
        double lowscore = Double.MIN_VALUE;

        while (true)
        {
            System.out.println("Enter as many non-negative integers as you like ");
            System.out.println("one at a time and I will find the average");
            System.out.println("Enter done to stop entering numbers");

            System.out.print("enter number: ");
            String ans = game.next();
            lowscore = game.nextDouble();
            highscore = game.nextDouble();
            while (!ans.equals("done"))
            {
                num = Double.parseDouble(ans);
                sum = (sum + num) - lowscore - highscore;
                cnt = cnt + 1;

                System.out.print("enter number: ");
                if (num > highscore)
                {
                    highscore = num;
                }
                if (num < lowscore)
                {
                    lowscore = num;
                }
                ans = game.next();
            }
            System.out.println("Throwing out low score " + lowscore + " and high score " + highscore);
            System.out.println("Total Score " + sum + " count scores " + cnt + " avg score " + sum / cnt);

            System.out.println("Enter another contestant (Y/N)?");
            String str = game.next();
            if (!str.equals("Y"))
                break;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:38:38+00:00Added an answer on June 11, 2026 at 6:38 pm

    So I did a really quick test

    public static void main(String[] args) {
    
        Scanner game = new Scanner(System.in);
    
        while (true) {
    
            System.out.println("Enter another contestant (Y/N)?");
            String str = game.next();
            if (!str.equalsIgnoreCase("Y")) {
                break;
            }
        }
    
        System.out.println("I'm free");
    
    }
    

    And this will exit fine.

    As to your second problem. I think your logic is a little skewed. You could try something like…

    Scanner game = new Scanner(System.in);
    
    double num = 0;
    double sum = 0;
    int cnt = 0;
    
    while (true) {
        System.out.println("Enter as many non-negative integers as you like ");
        System.out.println("one at a time and I will find the average");
        System.out.println("Enter done to stop entering numbers");
    
        double lowscore = Double.MAX_VALUE;
        double highscore = 0;
    
        System.out.print("enter number: ");
        String ans = game.next();
        while (!ans.equals("done")) {
    
            num = Double.parseDouble(ans);
    
            lowscore = Math.min(lowscore, num);
            highscore = Math.max(highscore, num);
    
            sum += num;
            cnt++;
    
            System.out.print("enter number: ");
            if (num > highscore) {
                highscore = num;
            }
            if (num < lowscore) {
                lowscore = num;
            }
            ans = game.next();
        }
    
        sum -= lowscore;
        sum -= highscore;
    
        System.out.println("Throwing out low score " + lowscore + " and high score " + highscore);
        System.out.println("Total Score " + sum + " count scores " + cnt + " avg score " + sum / cnt);
    
        System.out.println("Enter another contestant (Y/N)?");
        String str = game.next();
        if (!str.equalsIgnoreCase("Y")) {
            break;
        }
    }
    

    This will output…

    Enter as many non-negative integers as you like 
    one at a time and I will find the average
    Enter done to stop entering numbers
    enter number: 1
    enter number: 2
    enter number: 3
    enter number: 4
    enter number: 5
    enter number: 6
    enter number: 7
    enter number: 8
    enter number: 9
    enter number: 10
    enter number: done
    Throwing out low score 1.0 and high score 10.0
    Total Score 44.0 count scores 10 avg score 4.4
    Enter another contestant (Y/N)?
    y
    Enter as many non-negative integers as you like 
    one at a time and I will find the average
    Enter done to stop entering numbers
    enter number: 1
    enter number: 12
    enter number: 13
    enter number: 14
    enter number: 15
    enter number: 16
    enter number: 17
    enter number: 18
    enter number: 19
    enter number: 20
    enter number: done
    Throwing out low score 1.0 and high score 20.0
    Total Score 168.0 count scores 20 avg score 8.4
    Enter another contestant (Y/N)?
    n
    

    As to your exception. When using Scanner.nextDouble, it will throw an exception if the input is not parsable as a double. You will need to deal with this situation as you see fit…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two programs, Writer and Reader. I have a FIFO from Writer to
I have the following two programs: long startTime = System.currentTimeMillis(); for (int i =
I am developing two java programs that run in separate VM's that have a
I have two programs, the first is a producer: public class Producer { public
I have two programs: one CLI program, and one GUI. The GUI is a
I have two begininer programs, both using the 'while' function, one works correctly, and
I'm going to have two independent programs (using SqlAlchemy / ORM / Declarative) that
I have two very similar programs each trying to run two threads OddThread and
I need an XML-serializable dictionary. Actually, I now have two quite different programs that
I've got a table recording views of programs. Each program can have two different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.