EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
bartleby

Concept explainers

bartleby

Videos

Question
Book Icon
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
      • 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 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.

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
    • 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
    • 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
    • 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
    • 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
      • 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 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.

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
      • 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 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.

Blurred answer
Students have asked these similar questions
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.
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.
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
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