tQ1)-
Description
For this project, you will be writing a program calledBaseballScores
that is able to traverse through a string of baseball inning scores (Ex: XXXXXXXXXXwith each score separated by commas. These scores will correspond to a baseball game with 9 innings. For more information on baseball, see the next section.
This project is worth 7% of your final grade. We recommend that you take it, along with the other projects in the class, very seriously.
Note: 5 points of your grade is based on Coding Style. You will need to update the Starter Code to follow the standards described on Brightspace. Use the "Run" button to check your Coding Style without using one of your 10 submissions.
Baseball Overview
This assignment does not require previous knowledge of baseball. We provide a short overview of the sport and scoring system as it is relevant to the assignment below.
Baseball is a game wherein two teams compete to score runs using a bat and baseball. One team will play in the field, pitching the baseball and attempting to prevent the opposing team from scoring, while the other team bats and runs the bases. The teams exchange positions halfway through the inning. Feel free to conduct additional research on gameplay if you like.
Note: There are many different statistics in baseball. We will focus on runs for this assignment.
To win a game, a team must score more runs over the course of nine innings than their opponents. Teams also track the score differential, which is the number of points by which they won or lost.
For this assignment, we will be tracking a game log that marks the team's process in each inning. Teams might win, lose, or tie an inning. A perfect inning is defined as an inning where the team scored at least one point while the opposing team did not score any. More details are below.
Instructions
Download the Starter Code. The class already contains the prompts to accept the input and processing to identify individual inning scores by team.
- Do not modify the starter code sections. Scores are converted to integers using parseInt().
- The input string will have exactly 9 innings.
- The range of valid possible scores is 00 to 99.
- You may assume that all game scores are valid.You may also assume that no games will end in a tie, though innings may be tied.
Your solution must do the following:
- Identify the winner of the game, along with the score differential.
- Print the total number of runs each team scored.
- Print a log of each team's wins, losses, and ties by inning.
- Print the number of perfect innings each team played (described in the previous section).
Output examples are in the next section. Follow the same formats and be sure to include the prompts!
Testing
Sample Test 1
Welcome!
Enter Team One Name:
[New York Yankees]
Enter Team Two Name:
[Boston Red Sox]
Enter Inning Scores:
[00-01,00-01,00-01,00-00,00-00,00-00,00-00,04-00,00-00]
The winner is: New York Yankees, with a score differential of 1
New York Yankees scored 4 points.
Boston Red Sox scored 3 points.
New York Yankees Game Log: L-L-L-T-T-T-T-W-T
Boston Red Sox Game Log: W-W-W-T-T-T-T-L-T
New York Yankees Perfect Innings: 1
Boston Red Sox Perfect Innings: 3
Sample Test 2
Welcome!
Enter Team One Name:
[Miami Marlins]
Enter Team Two Name:
[New York Mets]
Enter Inning Scores:
[02-01,00-00,00-00,00-02,00-00,01-00,00-01,00-00,00-00]
The winner is: New York Mets, with a score differential of 1
Miami Marlins scored 3 points.
New York Mets scored 4 points.
Miami Marlins Game Log: W-T-T-L-T-W-L-T-T
New York Mets Game Log: L-T-T-W-T-L-W-T-T
Miami Marlins Perfect Innings: 1
New York Mets Perfect Innings: 2
Note: Brackets [] indicate input.
Note: Match this output exactly. Spelling mistakes will result in lost points.
Public Test Cases Note
For many homework assignments and projects, we will give you test cases that correspond to several of the ways we will be testing your program. But, we will not give you test cases for ALL of the ways we will be testing your program. You should think of other test cases to use that will fully test every aspect of every feature of your program. Just because your program passes all the test cases we give you does not mean that it is fully correct and will receive a score of 100.
We encourage you to review and modify the public test cases to verify your program works as expected for other input values!
Submit
After testing your solution and verifying that it meets the requirements described in this document, you can submit on Vocareum. You have 10 submission attempts to achieve full points.
starter code-
import java.util.Scanner;
/**
*Project 1-- A simple BaseballScores class
*
*This program is able to traverse through a string of baseball inning scores (Ex: XXXXXXXXXXwith each score separated by commas. These scores correspond to a baseball game with 9 innings.
*@obusired, lab sec B17
*@version 09/27/2021
*/
public class BaseballScores {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Welcome!");
System.out.println("Enter Team One Name:");
String teamOne = scanner.nextLine();
System.out.println("Enter Team Two Name:");
String teamTwo = scanner.nextLine();
System.out.println("Enter Inning Scores:");
String scores = scanner.nextLine();
scanner.close();
// The scores for each inning are calculated and stored in the variables below.
int currentScoreIndex = 0;
int teamOneInningOne = Integer.parseInt(scores.substring(currentScoreIndex, currentScoreIndex + 2));
currentScoreIndex += 3;
int teamTwoInningOne = Integer.parseInt(scores.substring(currentScoreIndex, currentScoreIndex + 2));
currentScoreIndex += 3;
int teamOneInningTwo = Integer.parseInt(scores.substring(currentScoreIndex, currentScoreIndex + 2));
currentScoreIndex += 3;
int teamTwoInningTwo = Integer.parseInt(scores.substring(currentScoreIndex, currentScoreIndex + 2));
currentScoreIndex += 3;
int teamOneInningThree = Integer.parseInt(scores.substring(currentScoreIndex, currentScoreIndex + 2));
currentScoreIndex += 3;
int teamTwoInningThree = Integer.parseInt(scores.substring(currentScoreIndex, currentScoreIndex + 2));
currentScoreIndex += 3;
int teamOneInningFour = Integer.parseInt(scores.substring(currentScoreIndex, currentScoreIndex + 2));
currentScoreIndex += 3;
int teamTwoInningFour = Integer.parseInt(scores.substring(currentScoreIndex, currentScoreIndex + 2));
currentScoreIndex += 3;
int teamOneInningFive = Integer.parseInt(scores.substring(currentScoreIndex, currentScoreIndex + 2));
currentScoreIndex += 3;
int teamTwoInningFive = Integer.parseInt(scores.substring(currentScoreIndex, currentScoreIndex + 2));
currentScoreIndex += 3;
int teamOneInningSix = Integer.parseInt(scores.substring(currentScoreIndex, currentScoreIndex + 2));
currentScoreIndex += 3;
int teamTwoInningSix = Integer.parseInt(scores.substring(currentScoreIndex, currentScoreIndex + 2));
currentScoreIndex += 3;
int teamOneInningSeven = Integer.parseInt(scores.substring(currentScoreIndex, currentScoreIndex + 2));
currentScoreIndex += 3;
int teamTwoInningSeven = Integer.parseInt(scores.substring(currentScoreIndex, currentScoreIndex + 2));
currentScoreIndex += 3;
int teamOneInningEight = Integer.parseInt(scores.substring(currentScoreIndex, currentScoreIndex + 2));
currentScoreIndex += 3;
int teamTwoInningEight = Integer.parseInt(scores.substring(currentScoreIndex, currentScoreIndex + 2));
currentScoreIndex += 3;
int teamOneInningNine = Integer.parseInt(scores.substring(currentScoreIndex, currentScoreIndex + 2));
currentScoreIndex += 3;
int teamTwoInningNine = Integer.parseInt(scores.substring(currentScoreIndex, currentScoreIndex + 2));
// TODO - Implement your solution!
}
}
Q2)-
Description
For this Homework, you will be writing a program calledPatternMatcher
that allows a user to play a pattern game. The user will select the level of difficulty and enter a starting digit for the sequence. The program will respond by printing the first four numbers in the pattern and requesting the next three. There are three possible levels of difficulty.
Note: 5 points of your Challenge grade is based on Coding Style. You will need to follow the standards described on Brightspace. Use the "Run" button to check your Coding Style without using a submission.
Instructions
Given user input, generate a pattern matching game of the appropriate difficulty. The user will then attempt to enter the next three numbers in the sequence generated by the program. The game repeats until the user decides to exit.
If the user enters all three numbers correctly, print the congratulations prompt. Otherwise, print the sorry prompt. Then ask the user if they want to play again. If the user inputs y or Y, go back to the beginning of the game. If the user inputs anything other than y or Y, the program should end.
Note: You may assume that all pattern values will be integers
Level 1
Pattern: Add 2 each time.
Example
Initial Number: 1
1, 3, 5, 7, 9, 11, 13
Sample Output
Choose Level Difficulty:
1. Easy
2. Medium
3. Hard
[1]
Enter a number to start the pattern:
[1]
Enter the next 3 numbers in the pattern:
1 3 5 7
[9]
[11]
[13]
Congrats! Your answer was correct!
Play Game Again? (y/n)
[n]
Ending Pattern Matcher...
Level 2
Pattern: Multiply by 4 each time.
Example
Initial Number: 5
5, 20, 80, 320, 1280, 5120, 20480
Sample Output
Choose Level Difficulty:
1. Easy
2. Medium
3. Hard
[2]
Enter a number to start the pattern:
[5]
Enter the next 3 numbers in the pattern:
XXXXXXXXXX
[1280]
[5120]
[20480]
Congrats! Your answer was correct!
Play Game Again? (y/n)
[n]
Ending Pattern Matcher...
Level 3
Pattern: Square each number and then add 1. The next input number for the calculation is the previous calculation input + 1.
Example
Initial Number: 3
10, 17, 26, 37, 50, 65, 82
Explanation:
32+ 1 = 10
42+ 1 = 17
52+ 1 = 26
62+ 1 = 37
72+ 1 = 50
… (and so on)
Sample Output
Choose Level Difficulty:
1. Easy
2. Medium
3. Hard
[3]
Enter a number to start the pattern:
[3]
Enter the next 3 numbers in the pattern:
XXXXXXXXXX
[50]
[65]
[82]
Congrats! Your answer was correct!
Play Game Again? (y/n)
[n]
Ending Pattern Matcher...
Notes
- Brackets [] are used to indicate input.
- You are not permitted to use System.exit in this program (or any other CS 18000 assignment).
- The menu must repeat until the user indicates they want to exit.
- If the user enters an invalid option while selecting the level, print the menu again.
- After the user enters anything other than y or Y when prompted to continue, print an exit message and end the program.
- "Ending Pattern Matcher..."
Valid Assumptions
- You can assume that no user will enter a value that is not an integer.
- You can assume that no user will enter a value that is mathematically impossible to use within the calculations.
- You can assume that no operation will result in a non-integer value during any stage of calculation.
- You can assume that no input will result in values that overflow the integer data type.
- You can assume that users will always enter the correct number of integers.
Testing
Sample Output Test
Choose Level Difficulty:
1. Easy
2. Medium
3. Hard
[4]
Choose Level Difficulty:
1. Easy
2. Medium
3. Hard
[5]
Choose Level Difficulty:
1. Easy
2. Medium
3. Hard
[1]
Enter a number to start the pattern:
[80]
Enter the next 3 numbers in the pattern:
XXXXXXXXXX
[88]
[90]
[92]
Congrats! Your answer was correct!
Play Game Again? (y/n)
[y]
Choose Level Difficulty:
1. Easy
2. Medium
3. Hard
[3]
Enter a number to start the pattern:
[5]
Enter the next 3 numbers in the pattern:
XXXXXXXXXX
[82]
[101]
[0]
Sorry! Your answer was incorrect!
Play Game Again? (y/n)
[n]
Ending Pattern Matcher...
Note: Brackets [] indicate input.
Note: Match this output exactly. Spelling mistakes will result in lost points.
Public Test Cases Note
For many homeworks and projects, we will give you test cases that correspond to several of the ways we will be testing your program. But, we will not give you test cases for ALL of the ways we will be testing your program. You should think of other test cases to use that will fully test every aspect of every feature of your program. Just because your program passes all the test cases we give you does not mean that it is fully correct and will receive a score of 100.
We encourage you to review and modify the public test cases to verify your program works as expected for other input values!
Submit
After testing your solution and verifying that it meets the requirements described in this document, you can submit on Vocareum. You have 10 submission attempts to achieve full points.
statter code-
import java.util.Scanner;
/**
* HW-05 -- Challenge
*
* This program inputs the total number of minutes,
* the number of minutes for commercials, and the
* number of minutes for episodes. The program
* computes the total number of minutes for videos,
* the number of videos, and the number of seconds
* left over.
*
* @obusired, lab sec L17
*
* @version September 26, 2021
*
*/
public class PatternMatcher {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String chooseLevel = "Choose Level Difficulty:" +
"\n1. Easy\n2. Medium\n3. Hard";
int Level = scanner.nextInt();
String startNumber = "Enter a number to start the pattern:";
int number= scanner.nextInt();
String nextThree = "Enter the next 3 numbers in the pattern:";
int numbers= scanner.nextInt();
String congratulations = "Congrats! Your answer was correct!";
String sorry = "Sorry! Your answer was incorrect!";
String again = "Play Game Again? (y/n)";
String ending = "Ending Pattern Matcher...";
//TODO: write your code below
}
}