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 7, Problem 2GZ
Program Plan Intro

Enhancement of Rock Paper Scissors game

Program plan:

  • Import necessary packages.
  • Create a class “RockPaperScissors2”,
    • Define the “main()” method.
      • Declare a variable.
      • Declare and initialize variables.
      • Execute the following,
        • Create “Scanner” object.
        • Generate Random number.
        • Prompt the user to enter Rock or Paper or Scissor.
        • Increment the number of games.
        • Get the user input.
        • Take the first two characters of user input.
        • Convert it into upper case.
        • Execute switch statement,
        • If the random number is “3”.
          • Print a message.
          • Check if first two characters of user input is "PA", print a message, and increment the number of loses.
          • Else,
            • Check if first two characters of user input is "SC", print a message, and increment the number of ties.
          • Else,
            • Check if first two characters of user input is "RO", print a message, and increment the number of wins.
        • If the random number is “1”,
          • Print a message.
          • Check if first two characters of user input is "SC", print a message, and increment the number of loses.
          • Else,
            • Check if first two characters of user input is "RO", print a message, and increment the number of ties.
          • Else,
            • Check if first two characters of user input is "PA", print a message, and increment the number of wins.
        • If the random number is “2”,
          • Print a message.
          • Check if first two characters of user input is "SC", print a message, and increment the number of wins.
          • Else,
            • Check if first two characters of user input is "RO", print a message, and increment the number of loses.
          • Else,
            • Check if first two characters of user input is "PA", print a message, and increment the number of ties.
        • For a default case, print a message as “Invalid input.”.
      • Ask the user if they want to repeat or not,
      • Get the opinion.
    • Check the condition in exit “while” loop.
      • Print total number games.
      • Print total number wins.
      • Print total number loses.
      • Print total number ties.

Blurred answer
Students have asked these similar questions
In physics, an object that is in motion is said to have kinetic energy. The following formula can be used to determine a moving object’s kinetic energy:KE = 1/2 mv2In the formula KE is the kinetic energy, m is the object’s mass in kilograms, and v is the object’s velocity in meters per second. Create an application that allows the user to enter an object’s mass and velocity and then displays the object’s kinetic energy. The application should have a method named KineticEnergy that accepts an object’s mass (in kilograms) and velocity (in meters per second) as arguments. The method should return the amount of kinetic energy that the object has.
JAVA Guess-the-Number Game Write an application that plays “guess the number” as follows: Your application chooses the number to be guessed by selecting an integer at random in the range 1–1000. The application then displays  the following in a label: I have a number between 1 and 1000. Can you guess my number? Please enter your first guess. A JTextField should be used to input the guess. }  As each guess is input, the background color should change to either red or blue. Red indicates that the user is getting “warmer,” and blue, “colder.” A JLabel should display either "Too High" or "Too Low" to help the user zero in. When the user gets the correct answer, "Correct!" should be displayed, and the JTextField used for input should be changed to be uneditable. A JButton should be provided to allow the user to play the game again. When the JButton is clicked, a new random number should be generated and the input JTextField changed to be editable.
Carpet Calculator The Westfield Carpet Company has asked you to write an application that calculates the price of carpeting for rectangular rooms. To calculate the price, you multiply the area of the floor (width times length) by the price per square foot of carpet. For example, the area of floor that is 12 feet long and 10 feet wide is 120 square feet. To cover that floor with carpet that costs $8 per square foot would cost $960. First, you should create a class named RoomDimension that has two fields: one for the length of the room and one for the width. The RoomDimension class should have a method that returns the area of the room. (The area of the room is the room’s length multiplied by the room’s width.) Next you should create a RoomCarpet class that has a RoomDimension object as a field. It should also have a field for the cost of the carpet per square foot. The RoomCarpet class should have a method that returns the total cost of the carpet. Figure 8-20 is a UML…
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
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Expressions in C++ | C++ tutorial for beginners; Author: Tutorial Mart;https://www.youtube.com/watch?v=XHbsZGpmRc8;License: Standard YouTube License, CC-BY
expression in python # python expressions; Author: Abhishek Tripathi;https://www.youtube.com/watch?v=Cc-kJGRjH6k;License: Standard Youtube License