Java Programming
8th Edition
ISBN: 9781305981829
Author: Joyce Farrell
Publisher: Cengage Limited
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
Start with the initial angles within the integration and just integrate them without mapping them to specific quadrants. Use python and radians
How does encryption prevent a hacker from getting your data
what is one way to secure a phone
Chapter 10 Solutions
Java Programming
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
- I need help creating the network diagram and then revising it for the modified activity times.arrow_forwardActivity No. Activity Time (weeks) Immediate Predecessors 1 Requirements collection 3 2 Requirements structuring 4 1 3 Process analysis 3 2 4 Data analysis 3 2 5 Logical design 50 3,4 6 Physical design 5 5 7 Implementation 6 6 c. Using the information from part b, prepare a network diagram. Identify the critical path.arrow_forwardGiven the following Extended-BNF grammar of the basic mathematical expressions: Show the derivation steps for the expression: ( 2 + 3 ) * 6 – 20 / ( 3 + 1 ) Draw the parsing tree of this expression. SEE IMAGEarrow_forward
- Whentheuserenters!!,themostrecentcommandinthehistoryisexecuted.In the example above, if the user entered the command: Osh> !! The ‘ls -l’ command should be executed and echoed on user’s screen. The command should also be placed in the history buffer as the next command. Whentheuserentersasingle!followedbyanintegerN,theNthcommandin the history is executed. In the example above, if the user entered the command: Osh> ! 3 The ‘ps’ command should be executed and echoed on the user’s screen. The command should also be placed in the history buffer as the next command. Error handling: The program should also manage basic error handling. For example, if there are no commands in the history, entering !! should result in a message “No commands in history.” Also, if there is no command corresponding to the number entered with the single !, the program should output "No such command in history."arrow_forwardActivity No. Activity Time (weeks) Immediate Predecessors 1 Requirements collection 3 2 Requirements structuring 4 1 3 Process analysis 3 2 4 Data analysis 3 2 5 Logical design 50 3,4 6 Physical design 5 5 7 Implementation 6 6 c. Using the information from part b, prepare a network diagram. Identify the critical path.arrow_forward2. UNIX Shell and History Feature [20 points] This question consists of designing a C program to serve as a shell interface that accepts user commands and then executes each command in a separate process. A shell interface gives the user a prompt, after which the next command is entered. The example below illustrates the prompt osh> and the user's next command: cat prog.c. The UNIX/Linux cat command displays the contents of the file prog.c on the terminal using the UNIX/Linux cat command and your program needs to do the same. osh> cat prog.c The above can be achieved by running your shell interface as a parent process. Every time a command is entered, you create a child process by using fork(), which then executes the user's command using one of the system calls in the exec() family (as described in Chapter 3). A C program that provides the general operations of a command-line shell can be seen below. #include #include #define MAX LINE 80 /* The maximum length command */ { int…arrow_forward
- Question#2: Design and implement a Java program using Abstract Factory and Singleton design patterns. The program displays date and time in one of the following two formats: Format 1: Date: MM/DD/YYYY Time: HH:MM:SS Format 2: Date: DD-MM-YYYY Time: SS,MM,HH The following is how the program works. In the beginning, the program asks the user what display format that she wants. Then the program continuously asks the user to give one of the following commands, and performs the corresponding task. Note that the program gets the current date and time from the system clock (use the appropriate Java date and time operations for this). 'd' display current date 't': display current time 'q': quit the program. • In the program, there should be 2 product hierarchies: "DateObject” and “TimeObject”. Each hierarchy should have format and format2 described above. • Implement the factories as singletons. • Run your code and attach screenshots of the results. • Draw a UML class diagram for the program.arrow_forward#include <linux/module.h> #include <linux/kernel.h> // part 2 #include <linux/sched.h> // part 2 extra #include <linux/hash.h> #include <linux/gcd.h> #include <asm/param.h> #include <linux/jiffies.h> void print_init_PCB(void) { printk(KERN_INFO "init_task pid:%d\n", init_task.pid); printk(KERN_INFO "init_task state:%lu\n", init_task.state); printk(KERN_INFO "init_task flags:%d\n", init_task.flags); printk(KERN_INFO "init_task runtime priority:%d\n", init_task.rt_priority); printk(KERN_INFO "init_task process policy:%d\n", init_task.policy); printk(KERN_INFO "init_task task group id:%d\n", init_task.tgid); } /* This function is called when the module is loaded. */ int simple_init(void) { printk(KERN_INFO "Loading Module\n"); print_init_PCB(); printk(KERN_INFO "Golden Ration Prime = %lu\n", GOLDEN_RATIO_PRIME); printk(KERN_INFO "HZ = %d\n", HZ); printk(KERN_INFO "enter jiffies = %lu\n", jiffies); return 0; } /* This function is called when the…arrow_forwardList at least five Operating Systems you know. What is the difference between the kernel mode and the user mode for the Linux? What is the system-call? Give an example of API in OS that use the system-call. What is cache? Why the CPU has cache? What is the difference between the Static Linking and Dynamic Linking when compiling the code.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:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
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
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
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