MSC / Pgdip It Programming: Exercise 1
MSC / Pgdip It Programming: Exercise 1
Exercise 1
Write a program to get the users first and last name and output their full name.
Your program should create a Console object and write a message Please enter
your first name. The program should then read a word from the console, storing it in
a variable called firstName. You should repeat this process to get the last name from the
user. You should then output the message Hello <full name>. Welcome to
Glasgow.
Your program should also print out each variable you create as soon as they are given values.
This should be printed using System.err and is an example of using trace statements.
Exercise 2
radius = 7 metres
The spaces are important. Also it is vital that you include a carriage return (end of line) after
the word metres!
You can chose your own filename and put it in any convenient place in your filesystem.
You may use any suitable tool (except a Java program!) to prepare this file.
Now write a program to read the contents of the file as 4 separate items, a string, a string, a
double and a string. Note that FileIn has a readDouble method as well as a
readWord method.
Write a message of the form The area is <correct area> on the following
outputs: a Console called con1, a second Console called con2 (just to show you can
have more than one console) and a file called Lab2out. Dont worry if you have a lot of
decimal places.
Exercise 3
Read a complete line from your input file, storing the result as a String in your program.
Now extract the radius information from this String and write the area message on a single
Console called con.