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
You are tasked with developing a portable system that can be worn to collect health and fitness data. The challenge is to integrate all functions into the smaller form of an ear clip. The device should include heart rate, movement and temperature sensor and wireless communication with a mobile app. Draw a diagram- hardware architecture of the system- including the selection of suitable sensors, communication modules, and an energy-efficient microcontroller. (visualize the components and their connections)
Draw out an example of 3 systems using Lamport’s logical clock and explain the steps in words.
"Systems have become very powerful and sophisticated, providing quality information fordecisions that enable the firm to coordinate both internally and externally."With reference to the above statement compare the operations of any three data gatheringsystems today’s organisations use to aid decision making.

Chapter 5 Solutions

Java: An Introduction to Problem Solving and Programming (8th Edition)

Chapter 5.1, Problem 11STQ Chapter 5.1, Problem 12STQ Chapter 5.2, Problem 13STQ Chapter 5.2, Problem 14STQ Chapter 5.2, Problem 15STQ Chapter 5.2, Problem 16STQ Chapter 5.2, Problem 17STQ Chapter 5.2, Problem 18STQ Chapter 5.2, Problem 19STQ Chapter 5.2, Problem 20STQ Chapter 5.2, Problem 21STQ Chapter 5.2, Problem 22STQ Chapter 5.2, Problem 23STQ Chapter 5.3, Problem 24STQ Chapter 5.3, Problem 25STQ Chapter 5.3, Problem 26STQ Chapter 5.3, Problem 27STQ Chapter 5.3, Problem 28STQ Chapter 5.3, Problem 29STQ Chapter 5.3, Problem 30STQ Chapter 5.3, Problem 31STQ Chapter 5.3, Problem 32STQ Chapter 5.4, Problem 33STQ Chapter 5, Problem 1E Chapter 5, Problem 2E Chapter 5, Problem 3E Chapter 5, Problem 4E Chapter 5, Problem 5E Chapter 5, Problem 6E Chapter 5, Problem 7E Chapter 5, Problem 8E Chapter 5, Problem 9E Chapter 5, Problem 10E Chapter 5, Problem 1P Chapter 5, Problem 2P Chapter 5, Problem 3P Chapter 5, Problem 4P Chapter 5, Problem 5P Chapter 5, Problem 1PP Chapter 5, Problem 2PP Chapter 5, Problem 3PP Chapter 5, Problem 4PP Chapter 5, Problem 5PP Chapter 5, Problem 6PP Chapter 5, Problem 7PP Chapter 5, Problem 8PP Chapter 5, Problem 9PP Chapter 5, Problem 10PP Chapter 5, Problem 11PP Chapter 5, Problem 12PP

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
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