Lab 9 (Year 3 Sem 1)

Lab 9 is the tenth lab in semester 1 of year 3, and the tenth lab in the total of year 3. It is a lab for arrays, and is considered to be moderately easy.

Description
No description was provided for this lab.

Unlocked after completion

 * OCD (Score at least 60% for Lab 9: Arrays)
 * The Organizer (Score at least 80% for Lab 9: Arrays)

Question
Write a program named Array that creates an array of integers and prints out some information about the array's contents. The program should:  Prompt the user to enter a positive integer N. Create an integer array of size N and initialise the array with random integer numbers in the range [-50, 50]. Print out the contents of the array using a for loop. Have a method named average that will take in an integer array and return the average value of its contents. Have a method named largest that will take in an integer array and return the largest value in the array. Have a method named smallest2 that will take in an integer array and return the second smallest DISTINCT value in the array. Finally, print the average, largest and second smallest value of the generated array.  Sample Output: <span style="font-family: &quot;Courier New&quot;;">Enter N: 10 <span style="font-family: &quot;Courier New&quot;;">Contents of Array:  <font face="Courier New">-47 48 -49 43 -23 40 35 33 49 -49 <font face="Courier New">Average Value: 8.0 <font face="Courier New">Largest Value: 49 <font face="Courier New">Second Smallest Value: -47

Solution
todo

Question
Write a program named SimulateATM that uses an Account class to simulate an ATM machine. For this question, the Account class has already been provided. The program should first create ten accounts in an array with id 0, 1, ..., 9 and initial balance $100, then prompt the user to enter an id from 0-9. If the id is entered incorrectly, it should ask the user to enter a correct id. Once an id is accepted, the main menu is displayed as shown in the sample run. From the main menu, the user can enter a choice:   (1) for viewing the current balance. (2) for withdrawing money. (3) for depositing money. (4) for exiting the program. Sample Run: <span style="font-family: &quot;Courier New&quot;;">Enter an id: 4 <font face="Courier New">Main menu <font face="Courier New">1: check balance <font face="Courier New">2: withdraw <font face="Courier New">3: deposit <font face="Courier New">4: exit <font face="Courier New">Enter a choice: 1 <font face="Courier New">The balance is $100.00 <font face="Courier New"> <font face="Courier New">Main menu <font face="Courier New">1: check balance <font face="Courier New">2: withdraw <font face="Courier New">3: deposit <font face="Courier New">4: exit <font face="Courier New">Enter a choice: 2 <font face="Courier New">Enter an amount to withdraw: 3 <font face="Courier New">Main menu <font face="Courier New">1: check balance <font face="Courier New">2: withdraw <font face="Courier New">3: deposit <font face="Courier New">4: exit <font face="Courier New">Enter a choice: 1 <font face="Courier New">The balance is $97.00 <font face="Courier New"> <font face="Courier New">Main menu <font face="Courier New">1: check balance <font face="Courier New">2: withdraw <font face="Courier New">3: deposit <font face="Courier New">4: exit <font face="Courier New">Enter a choice: 3 <font face="Courier New">Enter an amount to deposit: 10 <font face="Courier New"> <font face="Courier New">Main menu <font face="Courier New">1: check balance <font face="Courier New">2: withdraw <font face="Courier New">3: deposit <font face="Courier New">4: exit <font face="Courier New">Enter a choice: 1 <font face="Courier New">The balance is $107.00 <font face="Courier New"> <font face="Courier New">Main menu <font face="Courier New">1: check balance <font face="Courier New">2: withdraw <font face="Courier New">3: deposit <font face="Courier New">4: exit <font face="Courier New">Enter a choice: 4

Solution
todo

Question
Write a program which allows user to perform matrix addition, subtraction and multiplication for any two input N by N square matrices. The program should contain the following methods:  add: which will take in 2 integer square matrices and perform matrix addition. The method will return the resultant matrix as an integer 2D array.</li> subtract: which will take in 2 integer square matrices and perform matrix subtraction. The method will return the resultant matrix as an integer 2D array.</li> multiply: which will take in 2 integer square matrices and perform matrix multiplication. The method will return the resultant matrix as an integer 2D array.</li> </ul> Test your methods accordingly in the main method.

Solution
todo