Question 4 Write a function buildstr that will receive a character and a positive integer n It

Question 4: Write a function buildstr that will receive a character and a positive integer n. It will create and return a cell array with character vectors of increasing lengths, from 1 to the integer n. It will build the character vectors with successive characters in the ASCII encoding. >> buildstr(a,4) ans = aababcabcd Next, run your code and copy the output from the command window to Notepad (or a Word file) and save it as "lab8_output.txt" or "lab8_output.doc" in the "lab8" folder. Please include your name and lab section at the top. Finally, submit your work to Canvas. You should submit two files: "lab8_output.txt" (or Word file) and "lab8.m". If you wrote the function in a separate file, please submit that function as well.

Question 4: Write a function buildstr that will receive a character and a positive integer n. It will create and return a cell array with character vectors of increasing lengths, from 1 to the integer n. It will build the character vectors with successive characters in the ASCII encoding. >> buildstr(a,4) ans = aababcabcd Next, run your code and copy the output from the command window to Notepad (or a Word file) and save it as “lab8_output.txt” or “lab8_output.doc” in the “lab8” folder. Please i

Read More

Question 1 9 points Purpose Practice with conditionals practice with variables and good program

Question 1 (9 points): Purpose: Practice with conditionals; practice with variables and good program design. Degree of Difficulty: Moderate For this problem, you will write a program that will allow a user to calculate a letter-based grade, based on a grade percentage. Here is a description of how your program should look and behave: - Initially, display the text "Grade Calculator" and "Average:" on the canvas. - When the user presses a key, show the keys pressed beside "Average:" - When the user clicks the mouse, show the calculated grade in the bottom right corner of the canvas. - If a grade is showing and the user clicks the mouse, reset the canvas, clearing both the grade and average text. Below is a table of which grade should be assigned to each average. Here are some suggestions for how to design your program, especially with regard to the Model-ViewController design pattern. - Use at least 2 global variables in your program: current keys pressed and the grade to be displayed. - Create a function that takes an average as a parameter. This function should have conditionals to determine the appropriate grade and return it. - Update the global keys pressed variable in your keyPressed() function. - Implement a conditional in your mouseClicked() function. It will either calculate an appropriate grade or reset the canvas. NOTE: You can assume that the user will always type numbers. You do not have to handle incorrect data by checking for only numbers. (Feel free to handle this as an extra challenge, but it will not be worth marks.)

Question 1 (9 points): Purpose: Practice with conditionals; practice with variables and good program design. Degree of Difficulty: Moderate For this problem, you will write a program that will allow a user to calculate a letter-based grade, based on a grade percentage. Here is a description of how your program should look and behave: – Initially, display the text “Grade Calculator” and “Average:” on the canvas. – When the user presses a key, show the keys pressed beside “Average:” – When the use

Read More

Your program must define and call the following method The return value of getPhoneNumber 0 is the

Your program must define and call the following method. The return value of getPhoneNumber is the phone number associated with the specific contact name. public static String getPhoneNumber(String[] nameArr, String[] phoneNumberArr, String contactName, int arraySize) Hint: Use two arrays: One for the string names, and the other for the string phone numbers. Please note that the input has commas. You would need to deal with the comma using indexOf and substring. Example code snippet: int comma = userInput.indexOf(","); contactNames[i] = userInput.substring(0, comma); contactNumbers[i] = userInput.substring(comma + 1);

Your program must define and call the following method. The return value of getPhoneNumber is the phone number associated with the specific contact name. public static String getPhoneNumber(String[] nameArr, String[] phoneNumberArr, String contactName, int arraySize) Hint: Use two arrays: One for the string names, and the other for the string phone numbers. Please note that the input has commas. You would need to deal with the comma using indexOf and substring. Example code snippet: int comma =

Read More

A contact list is a place where you can store a specific contact with other associated information

A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes as input an integer N that represents the number of word pairs in the list to follow. Word pairs consist of a name and a phone number (both strings), separated by a comma. That list is followed by a name, and your program should output the phone number associated with that name. Output "None" if name is not found. Assume that the list will always contain less than 20 word pairs. Hint: here we are going to use oversize array again, so we need a variable to track the number of values in the array. You can use 20 as array capacity. Be careful: Word pairs consist of a name and a phone number (both strings) String[]contactNames=newString[20]; String[]contactNumbers=newString[20]; Important Note: Your output needs to match the required output including the space see Ex: Ex: If the input is: 3 Joe, 123-5432 Linda, 983-4123 Frank,867-5309 Frank the output is: 8675309 Your program must define and call the following method. The return value of getPhoneNumber is the phone number associated with the specific contact name. public static String getPhoneNumber(String[] nameArr, String[] phoneNumberArr, String contactName, int arraySize) Hint: Use two arrays: One for the string names, and the other for the string phone numbers. Please note that the input has comma. You would need to deal with the comma using indexOf and substring. int comma = userInput.indexOf(","); contactNames[i] = userlnput.substring(0, comma); contactNumbers[i] = userInput.substring(comma + 1); 487182.3555262.qx3zqy7 LAB 20.3.1: LAB 3.3: Contact list 3/10 ACTIVITY LabProgram.java Load default template... import java.util.Scanner; public class LabProgram { /* Define your method here */ public static void main(String[ ] args) { /* Type your code here. */ } }

A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes as input an integer N that represents the number of word pairs in the list to follow. Word pairs consist of a name and a phone number (both strings), separated by a comma. That list is followed by a name, and your program should output the phone number associated with that name. Output “None” if name is not foun

Read More

Sample output Bankers Algorithm 1 Enter claim graph 2 Request resource 3 Release resource 4

Sample output of the Banker's Algorithm: - Enter claim graph - Request resource - Release resource - Determine safe sequence - Quit program Enter selection: 1 Enter number of resources: 3 Enter number of units for resources (r0 to r2): 1057 Enter number of processes: 5 Enter maximum number of units process p0 will claim from each resource (r0 to r2): 753 Enter maximum number of units process p1 will claim from each resource (r0 to r2): 322 Enter maximum number of units process p2 will claim from each resource (r0 to r2): 902 Enter maximum number of units process p3 will claim from each resource (r0 to r2): 222 Enter maximum number of units process p4 will claim from each resource (r0 to r2): 433 Enter number of units of each resource (r0 to r2) currently allocated to process p0: 0 1 0 Enter number of units of each resource (r0 to r2) currently allocated to process p1: 2 0 0 Enter number of units of each resource (r0 to r2) currently allocated to process p2: 2 0 2 Enter number of units of each resource (r0 to r2) currently allocated to process p3: 21 1 Enter number of units of each resource (r0 to r2) currently allocated to process p4: 0 1 2 Available: r0 r1 r2 3 3 2 Allocated: r0 r1 r2 p0 0 1 0 p1 2 0 0 p2 3 0 2 p3 2 1 1 p4 0 0 2 Need: r0 r1 r2 p0 7 4 3 p1 1 2 2 p2 6 0 0 p3 0 1 1 p4 4 3 1 Banker's Algorithm: - Enter claim graph - Request resource - Release resource - Determine safe sequence - Quit program Enter selection: 4 Comparing: 743=332 : Process p0 cannot be sequenced Comparing: 122=332 : Process p1 can be sequenced Comparing: 60=532 : Process p2 cannot be sequenced Comparing: 011=532 : Process p3 can be sequenced Comparing: 431=743 : Process p4 can be sequenced Comparing: 743=745 : Process p0 can be sequenced Comparing: 600=755 : Process p2 can be sequenced Safe sequence of processes: p1 p3 p4 p0 p2 Banker's Algorithm: - Enter claim graph - Request resource - Release resource - Determine safe sequence - Quit program Enter selection: 2 Enter requesting process: p2 Enter requested resource: r0 Enter number of units process p2 is requesting from resource r0: 1 Enter selection: 3 Enter releasing process: p4 Enter released resource: r1 Enter number of units process p4 is releasing from resource r1: 1 Resources: r0 10 5 3 r1 0 4 1 r2 2 2 7 Available: r0 r1 r2 0 4 2 Max Claim: r0 r1 r2 p0 7 5 3 p1 3 2 2 p2 9 0 2 p3 2 2 2 p4 4 3 3 Allocated: r0 r1 r2 p0 0 1 0 p1 2 0 0 p2 2 0 2 p3 2 1 1 p4 0 1 2 Need: r0 r1 r2 p0 7 4 3 p1 1 2 2 p2 7 0 0 p3 0 1 1 p4 4 2 1 Enter selection: 4 Comparing: 743=332 : Process p0 cannot be sequenced Comparing: 122=332 : Process p1 can be sequenced Comparing: 60=532 : Process p2 cannot be sequenced Comparing: 011=532 : Process p3 can be sequenced Comparing: 431=743 : Process p4 can be sequenced Comparing: 743=745 : Process p0 can be sequenced Comparing: 600=75 : Process p2 can be sequenced Safe sequence of processes: p1 p3 p4 p0 p2 Banker's Algorithm: - Enter claim graph - Request resource - Release resource - Determine safe sequence - Quit program Enter selection: 5 Quitting program...

Sample output of the Banker’s Algorithm: – Enter claim graph – Request resource – Release resource – Determine safe sequence – Quit program Enter selection: 1 Enter number of resources: 3 Enter number of units for resources (r0 to r2): 1057 Enter number of processes: 5 Enter maximum number of units process p0 will claim from each resource (r0 to r2): 753 Enter maximum number of units process p1 will claim from each resource (r0 to r2): 322 Enter maximum number of units process p2 will claim from

Read More

53 Write a program that displays editable bar graphs The GUI has two horizontal panels The right

5.3. Write a program that displays editable bar graphs. The GUI has two horizontal panels. The right panel contains textfields with numbers. The left panel contains corresponding horizontal bar graphs that graphically show the value of the numbers on the left. Use a rectangle with the width (in pixels) equal to the numbers from the textfield, but no higher than 100 pixels. The UI should look something like this: Use MVC and the Observer pattern. Store the numbers in the model. Attach the graph view as a listener. When the user edits one of the numbers, the number controller should update the model and the model should notify the graph view that a change has occurred. Then, the graph should get the number from the model and repaint itself. Hints: use method TextField.getText() to extract the text from a textfield. Add a key listener to each textfield with method TextField.addKeyListener(KeyListener l)

5.3. Write a program that displays editable bar graphs. The GUI has two horizontal panels. The right panel contains textfields with numbers. The left panel contains corresponding horizontal bar graphs that graphically show the value of the numbers on the left. Use a rectangle with the width (in pixels) equal to the numbers from the textfield, but no higher than 100 pixels. The UI should look something like this: Use MVC and the Observer pattern. Store the numbers in the model. Attach the

Read More

Between a Rock and a Hard Place Given a string in a variable named text write code that finds the

Between a Rock and a Hard Place Given a string in a variable named text, write code that finds the substring that lies between the substring 'rock' and the substring 'hard place'. For example, if text contains 'here is a rock and here is a hard place', then the result would be ' and here is a'. Assign the result to a variable named between. Assume that text already has a value that contains the substrings 'rock' and 'hard place' in that order. Print the Longer String Write code that prints the longer of two strings that are stored in the variables str1 and str2. If both strings are equal in length, print the value of str1. Assume that both variables have already been given values. Print Product Id Write code that examines a string stored in a variable called product_id and prints an appropriate version of the id. If the id is composed of only numeric digits, print it as is. If it is composed of a combination of alphabetic letters and digits, print the id with all alphabetic letters in uppercase. Otherwise (if there are any other types of characters in the id), print it with all alphabetic letters in lowercase. Assume that the product id has already been initialized. Double Word Write code that constructs a string made up of each character in a string variable named word repeated twice. For example, if word contains 'Python', the resulting string would be 'PPyytthhoonn'. Store the constructed string in a variable called double_word. Assume that word has already been initialized. How Do You Spell That? Write code that produces a string made up of each character in a string variable named word separated by a dash. For example, if word contained the string 'Python', the resulting string would be 'P-y-t-h-o-n'. Do NOT include a dash after the last character. Store the resulting string in a variable named spell_string. Assume that the variable word has already been initialized. Generate Acronyms Given a phrase stored in the variable phrase, write code to construct an acronym made up of the first letter of each word in the phrase. For example, the phrase 'Portable Network Graphics' would produce the acronym 'PNG'. Store the result in a variable named acronym, ensuring that it is composed of all uppercase letters. Assume that there is no whitespace on either end of the phrase and that one space character separates each word. Back to Front Write code that constructs a string made by flipping the front and back halves of a string stored in a variable named flip_me. For example, if flip_me is 'bookmark', the resulting string is 'markbook'. Store the result in a variable named flipped. Assume that the variable flip_me has already been given a value and that it contains an even number of characters. Count It Write code that determines how many times the string 'it' appears in the character string stored in a variable named sentence. Store the result in the variable it_count. Assume that sentence has been initialized. Ideas and Thoughts Write code that prints a string made up of the string stored in the variable sentence with all instances of the word 'idea' replaced with the word 'thought'. Assume the sentence variable has already been initialized.

Between a Rock and a Hard Place Given a string in a variable named text, write code that finds the substring that lies between the substring ‘rock’ and the substring ‘hard place’. For example, if text contains ‘here is a rock and here is a hard place’, then the result would be ‘ and here is a’. Assign the result to a variable named between. Assume that text already has a value that contains the substrings ‘rock’ and ‘hard place’ in that order. Print the Longer String Write code that prints the

Read More