Computer Programming Lab One 2026: Java Variables, Scanner Input and Conditional Statements | Griffith College
| Module | Computer Programming (Java) |
| Institution | Griffith College (package name “griffith” in the brief) |
| Assessment | Computer Programming Lab One worksheet – 6% of CA |
| IDE / language | Java (IntelliJ IDEA), class LabOne.java |
| Deadline | 29/10/2026, 23:59 |
Lab One of this first-year Java programming module checks the basics: reading input with Scanner, storing values in variables and making decisions with if and switch statements. Four short tasks build on each other, from a ball volume calculator and a race car physics program to a simple command calculator and a fever checker, with marks also given for comments and naming standards.
Assignment Instructions
This worksheet is to help you become familiar with the basics of:
- Variable assignment
- Scanner input
- Conditional statements
This worksheet is worth 6% of your CA. Submit before 23:59, 29/10/26.
- Create a project called CP_LabOne_number_name, with number being your student ID (e.g. CP_LabOne_1000323_Tom_Hanks).
- Add a package called griffith.
- Create a class called LabOne.java with your main method.
- Add all tasks in the one file, and add your student name and ID as a comment at the top of the file.
Task One (10 marks)
Write a program to get the volume and surface area of a ball.
- Ask a user to enter the diameter of a ball in cm.
- Print out the volume and surface area of the ball.
- Round your totals off to two decimal places.
Example: Enter the diameter of the ball in cm: 10 → The volume of the ball is: 523.6cm cubed; The surface area of the sphere is: 314.16cm squared.
Task Two (20 marks)
Write the code to test the properties of a race car.
- Ask the user to enter the mass (m) of a car, its initial velocity (u), acceleration (a) and the time taken to complete the track (t).
- Print out: the distance the car covered (d = u*t + 1/2*a*t²); the weight of the car (w = m*g), making gravity a constant; and the final velocity of the car (v = u + a*t).
Example: mass 1500 kg, initial velocity 10 m/s, acceleration 2 m/s², time 15 s → distance 375.0 metres; weight 14715.0 N; final velocity 40.0 m/s.
Task Three (25 marks)
Write a simple calculator program.
- Ask a user to enter an arithmetic command and two numbers (Commands: Add, Sub, Div – e.g. Add 1 4).
- Using a switch or if statements, print the result.
- For division, add a check for if the second number is 0.
- Check for any incorrect commands.
Examples: Add 6 7 → Result: 13.0; Sub 4 10 → Result: -6.0; Div 6 0 → Cannot divide by zero.
Task Four (25 marks)
Write a program to check for a fever.
- Ask a user to enter their age; anyone 12 or less is considered a child.
- Ask them to enter their temperature in Celsius.
- Using the table below, print out the appropriate temperature class using if statements or switch statements.
| Temperature class | Adults (°C) | Children (°C) |
| Lower than average | ≤ 35.9 | ≤ 36.4 |
| Normal | 36.0 – 37.0 | 36.5 – 37.5 |
| Higher than average | 37.1 – 38.0 | 37.5 – 38.4 |
| Fever | 38.1 – 42.2 | 38.5 – 42.2 |
Example: Enter your age: 20; Enter your temperature in C°: 38.2 → You have a Fever.
Comments and Coding Standards (10 marks)
- Include a comment at the top of the file with your name and student number.
- Add a comment for each task explaining what the code does.
- Follow coding standards: lowercase for variable names, uppercase for the class name, all uppercase for constants, and use naming standards.