Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 7, Problem 8PP
Program Plan Intro
Shoulder surfing
Program Plan:
- Import required package.
- Define “AuthenticateTest” class.
- Define main function.
- Initializes actual PIN.
- Create an array “randomDigits” for randomly generated digits.
- Create an array “userEnteredDigits” for digits entered by the user.
- Generate random numbers from “1” to “3” for each digit using for loop.
- Display the sequence of PIN and NUM to screen.
- Display “10” digits random numbers for “NUM”.
- Create object for scanner class.
- Display user prompt statement.
- Read the five digits PIN number from user.
- Extract the digits from the code and store in the “userEnteredDigits” array.
- Convert char to corresponding digit.
- Check whether the user entered password is equal to random PIN number of actual PIN numbers by calling the method “checkValidPassword()”.
- If it is match, then display the message “Your password matches correctly!”.
- Otherwise, display the message “Invalid password.”.
- Define the boolean method “checkValidPassword()” with three arguments
- Check PIN numbers one by one using “for” loop. If the user entered PIN is not equal to actual PIN, then returns “false”.
- Define main function.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
attached below
Kingdom of Trolls is celebrating their Kingdom Day and one of the activities that is taking place is a game
where a player rolls a magic ball down the hill on a path with spikes. As the ball rolls down, it strikes a spike
and bursts open to release a number of smaller balls (in our simulated game, the number of smaller balls is a
randomly generated integer between 2 and 6, inclusive). As the smaller balls further roll down, when one
strikes a spike, that ball and all its sibling balls burst and each generates another set of smaller balls (using the
same random number already generated for the first roll). The balls keep rolling downhill and striking spikes
and bursting into smaller balls until a golden ball is released by one of the bursts. At this time, the game is
over and the player is told how many balls were generated during the last burst (including the golden ball).
The game is played by two players at a time and the player who had the lowest number of balls generated on
the…
Substitution ciphers are encryption/decryption algorithms that replace one letter or number with another. The first attested use of a substitution cipher in military affairs was by Julius Caesar, described by him in Gallic Wars (cf. Kahn pp83-84). In caesar cipher , you replace each letter by 3rd letter on. If it is out of bound (later than Z), then round to the head (letter A) and continue the shift. For example:meet me after the toga party
PHHW PH DIWHU WKH WRJD SDUWB
Please write a program in Java to implement the Caesar Cipher:
a. Implement the encryption algorithm. Ask the user to input one all lower case normal sentence (called plaintext) using the nextLine method, and then output the encrypted text (called ciphertext).
b. Implement the decryption algorithm. Ask the user to input one encrypted sentence (i.e. ciphertext) using the nextLine method, and then output the decrypted text (i.e. plaintext).
Chapter 7 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - Consider the following array: int [] a = new...Ch. 7.1 - What is wrong with the following code to...Ch. 7.1 - Write a complete Java program that reads 20 values...Ch. 7.2 - Write some Java code that will declare an array...Ch. 7.2 - Rewrite the method displayResults of the program...Ch. 7.2 - What output will be produced by the following...Ch. 7.2 - Give the definition of a static method called...
Ch. 7.2 - Give the definition of a static method called...Ch. 7.2 - Prob. 12STQCh. 7.2 - The following method compiles and executes but...Ch. 7.2 - Suppose that we add the following method to the...Ch. 7.3 - Prob. 15STQCh. 7.3 - Replace the last loop in Listing 7.8 with a loop...Ch. 7.3 - Suppose a is an array of values of type double....Ch. 7.3 - Suppose a is an array of values of type double...Ch. 7.3 - Prob. 19STQCh. 7.3 - Consider the partially filled array a from...Ch. 7.3 - Repeat the previous question, but this time assume...Ch. 7.3 - Write an accessor method getEntryArray for the...Ch. 7.4 - Prob. 23STQCh. 7.4 - Write the invocation of the method selectionSort...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - Consider an array b of int values in which a value...Ch. 7.5 - What output is produced by the following code?...Ch. 7.5 - Revise the method showTable in Listing 7.13 so...Ch. 7.5 - Write code that will fill the following array a...Ch. 7.5 - Write a void method called display such that the...Ch. 7.6 - Prob. 33STQCh. 7 - Write a program in a class NumberAboveAverage that...Ch. 7 - Write a program in a class CountFamiles that...Ch. 7 - Write a program in a class CountPoor that counts...Ch. 7 - Write a program in a class FlowerCounter that...Ch. 7 - Write a program in a class characterFrequency that...Ch. 7 - Create a class Ledger that will record the sales...Ch. 7 - Define the following methods for the class Ledger,...Ch. 7 - Write a static method isStrictlyIncreasing (double...Ch. 7 - Write a static method removeDuplicates(Character[]...Ch. 7 - Write a static method remove {int v, int [] in}...Ch. 7 - Suppose that we are selling boxes of candy for a...Ch. 7 - Create a class polynomial that is used to evaluate...Ch. 7 - Write a method beyond LastEntry (position) for the...Ch. 7 - Revise the class OneWayNoRepeatsList, as given in...Ch. 7 - Write a static method for selection sort that will...Ch. 7 - Overload the method selectionSort in Listing 7.10...Ch. 7 - Revise the method selectionSort that appears in...Ch. 7 - Prob. 18ECh. 7 - Write a sequential search of an array of integers,...Ch. 7 - Write a static method findFigure (picture,...Ch. 7 - Write a static method blur (double [] [] picture)...Ch. 7 - Write a program that reads integers, one per line,...Ch. 7 - The following code creates a small phone book. An...Ch. 7 - Write the method rotateRight that takes an array...Ch. 7 - The following code creates a ragged 2D array. The...Ch. 7 - Write a program that will read a line of text that...Ch. 7 - Prob. 2PPCh. 7 - Add a method bubbleSort to the class ArraySorter,...Ch. 7 - Add a method insertionSort to the class...Ch. 7 - The class TimeBook in Listing 7.14 is not really...Ch. 7 - Define a class called TicTacToe. An object of type...Ch. 7 - Repeat Programming Project 10 from Chapter 5 but...Ch. 7 - Prob. 8PPCh. 7 - Write a GUI application that displays a picture of...Ch. 7 - ELIZA was a program written in 1966 that parodied...Ch. 7 - Prob. 11PPCh. 7 - Create a GUI application that draws the following...Ch. 7 - Practice Program 2 used two arrays to implement a...Ch. 7 - Practice Program 5.4 asked you to define Trivia...
Knowledge Booster
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
- Java Program Scenario: A high school has 1000 students and 1000 lockers, one locker for each student. On the first day of school, the principal plays the following game: She asks the first student to open all the lockers. She then asks the second student to close all the even-numbered lockers. The third student is asked to check every third locker. If it is open, the student closes it; if it is closed, the student opens it. The fourth student is asked to check every fourth locker. If it is open, the student closes it; if it is closed, the student opens it. The remaining students continue this game. In general, the nth student checks every nth locker. If the locker is open, the student closes it; if it is closed, the student opens it. After all the students have taken their turns, some of the lockers are open and some are closed. Write a program that prompts the user to enter the number of lockers in a school. After the game is over, the program outputs the number of lockers and the…arrow_forwardIn Java Pleasearrow_forwardIn a Chess match "a + b", each player has a clock which shows a minutes at the start and whenever a player makes a move, b seconds are added to this player's clock. Time on a player's clock decreases during that player's turns and remains unchanged during the other player's turns. If the time on some player's clock hits zero (but not only in this case), this player loses the game. N+1 There's a 3 + 2 blitz chess match. After N turns (i.e. moves made by 2 N white and moves made by black), the game ends and the clocks of the two 2 players stop; they show that the players (white and black) have A and B seconds left respectively. Note that after the N-th turn, b = 2 seconds are still added to the clock of the player that made the last move and then the game ends. Find the total duration of the game, i.e. the number of seconds that have elapsed from the start of the game until the end.arrow_forward
- Eclipse Java: Write a program that reads a string (password) and a number. The maximum number of attempts (3). The program with stop asking data if the word ‘quit’ is provided in the password valuearrow_forwardA random walk is a random path most often represented as a random number that changes over time. In particular, one common random walk is that in which the starting state is 0 and in each iteration we either add 1 or subtract 1 from the current value with equal probability. That is, in the first step, the next value would be 1 with probability 0.5 and -1 with probability 0.5. Use R to generate a random walk with 100 values starting at value 0 and store the values in a vector called random_walk. This vector should have length 100.arrow_forwardCoupon collector is a classic statistic problem with many practical applications. The problem is to pick objects from a set of objects repeatedly and determine how many picks are needed for all the objects to be picked at least once. A variation of the problem is to pick cards from a shuffled deck of 52 cards repeatedly and find out how many picks are needed before you see one of each suit. Assume a picked card is placed back in the deck before picking another. Write a program to simulate the number of picks needed to get four cards from each suit and display the four cards picked (it is possible that a card may be picked twice).arrow_forward
- Java - Brute Force Equation Solverarrow_forwardKinetic energy can be calculated with the following formula: KE 1 2 • m is mass in kg • v is velocity in m/s • KE is kinetic energy in J mv² شور در روز Return the Kinetic Energy in Joules, given the mass and velocity. For the purposes of this challenge, round answers to the nearest integer. Examples kinetic Energy (60, 3) → 270 kinetic Energy (45, 10) - 2250 kinetic Energy (63.5, 7.35) → 1715 Notes Expect only positive numbers for inputs.arrow_forwardThe Monty Hall game is a statistical problem: there is a TV show (like the Monty Hall show) that allows contestants to choose between three doors, A, B, and C. Behind one of these doors is a new car (the winning door), and behind the other two are goats (the losing doors). After the contestant makes a choice, the game show host shows a goat behind one of the doors NOT chosen. The contestant is then given a choice to either switch to the other, non-opened door, or stick with their original guess. The interesting part of this “game" is the statistics involved-a person has a 1/3 chance of originally picking a winning door. The other door chosen – actually has a 2/3 chance of being a winning door. Therefore, it is in the contestant's best interest to switch doors. that which is not revealed to have a goat but also was not originally You will create a program that simulates the Monty Hall game, where the computer plays the role of the host. The program must have no outputs, but 1) Ask the…arrow_forward
- The Monty Hall game is a statistical problem: there is a TV show (like the Monty Hall show) that allows contestants to choose between three doors, A, B, and C. Behind one of these doors is a new car (the winning door), and behind the other two are goats (the losing doors). After the contestant makes a choice, the game show host shows a goat behind one of the doors NOT chosen. The contestant is then given a choice to either switch to the other, non-opened door, or stick with their original guess. The interesting part of this “game" is the statistics involved –a person has a 1/3 chance of originally picking a winning door. The other door – that which is not revealed to have a goat but also was not originally chosen – actually has a 2/3 chance of being a winning door. Therefore, it is in the contestant's best interest to switch doors. You will create a program that simulates the Monty Hall game, where the computer plays the role of the host. The program must have no outputs, but 1) Ask…arrow_forwardUse java languagearrow_forwardDynamic Programmingarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education