You are on page 1of 3

FIT1002 Laboratory/Practical Week 2 (week commencing 01/08)

Students are expected to attend all laboratory/practical sessions. Attendance will be recorded each week for on-campus students. Students who miss two consecutive sessions may be followed up by a phone call to discuss their absence and reasons for disengaging with the unit. Students are expected to prepare for laboratory/practical sessions. The laboratory/practical should be a session where you clear up outstanding coding problems NOT where you begin coding! Your lab work will be marked in the lab. Each lab is worth 2 marks of your final mark for the unit. Objective: get familiar with using variables, expressions, data types, assignment, arithmetic operators, operator precedence and String concatenation to code simple, short applications.
1. Code an application that outputs the average of three integers. Two of the integers should be initialised in their declaration statement. The other should be initialised in a separate assignment statement. The average divisor (3) should be declared as a constant of type int with a suitable name with a suitable text style. The result should be stored in a variable of type double and the value of this variable should be output, prefixed with the String Average = . Check the displayed average for several sets of three integer values. If its incorrect adjust your code to fix any errors. 2. Code an application that outputs the sum, product and quotient of the values of two variables of type double. The application should also output twice the sum, product and quotient. Cut and paste can be your friend here but be careful you cut, paste and change pasted text appropriately. Initialise both variables in assignment statements (not in their declaration statement).

Store the result of each of the six calculations in the same general purpose, double variable called outValue before outputting the value of this variable. Prefix each output value with a suitable description of what it is. 3. Repeat Question 2 but this time uses a different, dedicated variable to hold the result of each calculation. Do all the calculations first then do all the outputting. 4. Code an application that converts a time in hours minutes and seconds to seconds. You will need four variables of type integer. The first three will be initialised to the values of hours minutes and seconds. The fourth will hold the calculated value of total seconds which will then be output. You should use constants to hold the values: number of seconds in an hour and number of seconds in a minute. e.g. 1 hour, 28 minutes, and 42 seconds should be converted to 5322 seconds. Check the displayed total seconds for several sets of three integer values for hours minutes and seconds. If its incorrect adjust your code to fix any errors. 5. Now code an application that performs the reverse of Question 4 i.e. it converts a number of seconds into hours minutes and seconds. Hint: use integer division and the remainder operators. 6. Code an application that outputs a name on one line. Declare three String variables called firstName, secondName and thirdName. Initialise these with the appropriate components of your name. If you have no middle name initialise secondName to the empty string. Concatenate these Strings and assign the concatenated value to the String variable fullName which should then be output. Correct your code if the output does not look right.

continued

OPTIONAL Question: Code an application that, given a currency amount, determines the fewest number of each currency denomination necessary to make up that amount. e.g. in Australia the currency denominations are 100, 50, 20, 10, 5, 2, 1 dollars and 50, 20, 10, 5 cents. Currency amounts are expressed as dollars and cents. For a currency amount of $233.85 cents the program should report: 100 Dollars: 2 50 Dollars: 0 20 Dollars: 1 10 Dollars: 1 5 Dollars: 0 2 Dollars: 1 1 Dollars: 1 50 Cents: 1 20 Cents: 1 10 Cents: 1 5 Cents: 1 Feel free to adapt this question to your local currency. You should be able to adapt code from your solution to Question 5 to help create a solution for this question.

You might also like