Copyright © – Sudharsan Iyengar
CS – 234. Lab 8 10/30/2024
a) Write an application that uses Random class from java.util.* and generates 100 random numbers – in the range from 0 to 400 and writes to a text file inp.dat.
b) Write an application that reads integer values from an input file inp.dat until it reaches the end of the file. Based on the values read from the file, the output should answer the following questions (output should be neatly formatted and aligned).
1. How many numbers were above 200, and how many below 200?
2. How many numbers were between 100 and 400?
3. How many were even numbers?
4. How many were odd numbers?
5. Which of the numbers was closest to 250?
c) Write an application
a) That requests a number from a user and replies if it is a prime number.
b) That requests a number from a user and displays all the prime numbers between 2 and that number
c) That requests from the users i) principal amount (int – between 3000 and 30000), ii) interest rate (double – between 0 and 20), and ii) the monthly payment (double - between 500 and 2000).
In response the application should output the amortization table – by month for the users.
An amortization table lists the month, the principal balance, the interest charged, the payment made, the amount paid towards the principal.
Example:
|
Interest rate |
Principal |
Monthly payment |
|
|
5% |
$ 20000 |
$ 1200 |
|
Month |
Balance ($) |
Interest ($) |
Payment ($) |
Payment on Principal ($) |
1 |
20000.00 |
83.33 |
1200.00 |
1116.67 |
2 |
18883.33 |
78.68 |
1200.00 |
1121.32 |
3 |
17762.01 |
74.01 |
1200.00 |
1125.99 |
4 |
16636.02 |
69.32 |
1200.00 |
1130.68 |
5 |
15505.34 |
64.61 |
1200.00 |
1135.39 |
6 |
14369.94 |
59.87 |
1200.00 |
1140.13 |
7 |
13229.82 |
55.12 |
1200.00 |
1144.88 |
8 |
12084.94 |
50.35 |
1200.00 |
1149.65 |
9 |
10935.30 |
45.56 |
1200.00 |
1154.44 |
10 |
9780.86 |
40.75 |
1200.00 |
1159.25 |
11 |
8621.61 |
35.92 |
1200.00 |
1164.08 |
12 |
7457.54 |
31.07 |
1200.00 |
1168.93 |
13 |
6288.61 |
26.20 |
1200.00 |
1173.80 |
14 |
5114.81 |
21.31 |
1200.00 |
1178.69 |
15 |
3936.13 |
16.40 |
1200.00 |
1183.60 |
16 |
2752.53 |
11.47 |
1200.00 |
1188.53 |
17 |
1564.00 |
6.52 |
1200.00 |
1193.48 |
18 |
370.51 |
1.54 |
1200.00 |
1198.46 |
19 |
827.94 |
3.45 |
1200.00 |
1203.45 |
Your program should compute for up to 30 months or until a point when the principal is paid off (and the balance becomes negative (shown in red) – your program should stop computing and output a statement like “You can pay off the principal in 18 months”. If the at the end of 30 months – the principal is not paid off, your program should output “You will need more than 30 months to pay off the principal”. Do not worry about the table borders.