bartleby

Concept explainers

bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 5, Problem 7PP

Explanation of Solution

a.

Method heading for each method:

  • The method heading is “public int setOnePoint()” that takes no parameters and return the value “1”.
  • The method heading is “public int setTwoPoint()” that takes no parameters and return the value “2”.
  • The method heading is “public int setThreePoint()” that takes no parameters and return the value “3”.
  • The method heading is “public void setStatus(String newname)” that takes a parameters of string type and set the status of the game.
  • The method heading is “public String getStatus()” that takes no parameter and returns the status of game...

Explanation of Solution

b.

Preconditions and postconditions of each method:

  • Precondition and postcondition of “public int setOnePoint()” method.
    • Precondition: None.
    • Postcondition: This method returns the value “1”.
  • Precondition and postcondition of “public int setTwoPoint()” method.
    • Precondition: None.
    • Postcondition: This method returns the value “2”.
  • Precondition and postcondition of “public int setThreePoint()” method.
    • Precondition: None.
    • Postcondition: This method returns the value “3”.
  • Precondition and postcondition of “public void setStatus(String newname)” method.
    • Precondition: None.
    • Postcondition: This method sets the status of game.
  • Precondition and postcondition of “public String getStatus()” method.
    • Precondition: None.
    • Postcondition: This method returns the status of game.
  • Precondition and postcondition of “public void setFTScore(int score)” method...

Explanation of Solution

c.

Test class for some Java statement:

//Define the BasketBallTest class

public class BasketBallTest

{

    //Define the main() method

    public static void main(String[] args)

    {

        //Create an object for BasketBall class

        BasketBall BB = new BasketBall();

/*Call readInput() method to read the input from user...

Explanation of Solution

d.

Implementation of class:

BasketBall.java:

//Import the java packages

import java.util.Scanner;

import java.lang.String;

//Define the class

public class BasketBall

{

    //Create an object for Scanner class

    Scanner input = new Scanner(System.in);

    //Declare the required variables

    private String firstTeamName;

    private String secondTeamName;

    private int firstTeamScore = 0;

    private int secondTeamScore = 0;

    private String status;

    private int score;

    private String Tname;

    private int TScore = 0;

    //Define the setStatus() method

    public void setStatus(String newname)

    {

        //Set the status

        status = newname;

    }

    //Define the getStatus() method

    public String getStatus()

    {

        //Return the status

        return status;

    }

    //Define the setFTScore() method

    public void setFTScore(int score)

    {

        //Calculate the first team score

        firstTeamScore = firstTeamScore + score;

    }

    //Define the setSTScore() method

    public void setSTScore(int score)

    {

        //Calculate the second team score

        secondTeamScore = secondTeamScore + score;

    }

    //Define the getFTScore() method

    public int getFTScore()

>&#x...

Explanation of Solution

e.

List of extra methods and attributes needed for this implementation:

There is no extra attributes are needed for this implementation.

The extra methods that were used apart from the mentioned methods are,

  • public void setFTName() method:
    • This method is used to initialize the first team name.
  • public void setSTName() method:
    • This method is used to initialize the second team name...

Explanation of Solution

f.

Implementation of class:

BasketBall.java:

//Import the java packages

import java.util.Scanner;

import java.lang.String;

//Define the class

public class BasketBall

{

    //Create an object for Scanner class

    Scanner input = new Scanner(System.in);

    //Declare the required variables

    private String firstTeamName;

    private String secondTeamName;

    private int firstTeamScore = 0;

    private int secondTeamScore = 0;

    private String status;

    private int score;

    private String Tname;

    private int TScore = 0;

    //Define the setFTName() method

    public void setFTName(String newname)

    {

        //Set the first team name

        firstTeamName = newname;

    }

    //Define the setSTName() method

    public void setSTName(String newname)

    {

        //Set the second team name

        secondTeamName = newname;

    }

    //Define the getFTName() method

    public String getFTName()

    {

        //Return the first team name

        return firstTeamName;

    }

    //Define the getSTName() method

    public String getSTName()

    {

        //Return the second team name

        return secondTeamName;

    }

    //Define the setStatus() method

    public void setStatus(String newname)

    {

        //Set the status

        status = newname;

    }

    //Define the getStatus() method

    public String getStatus()

    {

        //Return the status

        return status;

    }

    //Define the setFTScore() method

    public void setFTScore(int score)

    {

        //Calculate the first team score

        firstTeamScore = firstTeamScore + score;

    }

    //Define the setSTScore() method

    public void setSTScore(int score)

    {

        //Calculate the second team score

        secondTeamScore = secondTeamScore + score;

    }

    //Define the getFTScore() method

    public int getFTScore()

    {

        //Return the first team score

        return firstTeamScore;

    }

    //Define the getSTScore() method

    public int getSTScore()

    {

        //Return the second team score

        return secondTeamScore;

    }

    //Define the setOnePoint() method

    public int setOnePoint()

    {

        //Return the value "1"

        return 1;

    }

    //Define the setTwoPoint() method

    public int setTwoPoint()

    {

        //Return the value "2"

        return 2;

    }

    //Define the setThreePoint() method

    public int setThreePoint()

    {

        //Return the value "3"

        return 3;

    }

    //Define the readInput() method

    public void readInput()

    {

        //Read the first and second team names from user

        System.out.println("Enter the first team name: ");

        firstTeamName = input.nextLine();

System.out.println("Enter the Second team name: ");

        secondTeamName = input.nextLine();

    }

    //Define the Game() method

    public void Game()

    {

        //Display the header message

        System.out.println("Game started");

        //Read the input to continue the game

System.out.println("Enter 1 to continue the game or 0 to end the game");

        int s = input.nextInt();

        //Loop executes until the "true"

        while (true)

        {

            //Check whether the input is equal to "1"

            if (s == 1)

            {

/*Call the setStatus() method to set the status. */

                setStatus("Progress");

/*Read the input name and score from user. */

System.out.println("Enter the score for example: a 2 : ");

                Tname = input.next();

                TScore = input...

Blurred answer
Students have asked these similar questions
Need Java method please. Thank you.
Need Java method please. Thank you.
3. Write two nested loops to generate the following output. (Note: There is one space between each number, and any extra line shown is intentional.) 12 10 8 6 18 15 12 24 20 30 2 3 3 6 48 12 5 10 15 20 6 12 18 24 30

Chapter 5 Solutions

Java: An Introduction to Problem Solving and Programming plus MyProgrammingLab with Pearson eText -- Access Card Package (7th Edition)

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
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
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
Text book image
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:9780357392676
Author:FREUND, Steven
Publisher:CENGAGE L
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
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