Java: An Introduction to Problem Solving and Programming plus MyProgrammingLab with Pearson eText -- Access Card Package (7th Edition)
7th Edition
ISBN: 9780133862119
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
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”.
- • Assign “base” is equal to 3.
- ○ 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”.
- • Assign “base” is equal to 3.
- ○ 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”.
- • Assign “base” is equal to 3.
- ○ 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”.
- • Assign “base” is equal to 3.
- ■ Check the “newBase” value is less than 3.
- ○ 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”.
- • Assign “base” is equal to 3.
- ○ 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”.
- • Assign “base” is equal to 3.
- ○ 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”.
- • Assign “base” is equal to 3.
- ○ 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”.
- • Assign “base” is equal to 3.
- ■ Check the “newBase” value is less than 3.
- ○ 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.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a program that simulates a Magic 8 Ball, which is a fortune-telling toy that displays a random response to a yes or no question. In the student sample programs for this book, you will find a text file named 8_ball_responses.txt. The file contains 12 responses, such as “I don’t think so”, “Yes, of course!”, “I’m not sure”, and so forth. The program should read the responses from the file into a list. It should prompt the user to ask a question, then display one of the responses, randomly selected from the list. The program should repeat until the user is ready to quit.
Contents of 8_ball_responses.txt:
Yes, of course! Without a doubt, yes. You can count on it. For sure! Ask me later. I'm not sure. I can't tell you right now. I'll tell you after my nap. No way! I don't think so. Without a doubt, no. The answer is clearly NO.
(You can access the Computer Science Portal at www.pearsonhighered.com/gaddis.)
Start with the initial angles within the integration and just integrate them without mapping them to specific quadrants. Use python and radians
How does encryption prevent a hacker from getting your data
Chapter 8 Solutions
Java: An Introduction to Problem Solving and Programming plus MyProgrammingLab with Pearson eText -- Access Card Package (7th Edition)
Ch. 8.1 - Prob. 1STQCh. 8.1 - Suppose the class SportsCar is a derived class of...Ch. 8.1 - Suppose the class SportsCar is a derived class of...Ch. 8.1 - Can a derived class directly access by name a...Ch. 8.1 - Can a derived class directly invoke a private...Ch. 8.1 - Prob. 6STQCh. 8.1 - Suppose s is an object of the class Student. Base...Ch. 8.2 - Give a complete definition of a class called...Ch. 8.2 - Add a constructor to the class Student that sets...Ch. 8.2 - Rewrite the definition of the method writeoutput...
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 the difference between what you can do in...Ch. 8.5 - Prob. 36STQCh. 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 - Prob. 8PPCh. 8 - Prob. 9PPCh. 8 - Prob. 10PP
Knowledge Booster
Similar questions
- what type of internet connection should be avoided on mobile devices?arrow_forwardI need help creating the network diagram and then revising it for the modified activity times.arrow_forwardActivity No. Activity Time (weeks) Immediate Predecessors 1 Requirements collection 3 2 Requirements structuring 4 1 3 Process analysis 3 2 4 Data analysis 3 2 5 Logical design 50 3,4 6 Physical design 5 5 7 Implementation 6 6 c. Using the information from part b, prepare a network diagram. Identify the critical path.arrow_forward
- Given the following Extended-BNF grammar of the basic mathematical expressions: Show the derivation steps for the expression: ( 2 + 3 ) * 6 – 20 / ( 3 + 1 ) Draw the parsing tree of this expression. SEE IMAGEarrow_forwardWhentheuserenters!!,themostrecentcommandinthehistoryisexecuted.In the example above, if the user entered the command: Osh> !! The ‘ls -l’ command should be executed and echoed on user’s screen. The command should also be placed in the history buffer as the next command. Whentheuserentersasingle!followedbyanintegerN,theNthcommandin the history is executed. In the example above, if the user entered the command: Osh> ! 3 The ‘ps’ command should be executed and echoed on the user’s screen. The command should also be placed in the history buffer as the next command. Error handling: The program should also manage basic error handling. For example, if there are no commands in the history, entering !! should result in a message “No commands in history.” Also, if there is no command corresponding to the number entered with the single !, the program should output "No such command in history."arrow_forwardActivity No. Activity Time (weeks) Immediate Predecessors 1 Requirements collection 3 2 Requirements structuring 4 1 3 Process analysis 3 2 4 Data analysis 3 2 5 Logical design 50 3,4 6 Physical design 5 5 7 Implementation 6 6 c. Using the information from part b, prepare a network diagram. Identify the critical path.arrow_forward
- 2. UNIX Shell and History Feature [20 points] This question consists of designing a C program to serve as a shell interface that accepts user commands and then executes each command in a separate process. A shell interface gives the user a prompt, after which the next command is entered. The example below illustrates the prompt osh> and the user's next command: cat prog.c. The UNIX/Linux cat command displays the contents of the file prog.c on the terminal using the UNIX/Linux cat command and your program needs to do the same. osh> cat prog.c The above can be achieved by running your shell interface as a parent process. Every time a command is entered, you create a child process by using fork(), which then executes the user's command using one of the system calls in the exec() family (as described in Chapter 3). A C program that provides the general operations of a command-line shell can be seen below. #include #include #define MAX LINE 80 /* The maximum length command */ { int…arrow_forwardQuestion#2: Design and implement a Java program using Abstract Factory and Singleton design patterns. The program displays date and time in one of the following two formats: Format 1: Date: MM/DD/YYYY Time: HH:MM:SS Format 2: Date: DD-MM-YYYY Time: SS,MM,HH The following is how the program works. In the beginning, the program asks the user what display format that she wants. Then the program continuously asks the user to give one of the following commands, and performs the corresponding task. Note that the program gets the current date and time from the system clock (use the appropriate Java date and time operations for this). 'd' display current date 't': display current time 'q': quit the program. • In the program, there should be 2 product hierarchies: "DateObject” and “TimeObject”. Each hierarchy should have format and format2 described above. • Implement the factories as singletons. • Run your code and attach screenshots of the results. • Draw a UML class diagram for the program.arrow_forward#include <linux/module.h> #include <linux/kernel.h> // part 2 #include <linux/sched.h> // part 2 extra #include <linux/hash.h> #include <linux/gcd.h> #include <asm/param.h> #include <linux/jiffies.h> void print_init_PCB(void) { printk(KERN_INFO "init_task pid:%d\n", init_task.pid); printk(KERN_INFO "init_task state:%lu\n", init_task.state); printk(KERN_INFO "init_task flags:%d\n", init_task.flags); printk(KERN_INFO "init_task runtime priority:%d\n", init_task.rt_priority); printk(KERN_INFO "init_task process policy:%d\n", init_task.policy); printk(KERN_INFO "init_task task group id:%d\n", init_task.tgid); } /* This function is called when the module is loaded. */ int simple_init(void) { printk(KERN_INFO "Loading Module\n"); print_init_PCB(); printk(KERN_INFO "Golden Ration Prime = %lu\n", GOLDEN_RATIO_PRIME); printk(KERN_INFO "HZ = %d\n", HZ); printk(KERN_INFO "enter jiffies = %lu\n", jiffies); return 0; } /* This function is called when the…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT