Some exam questions,from previous midterm exams: 1. Money Methods Write a function method theTotal(p,n,d,q) which returns the total value (in cents) of the given four slots (parameters) representing the number of pennies, nickels, dimes, and quarters. Write a routine method outTotal(p,n,d,q) which outputs the total value (in cents) of the given four slots (parameters) representing the number of pennies, nickels, dimes, and quarters. 2. Same Accounts Write a boolean function a.isSameAs(b), which determines whether two accounts a, b from the Account class are the same; i.e. they have the same identity (string) and balance (real). 3. Another Dispenser: of 15 cent items Draw the state diagram of a dispenser where the input is a sequence of nickels, dimes, and quarters, and the outputs are the item (costing 15 cents), and the proper change. 4. Nasty UnIndented Nests Write truth tables for the following pieces of Java code; note that a, b are boolean conditions and Y, Z are actions, such as output. a. if (a) if (b) Y; else Z; b. if (a) {if (b) Y;} else Z; c. if (a) Y; else if (b) Z; d. if (a && b) Y; else Z; 5.Plot DaysInMonth Given a function daysInMon(m) that determines the number of days in any given month m, write a routine which plots this number horizontally as shown below (for a leap year). m 1 2 3 1 1234567890123456789012345678901 2 12345678901234567890123456789 3 1234567890123456789012345678901 4 123456789012345678901234567890 5 1234567890123456789012345678901 6 123456789012345678901234567890 7 1234567890123456789012345678901 8 1234567890123456789012345678901 9 123456789012345678901234567890 10 1234567890123456789012345678901 11 123456789012345678901234567890 12 1234567890123456789012345678901 7. Bars again Given an array H of size 7, corresponding to the number of hours worked on each day of the week, write that part of a program to create a horizontal bar chart, where the length of each bar is proportional to the number of hours worked. For example, if the values in the array are 4, 8, 6, 4, 8, 8, 4, and the thickness is input as 2, and the scale multiplier is 3, then the bar plot will look like the following with a gap between the bars. 111111111111 111111111111 222222222222222222222222 222222222222222222222222 333333333333333333 333333333333333333 444444444444 444444444444 555555555555555555555555 555555555555555555555555 666666666666666666666666 666666666666666666666666 777777777777 777777777777 7. Array Trace Trace the following part of a program when acting on the given array, and indicate briefly what it does (not how it does it). Would you package this method as a function or a routine? Why? -- Array Trace Boxes i, j, k, temp ofType int Box A ofType int[] NewArray A ofType int[5] Set A[0] = 1 Set A[1] = 9 Set A[2] = 6 Set A[3] = 8 Set A[4] = 3 Set i = 0 Repeat ExitOn (i > 4) Set j = 4 - i -- Does what?? Set temp = A[i] Set A[i] = A[j] Set A[j] = temp Inc i by 1 EndRepeat Set k = 0 Repeat ExitOn (k > 4) Outputln A[k] Inc k by 1 EndRepeat