Question

In Java Problem Description/Purpose:  Write a program that will compute and display the final score...

In Java

Problem Description/Purpose:  Write a program that will compute and display the final score of two teams in a baseball game. The number of innings in a baseball game is 9.    Your program should read the name of the teams. While the user does not enter the word done for the first team name, your program should read the second team name and then read the number of runs for each Inning for each team, calculate the total scores and display the total score for each team.     o Create a constant for 9 innings. o Create an array of String to hold the baseball team names o Create an array to store the corresponding scores. o There must be a programmatic relationship between the arrays o You know there are exactly 2 teams. You also know there are exactly 9 innings.   Use loops such that for each team, and for each inning, the user enters the number of runs scored and calculates the total for each team. o Display the final scores afterwards. o Repeat with new teams until the user enters the word "done" instead of a name for the first team name. o End the program with the words "Program complete"  Hints: o STUDY THE OUTPUT EXAMPLES at the end of this document very carefully.   o This project will need multiple for loops and a while loop. o You may need to use a blanket statement of keyboard.nextLine() if you are reading a sequence of integers and then a nextLine. o There is not ONE RIGHT SOLUTION. Each of your solutions may be different and that will be great to see! Standards:  Set appropriate variables for all the data. Use meaningful names.  You must use a constant for the number of Innings.  You must use for loop(s) and a while loop where appropriate. Objectives:  Practice what you have learned:  Primitive Data Types  String Data Types  loops  arrays  Programming basics
 Algorithms (your plan).  Comments Requirements/Task(s):  The appropriate set of variables and data types for those variables should be created.  Feel free to create AS MANY variables as you need.    Use the appropriate programming techniques to solve the problem.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Java code

============================================================================================

import java.util.Scanner;

public class BaseballGame {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       Scanner keyboard=new Scanner(System.in);
      
       //Create a constant for 9 innings
       final int innings=9;
       //Create an array of String to hold the baseball team name
       String[] teamname=new String[2];
       //Create an array to store the corresponding scores.
       int []score=new int[innings];
      
       int i,j;
       int total;
      
       System.out.print("Enter name for team 1: ");
       teamname[0]=keyboard.nextLine();
      
       while(!teamname[0].equals("done"))
       {
           System.out.print("Enter name for team 2: ");
           teamname[1]=keyboard.nextLine();
          
           for(i=0;i<2;i++)
           {
               total=0;
               System.out.println("Enter score for team "+teamname[i]);
               for(j=0;j<innings;j++)
               {
                   int k=j+1;
                   System.out.print("Enter score for inning "+k+": ");
                   score[j]=keyboard.nextInt();
                   total=total+score[i];
               }
               System.out.println("Score for team "+teamname[i]+" is : "+total);
              
              
           }
           keyboard.nextLine();
          
           System.out.print("Enter name for team 1: ");
           teamname[0]=keyboard.nextLine();
          
       }
      
      
      
      
      

   }

}

============================================================================================

Output

Add a comment
Know the answer?
Add Answer to:
In Java Problem Description/Purpose:  Write a program that will compute and display the final score...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a class named BaseballGame that contains data fields for two team names and scores for...

    Create a class named BaseballGame that contains data fields for two team names and scores for each team in each of nine innings. names should be an array of two strings and scores should be a two-dimensional array of type int; the first dimension indexes the team (0 or 1) and the second dimension indexes the inning. Create get and set methods for each field. The get and set methods for the scores should require a parameter that indicates which...

  • In java, write a program that gets 10 integer numbers from the user using user input,...

    In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read.   Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. version1:  use a while loop. version2:  use a do-while loop. version 3:  use a for loop. For each version, use a loop to input 10 int numbers from the user...

  • import java.util.*; /** Description: This program determines the average of a list of (nonnegative) exam scores....

    import java.util.*; /** Description: This program determines the average of a list of (nonnegative) exam scores. Repeats for more exams until the user says to stop. Input: Numbers, sum, answer Output: Displays program description Displays instruction for user Displays average Algorithm: 1. START 2. Declare variables sum, numberOf Students, nextNumber, answer 3. Display welcome message and program description 4. DOWHILE user wants to continue 5. Display instructions on how to use the program 6. Inititalize sum and number of student...

  • [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and...

    [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...

  • In this assignment, you will write a program in C++ which uses files and nested loops...

    In this assignment, you will write a program in C++ which uses files and nested loops to create a file from the quiz grades entered by the user, then reads the grades from the file and calculates each student’s average grade and the average quiz grade for the class. Each student takes 6 quizzes (unknown number of students). Use a nested loop to write each student’s quiz grades to a file. Then read the data from the file in order...

  • JAVA Write a program that prompts the user to enter a file name, then opens the...

    JAVA Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it. The input files are assumed to be in CSV format. The input files contain a list of integers on each line separated by commas. The program should read each line, sort the numbers and print the comma separated list of integers on the console. Each sorted list of integers from the same line should be printed together...

  • Small Basic Programming Question: Average score Write a program that uses loops to collect data and...

    Small Basic Programming Question: Average score Write a program that uses loops to collect data and calculate the average score over a number of tests for a number of students. The program should : 1. first ask the user to enter the number of students in the range of 1 to 10. 2. then the program asks the user to enter the number of tests (in the range of 1 to 5) 3. Then use a loop to collect the...

  • In Java. Write a GUI contact list application. The program should allow you to input names...

    In Java. Write a GUI contact list application. The program should allow you to input names and phone numbers. You should also be able to input a name and have it display the previously entered phone number. The GUI should look something like the following, although you are welcome to format it in any way that works. This should be a GUI application with a JFrame. The program should contain two arrays of Strings. One array will contain a list...

  • .Need code for my java class !! Write a simple java program that uses loops. You...

    .Need code for my java class !! Write a simple java program that uses loops. You may use ‘WHILE’ or ‘FOR’ or ‘DO-WHILE’ – you decide. The program should use a loop to compute the semester average for up to 5 students. In the loop the user will ask for a student name and their 3 test scores and add them up and divide the total by 3 giving the semester average. You will print out the student name and...

  • write a java program that does the following Part one Use a For loop to compute...

    write a java program that does the following Part one Use a For loop to compute the sum of all the odd numbers from 1 through 99. Your result should be labeled, and the value should be 2500. Print your name 7 times using a While loop. String dogNames[ ] = {"Sam","Buster","Fido","Patches","Gromit","Flicka"}; Using the array defined here, print the values of the array vertically and horizontally using one For-Each loop. Reverse the logic (Nested loops: Indent text) so that the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT