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
Question
Book Icon
Chapter 8, Problem 2PP
Program Plan Intro

Displaying right arrow and left arrow

Program Plan:

Filename: Test.java

  • • Include the required header files.
  • • Define the class “Test”.
  • • Define main function.
    • ○ Create an object for scanner.
    • ○ Declare the character variable.
    • ○ The “do-while” condition is used to get the user response to do the operation once again.
      • ■ Create the objects “a1” and “b1” for “LeftArrow” and “RightArrow” classes.
      • ■ Call the method “writeOutput” using both the objects.
      • ■ Create the objects “a2” and “b2” for “LeftArrow” and “RightArrow” classes.
      • ■ Call the method “writeOutput” using both the objects.
      • ■ Create the objects “a3” and “b3” for “LeftArrow” and “RightArrow” classes.
      • ■ Call the method “writeOutput” using both the objects.
      • ■ Change the value of offset from 0 to 1 and call the method “writeOutput” using both the objects.
      • ■ Call the method “setOffset” using both the objects.
      • ■ Change the value of offset from 0 to 2 and call the method “writeOutput” using both the objects.
      • ■ Call the method “setTail” using both the objects.
      • ■ Change the value of offset from 3 to 10 and call the method “writeOutput” using both the objects.
      • ■ Call the method “setBase” using both the objects.
      • ■ Test the write offset values for both arrows by calling “writeOffset” method.
      • ■ Test the return offset for both arrows by calling “getOffset” method.
      • ■ Test the write tail for both arrows by calling “writeTail” method.
      • ■ Test the return tail for both arrows by calling “getTail” method.
      • ■ Test the write base for both arrows by calling “writeBase” method.
      • ■ Test the return tail for both arrows by calling “getBase” method.
      • ■ Reset the values and call “set” method.
      • ■ Call the method “writeOutput” using both the objects.
      • ■ Call the “drawHere” method using both the objects.
      • ■ Reset the values and call “set” method.
      • ■ Call the method “writeOutput” using both the objects.
      • ■ Call the “drawHere” method using both the objects.
      • ■ Reset the values and call “set” method.
      • ■ Call the method “writeOutput” using both the objects.
      • ■ Call the “drawHere” method using both the objects.
      • ■ Finally display the two arrows on the output screen.

Filename: LeftArrow.java

  • • Define the class “LeftArrow” extends from the “ShapeBase” class.
    • ○ Declare the required variables.
    • ○ Define the default constructor.
      • ■ Call the “super” method.
      • ■ Set the values.
    • ○ Define the constructor with the arguments “theTail”, “theBase”.
      • ■ Call the method “super” with an offset value.
      • ■ Set the value.
      • ■ Check the “theBase” value is less than 3.
        • • Assign “base” is equal to 3.
          • ■ Check the “theBase% 2” is equal to 0.
            • • Assign “base” value is equal to “theBase + 1”.
          • ■ Otherwise, assign the “base” is equal to “theBase”.
    • ○ Define another constructor with the arguments “theTail”, “theBase”.
      • ■ Call the method “super”.
      • ■ Set the value.
      • ■ Check the “theBase” value is less than 3.
        • • Assign “base” is equal to 3.
          • ■ Check the “theBase% 2” is equal to 0.
            • • Assign “base” value is equal to “theBase + 1”.
          • ■ Otherwise, assign the “base” is equal to “theBase”.
          • ■ Define another constructor with the parameters “theTail”, “theBase”.
    • ○ Define the “set” method with the arguments “newOffset”, newTail”, and “newBase”.
      • ■ Call the method “super” with an offset value.
      • ■ Set the value.
      • ■ Check the “newBase” value is less than 3.
        • • Assign “base” is equal to 3.
          • ■ Check the “newBase% 2” is equal to 0.
            • • Assign “base” value is equal to “theBase + 1”.
          • ■ Otherwise, assign the “base” is equal to “newBase”.
    • ○ Define the “setTail” method with an argument “newTail”.
      • ■ Set the value.
    • ○ Define the method “setBase” with an argument “newBase”.
      • ■ Check the “newBase” value is less than 3.
        • • Assign “base” is equal to 3.
          • ■ Check the “newBase% 2” is equal to 0.
            • • Assign “base” value is equal to “theBase + 1”.
          • ■ Otherwise, assign the “base” is equal to “newBase”.
    • ○ Define the “writeOutput()” method.
      • ■ Call the “writeOffset()”, “writeTail ()”, and “writeBase()” methods.
    • ○ Define the “writeOffset()” method.
      • ■ Display the offset by calling the “getOffset()” method.
    • ○ Define the “writeTail()” method.
      • ■ Display the offset by calling the “getTail()” method.
    • ○ Define the “writeBase()” method.
      • ■ Display the offset by calling the “getBase()” method.
    • ○ The method “getTail()” returns the “tail” value.
    • ○ The method “getBase()” returns the “base” value.
    • ○ Define the method “drawHere ()”.
      • ■ Call the “drawTop()”, “drawTail()”, and “drawBottom()” methods.
    • ○ Define the “drawTop ()” method.
      • ■ Declare the variable “linecount” and assign the value of “getBase()” value divided by 2.
      • ■ Declare the variable “numberOfSpaces” and calculate it.
      • ■ Call the “skipSpaces()” method with a parameter “numberOfSpaces” value.
      • ■ Display the “*” character.
      • ■ Declare the “count” variable.
      • ■ Declare the “insideWidth” with value 1.
      • ■ The “for” condition is used to display the “*” character in left arrow shape.
        • • Decrement the “numberOfSpaces” value by 2.
        • • Call the “skipSpaces()” method with “numberOfSpaces” value.
        • • Display the “*” character.
        • • Call the “skipSpaces()” method with “insideWidth” value.
        • • Display the “*” character.
        • • Increment the “insideWidth” value by 2.
    • ○ Define the “drawTial()” method.
      • ■ Call the “skipSpaces()” method with “getOffset()” value.
      • ■ Display the “*” character.
      • ■ Declare and calculate the “insideWidth” value.
      • ■ Call the “skipSpaces()” method with “insideWidth” value.
      • ■ Declare the “count” variable.
      • ■ The “for” condition is used to display the “*” character in left arrow shape.
        • • Display the “*” character.
    • ○ Define the “drawBottom()” method.
      • ■ Declare the required variables and calculate them respectively.
      • ■ The “for” condition is used to display the “*” character in left arrow shape.
        • • Call the “skipSpaces()” method with “startOfLine” value.
        • • Display the “*” character.
        • • Call the “skipSpaces()” method with “inideWidth” value.
        • • Display the “*” character.
        • • Increment the “startOfLine” value by 2.
        • • Decrement the “insideWidth” value by 2.
    • ○ Define “skipSpaces()” method.
      • ■ Display the space.

Filename: RightArrow.java

  • • Define the class “RightArrow” extends from the “ShapeBase” class.
    • ○ Declare the required variables.
    • ○ Define the default constructor.
      • ■ Call the “super” method.
      • ■ Set the values.
    • ○ Define the constructor with the arguments “theTail”, “theBase”.
      • ■ Call the method “super” with an offset value.
      • ■ Set the value.
      • ■ Check the “theBase” value is less than 3.
        • • Assign “base” is equal to 3.
          • ■ Check the “theBase% 2” is equal to 0.
            • • Assign “base” value is equal to “theBase + 1”.
          • ■ Otherwise, assign the “base” is equal to “theBase”.
    • ○ Define another constructor with the arguments “theTail”, “theBase”.
      • ■ Call the method “super”.
      • ■ Set the value.
      • ■ Check the “theBase” value is less than 3.
        • • Assign “base” is equal to 3.
          • ■ Check the “theBase% 2” is equal to 0.
            • • Assign “base” value is equal to “theBase + 1”.
          • ■ Otherwise, assign the “base” is equal to “theBase”.
          • ■ Define another constructor with the parameters “theTail”, “theBase”.
    • ○ Define the “set” method with the arguments “newOffset”, newTail”, and “newBase”.
      • ■ Call the method “super” with an offset value.
      • ■ Set the value.
      • ■ Check the “newBase” value is less than 3.
        • • Assign “base” is equal to 3.
          • ■ Check the “newBase% 2” is equal to 0.
            • • Assign “base” value is equal to “theBase + 1”.
          • ■ Otherwise, assign the “base” is equal to “newBase”.
    • ○ Define the “setTail” method with an argument “newTail”.
      • ■ Set the value.
    • ○ Define the method “setBase” with an argument “newBase”.
      • ■ Check the “newBase” value is less than 3.
        • • Assign “base” is equal to 3.
          • ■ Check the “newBase% 2” is equal to 0.
            • • Assign “base” value is equal to “theBase + 1”.
          • ■ Otherwise, assign the “base” is equal to “newBase”.
    • ○ Define the “writeOutput()” method.
      • ■ Call the “writeOffset()”, “writeTail ()”, and “writeBase()” methods.
    • ○ Define the “writeOffset()” method.
      • ■ Display the offset by calling the “getOffset()” method.
    • ○ Define the “writeTail()” method.
      • ■ Display the offset by calling the “getTail()” method.
    • ○ Define the “writeBase()” method.
      • ■ Display the offset by calling the “getBase()” method.
    • ○ The method “getTail()” returns the “tail” value.
    • ○ The method “getBase()” returns the “base” value.
    • ○ Define the method “drawHere ()”.
      • ■ Call the “drawTop()”, “drawTail()”, and “drawBottom()” methods.
    • ○ Define the “drawTop ()” method.
      • ■ Declare the variable “startOfLine” and assign the value of “getOffset()” plus “getTail()”.
      • ■ Call the “skipSpaces()” method with a parameter “startOfLine” value.
      • ■ Display the “*” character.
      • ■ Declare the “linecount” and calculate it.
      • ■ Declare the “count” variable.
      • ■ Declare the “insideWidth” with value 1.
      • ■ The “for” condition is used to display the “*” character in right arrow shape.
        • • Call the “skipSpaces()” method with “startOfLine” value.
        • • Display the “*” character.
        • • Call the “skipSpaces()” method with “insideWidth” value.
        • • Display the “*” character.
        • • Increment the “insideWidth” value by 2.
    • ○ Define the “drawTial()” method.
      • ■ Call the “skipSpaces()” method with “getOffset()” value.
      • ■ Declare the “count” variable.
      • ■ The “for” condition is used to display the “*” character in right arrow shape.
        • • Display the “*” character.
        • • Calculate the “insideWidth”.
        • • Call the “skipSpaces()” method with “insideWidth” value.
        • • Display the “*” character.
    • ○ Define the “drawBottom()” method.
      • ■ Declare the required variables and calculate them respectively.
      • ■ The “for” condition is used to display the “*” character in right arrow shape.
        • • Call the “skipSpaces()” method with “startOfLine” value.
        • • Display the “*” character.
        • • Call the “skipSpaces()” method with “inideWidth” value.
        • • Display the “*” character.
        • • Decrement the “insideWidth” value by 2.
        • • Call the “skipSpaces()” method with “startOfLine” value.
        • • Display the “*” character.
    • ○ Define “skipSpaces()” method.
      • ■ Display the space.

Filename: ShapeInterface.java

Define the interface “SpaceInterface”.

  • • Declare the “setOffset()” method.
  • • Declare the “getOffset()” method.
  • • Declare the “drawAt()” method.
  • • Declare the “drawHere()” method.

Blurred answer
Students have asked these similar questions
Create a class BeautyProduct with name, color, brand. Provide Constructors, getters, setters and also write toString method. Now create a class Lipstick which extends the class BeautyProduct as Lipstick is-a Beauty Product it has totalVolume, remainingVolume, price, texture (gloss, matt) as private data members. Provide Constructors, getters, setters and an apply() method whenever this method is called a beauty item is applied and its volume decreases by 10.This should also check that volume must not be zero if it then u have to throw exception. Also write toString method which prints all details like name, color, brand, price, texture and volume. Create another class foundation having totalVolume, remainingVolume, price, texture (liquid, cake) and lastingTime (number of hours foundation remain intact on face and does not crease) as private data members. This also extends the base class i.e. BeautyProduct. Provide Constructors, getters, setters and an apply() method whenever this…
Language is Java Write a Clothing class with the following attributes: color (e.g., "blue", "green", "orange") displayName (e.g., "Doctor Who hoodie", "slacks") price (e.g., 19.99, 7) Include only one constructor. It should have parameters for each of the attributes and set their values. Additionally, include getters and setters for each of the attributes. Add a driver, name it Purchases, and create 2 Clothing objects. Finally, print out some information about both objects (i.e., print the information from some or all of the getters). For example, if you created a Clothing object whose color was blue, whose display name was work trousers, for a price of 27.99, you could use the getters to print something like this:These work trousers are blue and cost $27.99.Don't hardcode the print statement for full credit, you must use the getters
In the board game Scrabble, each tile contains a letter, which is used to spell words in rows and columns, and a score, which is used to determine the value of words. The point of this exercise is to practice the mechanical part of creating a new class definition: Write a definition for a class named Tile that represents Scrabble tiles. The instance variables should be a character named "letter" and an integer named "value". Write a constructor that takes parameters named letter and value, and initializes the instance variables. Create getters for both of the attributes. (No setters, so that a Tile is immutable.) Implement the .toString() and .equals methods for a Tile. Your completed Tile class should work with this Main program (Links to an external site.) so that it produces sample output like shown at the end of the program. You can Fork the program to make your own version in Replit, where you can add your Tile.java, or you can copy the program to your own Java development…

Chapter 8 Solutions

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

Ch. 8.2 - Rewrite the definition of the method reset for the...Ch. 8.2 - Can an object be referenced by variables of...Ch. 8.2 - What is the type or types of the variable(s) that...Ch. 8.2 - Prob. 14STQCh. 8.2 - Prob. 15STQCh. 8.2 - Consider the code below, which was discussed in...Ch. 8.2 - Prob. 17STQCh. 8.3 - Prob. 18STQCh. 8.3 - Prob. 19STQCh. 8.3 - Is overloading a method name an example of...Ch. 8.3 - In the following code, will the two invocations of...Ch. 8.3 - In the following code, which definition of...Ch. 8.4 - Prob. 23STQCh. 8.4 - Prob. 24STQCh. 8.4 - Prob. 25STQCh. 8.4 - Prob. 26STQCh. 8.4 - Prob. 27STQCh. 8.4 - Prob. 28STQCh. 8.4 - Are the two definitions of the constructors given...Ch. 8.4 - The private method skipSpaces appears in the...Ch. 8.4 - Describe the implementation of the method drawHere...Ch. 8.4 - Is the following valid if ShapeBaSe is defined as...Ch. 8.4 - Prob. 33STQCh. 8.5 - Prob. 34STQCh. 8.5 - What is an advantage of having the main...Ch. 8.5 - What Java construct allows us to define and...Ch. 8 - Consider a program that will keep track of the...Ch. 8 - Implement your base class for the hierarchy from...Ch. 8 - Draw a hierarchy for the components you might find...Ch. 8 - Suppose we want to implement a drawing program...Ch. 8 - Create a class Square derived from DrawableShape,...Ch. 8 - Create a class SchoolKid that is the base class...Ch. 8 - Derive a class ExaggeratingKid from SchoolKid, as...Ch. 8 - Create an abstract class PayCalculator that has an...Ch. 8 - Derive a class RegularPay from PayCalculator, as...Ch. 8 - Create an abstract class DiscountPolicy. It should...Ch. 8 - Derive a class BulkDiscount from DiscountPolicy,...Ch. 8 - Derive a class BuyNItemsGetOneFree from...Ch. 8 - Prob. 13ECh. 8 - Prob. 14ECh. 8 - Create an interface MessageEncoder that has a...Ch. 8 - Create a class SubstitutionCipher that implements...Ch. 8 - Create a class ShuffleCipher that implements the...Ch. 8 - Define a class named Employee whose objects are...Ch. 8 - Define a class named Doctor whose objects are...Ch. 8 - Create a base class called Vehicle that has the...Ch. 8 - Create a new class called Dog that is derived from...Ch. 8 - Define a class called Diamond that is derived from...Ch. 8 - Prob. 2PPCh. 8 - Prob. 3PPCh. 8 - Prob. 4PPCh. 8 - Create an interface MessageDecoder that has a...Ch. 8 - For this Programming Project, start with...Ch. 8 - Modify the Student class in Listing 8.2 so that it...Ch. 8 - Create a JavaFX application that uses a TextField...Ch. 8 - Prob. 10PP
Knowledge Booster
Background pattern image
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
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT