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...
-
Product A is made from components B and C. Item B, in turn, is made from D and E. Item C also is an intermediate item, made from F and H, Finally, intermediate item B is made from H and G. Note that...
-
Do you agree with the principle of self-reference? In other words, do you believe if people know where the organization is trying to go, they will make decisions that support the desired...
-
Discuss the following issues relating to criticism of conventional accounting. 1 Conventional accounting uses the accrual convention.What is the accrual convention? What is the main benefit of...
-
Code Churn is a common metric used to measure the efficiency and productivity of software engineers and computer programmers. It?s usually measured as the percentage of a programmer?s code that must...
-
Prove the following identity: cos(2x) - 1 sin(2x) tan(x) 1 cos(2x) - 1 sin(2x) Question Help: Video Submit Question Search ASUS VivoBook
-
Following are preacquisition financial balances for Padre Company and Sol Company as of December 31. Also included are fair values for Sol Company accounts. Padre Company Sol Company Book Values Book...
-
Given functions f and g, find (a) (fog)(x) and its domain, and (b) (go f)(x) and its domain. f(x)=x, g(x)=x+10 (a) (fog)(x) = (Simplify your answer. Type an exact answer, using radicals as needed.)...
-
What were the positive and negative aspects of the changes that occurred in the auditors ethical environment during the 1970s and 1980s?
-
What is the advantage of using a cascode active load?
-
You have been assigned to perform an operational audit of the vehicle mainte nance department of a large university. What factors will you consider in deter mining if the department is operating...
-
What is the impedance seen looking into a simple active load?
-
During the 1970s and 1980s, all of the rules of conduct listed below were either substantially modified or eliminated except a. Advertising and solicitation. b. Independence. c. Competitive bidding....
-
The Walt Disney Company (NYSE: DIS) has debt of a par value of $58.6 billion and is currently traded at 98% of the par value. While Disney's debt is priced to yield 3%, the US Treasury rate is 2%....
-
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.
-
(a) Use a histogram to graph the empirical distribution of the duration times between American Airline trades. Compare the graph with Figure 2.9. Figure 2.9. (b) Interpret the shape of the...
-
Consider the equity prices of the United States companies Microsoft and Walmart for the period April 1990 to July 2004 ( \(T=172)\). (a) Compute the continuously compounded (log) returns on Microsoft...
-
(a) Compute the monthly excess returns on Exxon, General Electric, Gold, IBM, Microsft and Walmart. Be particularly carefully when computing the correct risk free rate to use. (b) Estimate the CAPM...
Study smarter with the SolutionInn App