MINDTAPV2.0 JAVA PROGRAMMING 2021, 1TERM
9th Edition
ISBN: 9780357505526
Author: FARRELL
Publisher: CENGAGE L
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 10, Problem 6PE
Program Plan Intro
Base ball game
Program plan:
Filename: “DemoBaseballGame.java”
- Include the required header files
- Define the class “DemoBaseballGame”
- Define the main method
- Create an object for “BaseballGame” class
- Call the method “SetNames” for setting the names
- Call the method “display”
- Call the “setScore” method for setting the score
- After setting the score, call the “display” method
- Call the “setScore” method in fifth inning
- Call the “setScore” method after setting second inning
- Call the “setScore” method for invalid inning
- Call the “setScore” method for invalid team
- Iterate the “t” value until it reaches “2”
- Iterate the “i” value until it reaches “getInnings”
- Call the “setScore” method
- Iterate the “i” value until it reaches “getInnings”
- Call the “display” method
- Define the “display” method
- Declare the required variables
- Display the teams
- Iterate the “t” value until it reaches “2”
- Iterate the “i” value until it reaches “getInnings”
- Call the “getScore” method
- Check “score” is not equal to “BaseballGame.UNPLAYED”
-
- Check the “i” is equal to 0
- Display the team
- Display the score
- Calculate the total score
-
- Set the value
-
- Check the “i” is equal to 0
- Iterate the “i” value until it reaches “getInnings”
- Check the condition
- Display no innings played yet
- Check the condition
- Check “total[0]” is greater than “total[1]”
- Display the winning name
- Otherwise, check “total [0]” is less than “total [1]”
- Display the winning name
- Otherwise, display game is tie.
- Check “total[0]” is greater than “total[1]”
- Define the main method
Filename: “BaseballGame.java”
- Define the “BaseballGame” class
- Declare the required variables
- Define the constructor
- Declare an array variable
- Iterate “t” until it reaches “scores” length
- Iterate “i” until it reaches “scores [t]” length
- Set the value
- Iterate “i” until it reaches “scores [t]” length
- Define the “setNames” method
- Set the values
- Define the “setScore” method
- Declare the required variables
- Check “team” is less than 0 or greater than “scores” length minus 1
- Display the team is valid
- Check “inning” is less than 0 or greater than “scores” length minus 1
- Display the team is not valid
- Otherwise,
- Iterate “x” until it reaches “inning”
- Check the condition
-
- Set the value
- Check the condition
- Display a score can’t yet be set for inning
- Otherwise, set the value
- Iterate “x” until it reaches “inning”
- Define the “setNames” method
- Return the names
- Define the “getNames” method
- Return the position of the name
- Define the “getScores” method
- Declare the variable
- Check “team” is less than 0 or greater than “scores” length minus 1
- Display invalid team number
- Check “inning” is less than 0 or greater than “scores[0]” length minus 1
- Display invalid inning
- Otherwise, set the value
- Define “getInnings” method
- Return innings
Filename: “HighSchoolBaseballGame.java”
- Declare the variable and assign the value
- Define the constructor
- Declare the array variable
- Iterate “t” until it reaches “scores” length
- Iterate “i” until it reaches “scores[t]” length
- Set the value
- Iterate “i” until it reaches “scores[t]” length
- Define “getInnings” method
- Return innings
Filename: “LittleLeagueBaseballGame.java”
- Declare the variable and assign the value
- Define the constructor
- Declare the array variable
- Iterate “t” until it reaches “scores” length
- Iterate “i” until it reaches “scores[t]” length
- Set the value
- Iterate “i” until it reaches “scores[t]” length
- Define “getInnings” method
- Return innings
Filename: “DemoLLBaseballGame.java”
- Include the required header files
- Define the class “DemoLLBaseballGame”
- Define the main method
- Create an object for “LittleLeagueBaseballGame” class
- Call the method “SetNames” for setting the names
- Call the method “display”
- Call the “setScore” method for setting the score
- After setting the score, call the “display” method
- Call the “setScore” method in fifth inning
- Call the “setScore” method after setting second inning
- Call the “setScore” method for invalid inning
- Call the “setScore” method for invalid team
- Iterate the “t” value until it reaches “2”
- Iterate the “i” value until it reaches “getInnings”
- Call the “setScore” method
- Iterate the “i” value until it reaches “getInnings”
- Call the “display” method
- Define the “display” method
- Declare the required variables
- Display the teams
- Iterate the “t” value until it reaches “2”
- Iterate the “i” value until it reaches “getInnings”
- Call the “getScore” method
- Check “score” is not equal to “BaseballGame.UNPLAYED”
-
- Check the “i” is equal to 0
- Display the team
- Display the score
- Calculate the total score
-
- Otherwise, set the value
-
- Check the “i” is equal to 0
- Iterate the “i” value until it reaches “getInnings”
- Check the condition
- Display no innings played yet
- Check the condition
- Check “total[0]” is greater than “total[1]”
- Display the team 1 is win
- Otherwise, check “total [0]” is less than “total [1]”
- Display the team 2 is win
- Otherwise, display game is tie.
- Check “total[0]” is greater than “total[1]”
- Define the main method
Filename: “DemoHSBaseballGame.java”
- Include the required header files
- Define the class “DemoHSBaseballGame”
- Define the main method
- Create an object for “HighSchoolBaseballGame” class
- Call the method “SetNames” for setting the names
- Call the method “display”
- Call the “setScore” method for setting the score
- After setting the score, call the “display” method
- Call the “setScore” method in fifth inning
- Call the “setScore” method after setting second inning
- Call the “setScore” method for invalid inning
- Call the “setScore” method for invalid team
- Iterate the “t” value until it reaches “2”
- Iterate the “i” value until it reaches “getInnings”
- Call the “setScore” method
- Iterate the “i” value until it reaches “getInnings”
- Call the “display” method
- Define the “display” method
- Declare the required variables
- Display the teams
- Iterate the “t” value until it reaches “2”
- Iterate the “i” value until it reaches “getInnings”
- Call the “getScore” method
- Check “score” is not equal to “BaseballGame.UNPLAYED”
-
- Check the “i” is equal to 0
- Display the team
- Display the score
- Calculate the total score
-
- Otherwise, set the value
-
- Check the “i” is equal to 0
- Iterate the “i” value until it reaches “getInnings”
- Check the condition
- Display no innings played yet
- Check the condition
- Check “total[0]” is greater than “total[1]”
- Display the team 1 is win
- Otherwise, check “total [0]” is less than “total [1]”
- Display the team 2 is win
- Otherwise, display game is tie.
- Check “total[0]” is greater than “total[1]”
- Define the main method
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
The college that you attend requires an application that will print out a Course Report. You are required to create an application that will allocate the following course data:COURSE CODE COURSE NAME STUDENT NUMBERS LECTURERDISD Diploma in Software Development 35 Mr JonesDIWD Diploma in Web Development 28 Mrs SmithDIDM Diploma in Data Metrics 39 Mr NtsingaCreate a class named Course_Details that will contain get and set methods for the course name, student numbers and lecturer. In the Course_Details class include a method called Assign Venue that will randomly generate a Venue/Class for the course. Venues can be from 1 to 3 only. Your main class must include a static method to handle the printing of the course report.
The xxx_Student class:– Name - the name consists of the First and Last name separated by a space.– Student Id – a whole number automatically assigned in the student class– Student id numbers start at 100. The numbers are assigned using a static variable in the Student class• Include all instance variables• Getters and setters for instance variables• A static variable used to assign the student id starting at 100• A toString method which returns a String containing the student name and id in the format below:Student: John Jones ID: 101
The xxx_Course classA Course has the following information (modify your Course class):– A name– An Array of Students which contains an entry for each Student enrolled in the course (allow for up to 10 students)– An integer variable which indicates the number of students currently enrolled in the course.
Write the constructor below which does the following:Course (String name)Sets courseName to nameCreates the students array of size 10Sets number of…
Design a class named BaseBallGame that has the fields for two names and a final score for each team. Include methods to set and get the values for each data field. Create the class diagram and write the pseudocode that defines the class.
Design an application (submit pseudocode) that declares three BaseBallGame objects and sets and displays their values.
Design an application (submit pseudocode) that declares an array of 12 BaseBallGame objects. Prompt the user for data for each object, and display all the values. Then pass each object to a method that displays the name of the winning team or "Tie" if the score is a tie.
Chapter 10 Solutions
MINDTAPV2.0 JAVA PROGRAMMING 2021, 1TERM
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Design a class named CustomerRecord that holds a customer number, name, and address. Include separate methods to 'set' the value for each data field using the parameter being passed. Include separate methods to 'get' the value for each data field, i.e. "return" the field's value. Pseudocode:arrow_forwardMick’s Wicks makes candles in various sizes. Create a class for the business named Candle that contains the following data fields: color - of type String height - of type int price - of type double Create get methods for all three fields. Create set methods for color and height, but not for price. Instead, when height is set, determine the price as $2 per inch. Create a child class named ScentedCandle that contains an additional data field named scent (of type String) and methods to get and set it. In the child class, override the parent’s setHeight() method to set the price of a ScentedCandle object at $3 per inch.arrow_forwardIntroduction In this project, you will complete a C++ class by writing a copy constructor, destructor, and assignment operator. Furthermore, you will write a tester class and a test program and use Valgrind to check that your program is free of memory leaks. Finally, you will submit your project files on GL. If you have submitted programs on GL using shared directories (instead of the submit command), then the submission steps should be familiar. In this project we develop an application which holds the information about a digital art piece. There are two classes in this project. • The Random class generates data. The implementation of this class is provided. It generates random int numbers for colors. To create an object of this class we need to specify min and max values for the constructor. The colors fall between 30 and 37 inclusively. The Art class generates random colors and stores the color values. You implement the Art class. An object of the Art class is a digital masterpiece.…arrow_forward
- • Create a class called TeslaStock. This class will be used to represent each stock's data in your project. This class should not contain any methods to read / write the data. Only implement the following in the class. • This class should contain data fields for the date, opening price, low price, high price, and closing price of a stock. All data fields shall have the PRIVATE access modifier. 。 NOTE: Be sure to use the correct data types for each piece of data. Create getters and setters for each data field. • Create appropriate constructors for this class. Implement the toString() method to display a TeslaStock object in the following format: o Date: 2010-06-29 . Opening Price: High Price: Low Price: 3.8 5.0 3.508 4.778 Closing Price: • No other methods are allowed.arrow_forwardDice Rolling Class In this problem, you will need to create a program that simulates rolling dice. To start this project, you will first need to define the properties and behaviors of a single die that can be reused multiple times in your future code. This will be done by creating a Dice class. Create a Dice class that contains the following members: Two private integer variables to store the minimum and maximum roll possible. Two constructors that initialize the data members that store the min/max possible values of rolls. a constructor with default min/max values. a constructor that takes 2 input arguments corresponding to the min and max roll values Create a roll() function that returns a random number that is uniformly distributed between the minimum and maximum possible roll values. Create a small test program that asks the user to give a minValue and maxValue for a die, construct a single object of the Dice class with the constructor that initializes the min and max…arrow_forwardThis is the question I am stuck on - Radio station KJAVA wants a class to keep track of recordings it plays. Create a class named Recording that contains fields to hold methods for setting and getting a Recording’s title, artist, and playing time in seconds. Write an application that instantiates five Recording objects and prompts the user for values for the data fields. Then prompt the user to enter which field the Recordings should be sorted by—(S)ong title, (A)rtist, or playing (T)ime. Perform the requested sort procedure, and display the Recording objects. This is what I have so far - public class Recording { private String song; private String artist; private int playTime; public void setSong(String title) { this.song = title; } public void setArtist(String name) { this.artist = name; } public void setPlayTime(int time) { this.playTime = time; } public String getSong() { return song; } public String…arrow_forward
- The college that you attend requires an application that will print out a Course Report. You arerequired to create an application that will allocate the following course data: COURSE CODE COURSE NAME STUDENT NUMBERS LECTURER DISD Diploma in Software Development 35 Mr Jones DIWD Diploma in Web Development 28 Mrs Smith DIDM Diploma in data Metrics 39 Mr Ntsinga Create a class named Course_Details that will contain get and set methods for the course name,student numbers and lecturer. In the Course_Details class include a method called Assign Venuethat will randomly generate a Venue/Class for the course. Venues can be from 1 to 3 only. Yourmain class must include a static method to handle the printing of the course report Use java languagearrow_forwardFor this assignment, you need to build a class that contains basic information about students and courses that have those students on the roster. You also need to build a menu that supports basic CRUD functionality for those courses. The requirements are as follows: The student class should contain the following data about a student: Name (dynamic char array) Classification (char) Major (dynamic char array) StudentId (can be an int or a dynamic char array) The course class should contain the following data about a course: Course Name (dynamic char array) Course Code (char array of size 7) Location (char array of size 10) Roster (dynamic student array) The menu program should act as a driver program that manages a dynamically allocated array of courses and allows the user to: Add a course to the list Add students to a course Update a course to change any of the data above including edits to students or adding/removing students from the roster List courses including students in the…arrow_forwardAppointment Class Requirements The appointment object shall have a required unique appointment ID string that cannot be longer than 10 characters. The appointment ID shall not be null and shall not be updatable. The appointment object shall have a required appointment Date field. The appointment Date field cannot be in the past. The appointment Date field shall not be null.Note: Use java.util.Date for the appointmentDate field and use before(new Date()) to check if the date is in the past. The appointment object shall have a required description String field that cannot be longer than 50 characters. The description field shall not be null. Appointment Service Requirements The appointment service shall be able to add appointments with a unique appointment ID. The appointment service shall be able to delete appointments per appointment ID.arrow_forward
- Microsoft Visual C# 7th edition. In Chapter 7, you modified the GreenvilleRevenue program to include a number of methods. Now, using your code from Chapter 7 Case Study 1, modify your program so every data entry statement uses a TryParse() method to ensure that each piece of data is the correct type. Any invalid user entries should generate an appropriate message that contains the word Invalid, and the user should be required to reenter the data. Cengage requirement for the shaded part is attached and I don't understand it. I need help with the highlighted part (getContestantData() method) please. Thanks using System; using static System.Console; using System.Globalization; class GreenvilleRevenue { static void Main() { int numLastYear; int numThisYear; double revenue; int fee = 25; const int MAX_CONTESTANTS = 30; string[] names = new string[MAX_CONTESTANTS]; char[] talents = new char[MAX_CONTESTANTS]; char[] talentCodes = { 'S', 'D', 'M', 'O'…arrow_forwardStatic & Not Final Field: Accessed by every object, Changing Non-Static & Final Field: Accessed by object itself, Non-Changing Static & Final: Accessed by every object, Non-Changing Non-Static & Not Final Field: Accessed by object itself, ChangingRead the following situation and decide how the variables should be defined. You have a class named HeartsPlayerA round of Hearts starts with every player having 13 cardsPlayers then choose 3 cards to “trade” with a player (1st you pass left, 2nd you pass right, 3rd you pass across, 4th you keep)Players then strategically play cards in order to have the lowest scoreAt the end of the round, points are cumulatively totaled for each player.If one player’s total is greater than 100, the game ends and the player with the lowest score wins. 1. How should the following data fields be defined (with respect to final and static)?(a) playerPosition (These have values of North, South, East, or West)(b) directionOfPassing(c) totalScore…arrow_forwardRadio station KJAVA wants a class to keep track of recordings it plays. Create a class named Recording that contains fields to hold methods for setting and getting a Recording’s title, artist, and playing time in seconds. Write an application that instantiates five Recording objects and prompts the user for values for the data fields. Then prompt the user to enter which field the Recordings should be sorted by—(S)ong title, (A)rtist, or playing (T)ime. Perform the requested sort procedure, and display the Recording objects. Given classes: public class Recording { privateString song; privateString artist; privateint playTime; publicvoidsetSong(Stringtitle) { } publicvoidsetArtist(Stringname) { } publicvoidsetPlayTime(inttime) { } publicStringgetSong() { } publicStringgetArtist() { } publicintgetPlayTime() { } } import java.util.*; public class RecordingSort { publicstaticvoidmain(String[] args) { // Write your code here } publicstaticvoidsortByArtist(Recording[] array) { //…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY