开发者

Java arrays question

开发者 https://www.devze.com 2023-02-22 07:40 出处:网络
I am writing a program for a homework assignment in Java in an arrays chapter.Before I do my question I\'ll go ahead and post the directions here to avoid confusion.

I am writing a program for a homework assignment in Java in an arrays chapter. Before I do my question I'll go ahead and post the directions here to avoid confusion.

This program is model after The International Gymnastics Federation using a scoring system for men’s and women’s artistic gymnastics. The system incorporates credit for the routines difficulty and execution. The Execution and Difficulty Score is calculated by averaging the middle three of five scores. The Execution and Difficulty Score after average are added together for final score. The Execution and Difficulty score are between 0-5. This program will print out direction for program and title. The program should intake 5 judges score for Execution and Difficulty. You will need to use a for loop to intake 5 judges score, and do until scores are within range. Remember you have Execution and Difficulty scores that must be within range. If the user enters Execution score wrong, they must reenter score again and came not continue until score is corrected. The same will be true for Difficulty score. Use the BubbleSort to sort scores for Execution and Difficulty. Them use a print() method to print results. One of the last steps in the program is to calculate average of middle three scores for both Execution and Difficulty and print out the Overall Total Score, by adding the average of the scores.

So my question is can I take in array variables through user input? I am doing this for the judge which I have made an array of. Not sure if this is right but here is my code so far.

import java.util.Scanner;
public class CH6PA
{
    private double difficulty;
    private int score;
    private double[] average;
public CH6PA
{
    public static main void(String[]args)
    {
        int[] judge;
        judge = new int[5];
        judge[0]=keyboard.nextInt();
        judge[1]=keyboard.nextInt();
        judge[2]=keyboard.nextInt();
        judge[3]=keyboard.nextInt();
        judge[4]=keyboard.nextInt();

        System.out.println("Enter the difficulty score for each judge (0-5)");
        judge[0] = keyboard.nextInt();

From making the array I am going on and accepting the difficulty score from each judge but am not sure how to do that. Where开发者_如何学Python I have judge[0]=keyboard.nextInt(); is that the correct way to get the score of the first judge?


It depends on what the input is. Have the user press enter after each score, then yes, you are doing it correctly. Otherwise, you have to specify what the delimiter is and use String.split or something similar to break it up.

There are a couple of things wrong with your code:

  • I have to assume that keyboard is a Scanner. I don't see it declared anywhere.
  • The public CH6PA looks out of place and is probably a type-o

As for your line: judge[0]=keyboard.nextInt(), that looks fine.

Good luck with your homework and I hope you enjoy programming!!

EDIT: I think you know this, but your code won't compile as-is. You don't have a closing brace, but that's just nit-picky.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号