Java: An Introduction to Problem Solving and Programming (8th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
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
Create an original network topology consisting of at least seven routers and twelve links, assigning arbitrary positive weights to each link. Using this topology, apply Dijkstra's Link-State Algorithm to compute the shortest paths from a source router of your choice to all other routers in the network. Your topology must be entirely your own design and should not resemble any examples from the textbook, lecture slides, or other students' work. Al-generated topologies are not permitted. Create a PowerPoint presentation that follows the format and style of slides 11 to 23 from Lecture Slide Set 06 (LS06). You should copy those slides and make any necessary changes, additions, or deletions to reflect your own topology, shortest-path calculations, and update tables. Do not alter the original slide style, layout, or formatting.
Create an original network topology consisting of at least seven routers and twelve links, assigning arbitrary positive weights to each link. Using this topology, apply Dijkstra's Link-State Algorithm to compute the shortest paths from a source router of your choice to all other routers in the network. Your topology must be entirely your own design and should not resemble any examples from the textbook, lecture slides, or other students' work. Al-generated topologies are not permitted. Create
x3003 x3008 1110 0000 0000 1100 1110 0010 0001 0000 0101 0100 1010 0000 x3004 0010 0100 0001 0011 x3005 0110 0110 0000 0000 X3006 0110 1000 0100 0000 x3007 0001 0110 1100 0100 0111 0110 0000 What does the following LC-3 program do? Trace Step by Step, SHOW ALL YOUR WORK. x3001 x3002 0000 x3009 0001 0000 0010 0001 X300A 0001 0010 0110 0001 x300B 0001 0100 1011 1111 x300C 0000 0011 1111 1000 X300D 1111 0000 0010 0101 x300E 0000 0000 0000 0101 x300F 0000 0000 0000 0100 x3010 0000 0000 0000 0011 x3011 0000 0000 0000 0110 x3012 0000 0000 0000 0010 x3013 x3014 0000 0000 0000 0000 0000 0100 0000 0111 x3015 0000 0000 0000 0110 x3016 0000 0000 0000 1000 x3017 0000 0000 0000 0111 x3018 0000 0000 0000 0101

Chapter 5 Solutions

Java: An Introduction to Problem Solving and Programming (8th 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