Simplex locks are keyless locks that have a sequence of buttons. You press the proper combination...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Simplex locks are keyless locks that have a sequence of buttons. You press the proper combination of buttons, 12. and the lock opens. A typical lock has five buttons. A combination might be set to three buttons, and then you need to press them in the same order. You never press the same button twice. ... For example the lock for the restroom at the Rob Hill campground in the San Francisco Presidio is opened by the combination 425, as I figured out by trial and error. (They probably changed it by the time you read this.) It is also possible to define combinations with four or five buttons. Is that more secure? Would it be much better to have six buttons? That is what this exercise is about. If the lock has n buttons, and the combination requires k buttons to be pressed, how many combinations are there? Let's call that number combinations (n, k). If k is 1, then you push one button out of n, so combinations (n, 1) is clearly n. If k is greater than one, let us focus on the first button. There are n choices for the first button, and for each of them we get to pick k - 1 choices out of n - 1 buttons. That's the same problem again, with simpler inputs. Complete the method that yields the total number of combinations for a lock with n buttons, of which k are to be selected. SimplexLock.java 1 public class SimplexLocks 2 { 3 4 6 7 8 9 10 11 12 13 123456 14 15 16 17 18 19 20 21 344828 25 26 27 // calculate the factorial int fact(int num) { } // test the function 22 public static void main (String[] args) { 28 } int f=1; for(int i=1;i<=num; i++) f*=i; return f; public int combinations (int n, int k) { } // so, we have result = (n)/ ( (k!)*(n-k)! ) int numerator = fact(n); int denominator = return numerator/denominator; fact(k)* fact (n-k); System.out.println("Combinations (10,4) is "+new SimplexLocks ().combinations (1 System.out.println("Combinations (6,4) is "+new SimplexLocks (). combinations (6, System.out.println("Combinations (10,2) is "+new SimplexLocks (). combinations (1 ... 5. Complete the printCalendarmethod that prints a calendar such as 1 2 3 4 7 8 9 10 5 6 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 The column of the first day and the number of days are given as parameters. The method prints the calendar and returns no result. Calendar.java 1 import java.util.Scanner; 2 3 public class Calender { 456789 7 9 10 11 12 13 System.out.print("Number of days :"); 14 int days=sc. nextInt(); 1 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 15 System.out.print ("Weekday of first day (0 = Sunday) :"); 16 int weekday=sc.nextInt (); 44 45 public static void main (String[] args) { 46 47 48 49 50 51 52 53 53 } * Creating an Scanner class object which is used to get the inputs * entered by the user */ Scanner sc = new Scanner (System.in); System.out.println(" Su Mo Tu We th Fr Sa"); print Calender (weekday, days); } //Getting the input entered by the user } private static void printCalender (int firstDay, int days) { int i; //System.out.println(" "); == if ((firstDay % 7) >= 0) { if ((firstDay % 7) 0) { } else if ((firstDay % 7) System.out.print(" "); } else if ((firstDay % 7) System.out.print ("\t"); } else if ((firstDay % 7) System.out.print("\t\t "); } else if ((firstDay % 7) System.out.print ("\t "); } else if ((firstDay % 7) System.out.print("\t\t "); } else if ((firstDay % 7) System.out.print("\t\t "); } } == } == 2) { == == == 1) { == 3) { 4) { 5) { 6) { for (i = 1; i <= days ; i++) { System.out.printf("%2d " i); if (((i+firstDay) % 7 System.out.println(); 0) || (i == days)) ... 9. In the preceding exercises, you saw how one can use stepwise refinement to solve the problem of translating Wiki markup to HTML. Now turn the pseudocode into code. Complete the convertToHTML and nextSymbol methods in the following class. WikiMarkup.java 1 import java.util.Scanner; 2345678 3 public class WikiMarkup 4 { 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 -10 15 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 } 70 71 70 71 } public static void main(String[] args) { } /** Scanner in = new Scanner (System.in); String message = in.nextLine(); System.out.println(convertToHTML (message)); */ public static String convertToHTML (String message) { String result = message; return result. replace("\\", ""); Converts a message with Wiki markup to HTML. @param message the message with markup @return the message with Wiki notation converted to HTML } /** } /** */ public static int next Symbol (String message, String symbols, int start) { } /** Gets the HTML tag for a markup symbol. @param symbol the markup symbol @return the corresponding HTML tag, or null if none found Finds the next unescaped symbol. @param message a message with Wiki markup @param symbols the symbols to search for @param start the starting position for the search @return the position of the next markup symbol at or after start */ public static String tagForSymbol (char symbol) { } == if (symbol '!') { return "em"; } else if (symbol == else if (symbol else if (symbol else if (symbol == else { return null; } Replaces a character of a string at a given position. @param str the string where the replacement takes place @param position the position of the character to be replaced @param replacement the replacement string, or the original string if position was not valid. */ public static String replaceAt (String str, int position, String replacement) == { if (0<= position && position < str.length()) { ¹*') { return "strong"; } ¹) { return "code"; } ^') { return "super"; } _') { return "sub"; } } else { } return str.substring(0, position) + replacement + str.substring (position + 1); return str; Simplex locks are keyless locks that have a sequence of buttons. You press the proper combination of buttons, 12. and the lock opens. A typical lock has five buttons. A combination might be set to three buttons, and then you need to press them in the same order. You never press the same button twice. ... For example the lock for the restroom at the Rob Hill campground in the San Francisco Presidio is opened by the combination 425, as I figured out by trial and error. (They probably changed it by the time you read this.) It is also possible to define combinations with four or five buttons. Is that more secure? Would it be much better to have six buttons? That is what this exercise is about. If the lock has n buttons, and the combination requires k buttons to be pressed, how many combinations are there? Let's call that number combinations (n, k). If k is 1, then you push one button out of n, so combinations (n, 1) is clearly n. If k is greater than one, let us focus on the first button. There are n choices for the first button, and for each of them we get to pick k - 1 choices out of n - 1 buttons. That's the same problem again, with simpler inputs. Complete the method that yields the total number of combinations for a lock with n buttons, of which k are to be selected. SimplexLock.java 1 public class SimplexLocks 2 { 3 4 6 7 8 9 10 11 12 13 123456 14 15 16 17 18 19 20 21 344828 25 26 27 // calculate the factorial int fact(int num) { } // test the function 22 public static void main (String[] args) { 28 } int f=1; for(int i=1;i<=num; i++) f*=i; return f; public int combinations (int n, int k) { } // so, we have result = (n)/ ( (k!)*(n-k)! ) int numerator = fact(n); int denominator = return numerator/denominator; fact(k)* fact (n-k); System.out.println("Combinations (10,4) is "+new SimplexLocks ().combinations (1 System.out.println("Combinations (6,4) is "+new SimplexLocks (). combinations (6, System.out.println("Combinations (10,2) is "+new SimplexLocks (). combinations (1 ... 5. Complete the printCalendarmethod that prints a calendar such as 1 2 3 4 7 8 9 10 5 6 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 The column of the first day and the number of days are given as parameters. The method prints the calendar and returns no result. Calendar.java 1 import java.util.Scanner; 2 3 public class Calender { 456789 7 9 10 11 12 13 System.out.print("Number of days :"); 14 int days=sc. nextInt(); 1 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 15 System.out.print ("Weekday of first day (0 = Sunday) :"); 16 int weekday=sc.nextInt (); 44 45 public static void main (String[] args) { 46 47 48 49 50 51 52 53 53 } * Creating an Scanner class object which is used to get the inputs * entered by the user */ Scanner sc = new Scanner (System.in); System.out.println(" Su Mo Tu We th Fr Sa"); print Calender (weekday, days); } //Getting the input entered by the user } private static void printCalender (int firstDay, int days) { int i; //System.out.println(" "); == if ((firstDay % 7) >= 0) { if ((firstDay % 7) 0) { } else if ((firstDay % 7) System.out.print(" "); } else if ((firstDay % 7) System.out.print ("\t"); } else if ((firstDay % 7) System.out.print("\t\t "); } else if ((firstDay % 7) System.out.print ("\t "); } else if ((firstDay % 7) System.out.print("\t\t "); } else if ((firstDay % 7) System.out.print("\t\t "); } } == } == 2) { == == == 1) { == 3) { 4) { 5) { 6) { for (i = 1; i <= days ; i++) { System.out.printf("%2d " i); if (((i+firstDay) % 7 System.out.println(); 0) || (i == days)) ... 9. In the preceding exercises, you saw how one can use stepwise refinement to solve the problem of translating Wiki markup to HTML. Now turn the pseudocode into code. Complete the convertToHTML and nextSymbol methods in the following class. WikiMarkup.java 1 import java.util.Scanner; 2345678 3 public class WikiMarkup 4 { 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 -10 15 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 } 70 71 70 71 } public static void main(String[] args) { } /** Scanner in = new Scanner (System.in); String message = in.nextLine(); System.out.println(convertToHTML (message)); */ public static String convertToHTML (String message) { String result = message; return result. replace("\\", ""); Converts a message with Wiki markup to HTML. @param message the message with markup @return the message with Wiki notation converted to HTML } /** } /** */ public static int next Symbol (String message, String symbols, int start) { } /** Gets the HTML tag for a markup symbol. @param symbol the markup symbol @return the corresponding HTML tag, or null if none found Finds the next unescaped symbol. @param message a message with Wiki markup @param symbols the symbols to search for @param start the starting position for the search @return the position of the next markup symbol at or after start */ public static String tagForSymbol (char symbol) { } == if (symbol '!') { return "em"; } else if (symbol == else if (symbol else if (symbol else if (symbol == else { return null; } Replaces a character of a string at a given position. @param str the string where the replacement takes place @param position the position of the character to be replaced @param replacement the replacement string, or the original string if position was not valid. */ public static String replaceAt (String str, int position, String replacement) == { if (0<= position && position < str.length()) { ¹*') { return "strong"; } ¹) { return "code"; } ^') { return "super"; } _') { return "sub"; } } else { } return str.substring(0, position) + replacement + str.substring (position + 1); return str;
Expert Answer:
Answer rating: 100% (QA)
Answer Here is the recursive function to determine t... View the full answer
Related Book For
Discrete and Combinatorial Mathematics An Applied Introduction
ISBN: 978-0201726343
5th edition
Authors: Ralph P. Grimaldi
Posted Date:
Students also viewed these programming questions
-
A lock has n buttons labeled 1, 2, . . . , n. To open this lock we press each of the n buttons exactly once. If no two or more buttons may be pressed simultaneously, then there are n\ ways to do...
-
Let S be the simplex generated by the finite set of points E = (x1; x2; . . . ; xn). Show that each of the vertices xi is an extreme point of the simplex. Simplexes are the most elementary of convex...
-
A combination lock has four dials. On each dial are the digits 0 to 9. a. Suppose you forget the correct combination to open the lock. How many combinations do you have to try? If it takes 10 s to...
-
A mixture of 1 kmol carbon dioxide, 2 kmol carbon monoxide, and 2 kmol oxygen, at 25C, 150 kPa, is heated in a constant pressure steady state process to 3000 K. Assuming that only these same...
-
Jenkins Corporation wants to acquire a $200,000 computer. Jenkins has a 40 percent marginal tax rate. If owned, the computer would be depreciated on a straight-line basis to a book salvage value of...
-
Some food retailers propose subjecting food to a low level of radiation in order to improve safety, but sale of such irradiated food is opposed by many people. Suppose a grocer wants to find out what...
-
Masy's Department Store supported its operations through short-term note financing in 2020 described as follows: May 10 The Company entered into a new credit agreement with certain financial...
-
Wingate Company, a wholesale distributor of videotapes, has been experiencing losses for some time, as shown by its most recent monthly contribution format income statement, which follows: In an...
-
Kathy Burnett works for Triumph Industries. Her pay rate is $12.24 per hour and she receives overtime pay at one and one-half times her regular hourly rate for any hours worked beyond 40 in a week....
-
Jerry Stevenson is the manager of a medical clinic in Scottsdale, AZ. He wants to analyze patient data to identify high-risk patients for cardiovascular diseases. From medical literature, he learned...
-
Given 512 KB of physical memory, an 8-way set associative cache 16 KB in size with a block size of 8 bytes. 6. (1 pt) How many bits for the block offset? 7. (1 pt) How many bits required for the...
-
Mr. John Nicos, financial manager of Cbles Chat Lte (CCL), must choose between two investment projects intended to increase the company's capacity to meet growing customer demand. The Refit project...
-
Texas Boots Inc. is considering the production of a new line of boots. Based on preliminary market research, management has decided that each pair of boots should be priced at $300. Furthermore,...
-
Let s say you are buying a home, putting 1 5 % down and financing the rest with a 3 0 - year mortgage. The price of the home you are buying is $ 1 , 0 0 0 , 0 0 0 and the APR is 6 . 8 5 % . 1 ....
-
Determine the stability of the sytem whose zero-pole plot is shown Stable Marginally stable Unstable 7 where all poles are of multiplicity 1.
-
The cost of flood damage from significant storms varies as a function of the severity of the storm. Estimate the expected flood damage due to the next significant storm. Flood Flow, Million Acre-Ft...
-
Western Gas & Electric Co. (WG&E) currently has $645,000 in total assets and sales of $1,720,000. Half of WG&E's total assets come from net fixed assets, and the rest are current assets. The firm...
-
Outline a general process applicable to most control situations. Using this, explain how you would develop a system to control home delivery staff at a local pizza shop.
-
(b) State and prove another result comparable to that in part (a). (What principle is used here?) f(z)
-
Write the following statement as an implication in two ways, each in the if-then form: Either Kaylyn practices her piano lessons or she will not go to the movies.
-
Find the generating function for the number of integer solutions to the equation c1 + c2 + c3 + C4 = 20 where -3 < c1, -3 < c2, -5 < c3 < 5, and 0 < C4.
-
On the Internet, locate "Corruption and Related Matters: An Annotated Bibliography" by the Independent Commission Against Corruption, especially the Chapters on White Collar Crime and Workplace...
-
Go to the AICPA's Antifraud Resource Center and search for forensic accounting topics. Read some of the material listed. Search for material dealing with litigation support. What type of forensic...
-
Go to the Association of Certified Fraud Examiners web site and locate the 2008 Report to the Nation on Occupational Fraud and Abuse (The 2008 Wells Report). a. The cases in this study generated...
Study smarter with the SolutionInn App