%%[[9 Test Answers]]%%
* You have 55 minutes to complete the test
* Type or copy and paste your answers onto a Word Document
* You must print out your answer document within time
Write programs to do the following
1. Prompt the user to enter the length and width of a square. Output the area of the square.
2. Prompt the user to enter a test score. Output their grade: Under 100 - Fail, Under 120 Pass, Under 130 Merit, 130+ Distinction
3. Use a for loop to print out the following sequence: 12, 15, 18, 21, 24, 27
4. Use a for loop to print out the first 8 square numbers: 1,4,9,16,25,36,49,64
5. Make a counting program. Use a do while loop to keep asking "Another?" until the user enters "n". Output the number of times the loop repeated
6. Create a file called names.txt containing the names John, Paul, George and Ringo. Write a program the reads in the text file and prints out the data
7. Create a string array containing the four seasons: spring, summer, autumn and winter. Print out a random season
## Extension
Write a program that prints out the verses of the song the Twelve Days of Christmas. You will get bonus marks for elegant coding.
```
On the first day of Christmas
my true love sent to me:
A Partridge in a Pear Tree
On the second day of Christmas
my true love sent to me:
2 Turtle Doves
and a Partridge in a Pear Tree
On the third day of Christmas
my true love sent to me:
3 French Hens
2 Turtle Doves
and a Partridge in a Pear Tree
.
.
.
On the first day of Christmas
my true love sent to me:
12 Drummers Drumming
11 Pipers Piping
10 Lords a Leaping
9 Ladies Dancing
8 Maids a Milking
7 Swans a Swimming
6 Geese a Laying
5 Golden Rings
4 Calling Birds
3 French Hens
2 Turtle Doves
and a Partridge in a Pear Tree
```
%%
```java
Scanner scan = new Scanner(System.in);
System.out.println("Enter the length of a square");
int length = scan.nextInt();
System.out.println("Enter the width of a square");
int width = scan.nextInt();
System.out.println("Area: " + length * width);
System.out.println("Enter a test score: ");
int score = scan.nextInt();
if (score < 100) {
System.out.println("Fail");
} else if (score < 120) {
System.out.println("Pass");
} else if (score < 130) {
System.out.println("Merit");
} else {
System.out.println("Distinction");
}
for (int i = 12; i < 28; i = i + 3) {
System.out.println(i);
}
for (int i = 1; i < 9; i++) {
System.out.println(i * i);
}
int count = 0;
String ans;
do {
System.out.println("Another?");
ans = scan.nextLine();
count++;
} while (!ans.equals("n"));
System.out.println(count);
try {
Scanner scan = new Scanner(new File("M:/names.txt"));
while (scan.hasNext()) {
System.out.println(scan.nextLine());
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] season = { "Spring", "Summer", "Autumn", "Winter" };
int num = (int) (Math.random() * 4);
System.out.println(season[num]);
}
```
%%