[SOLVED] COMP90041 Lab 2-Floating point numbers

35.00 $

Programming resource
Digital learning resource
Category:
✓ Practical programming resource
✓ Suitable for guided study and reference
✓ Tutor guidance available when needed

Description

5/5 - (1 vote)

COMP90041 Programming and Software Development
Workshop Instructions
Introduction to Java programming
1.Write a program that reads two floating point numbers and print their sum, difference, and product.
2.Write a program that reads the radius of a sphere and prints its volume and surface area. Use the following formulas, where r represents the radius:
! ”
(a) Volume = “𝜋𝑟
(b) Surface Area = 4𝜋𝑟#
3. Write a program that calculates the total wages based on the number of hours worked. The wages are calculated at a rate of 8.25 per hour for hours less than 40 and at the rate of 1.5 the standard rate for any hours greater than 40. Number of hours is a command line argument to the program.

1. Hints for Problem 1:
• program syntax public class FloatPointCalculation { public static void main (String[] args) {
}
}

• reading from keyboard import java.util.Scanner;
Scanner scanner = new Scanner(System.in);

Page 1 of 2

• float point numbers float numberA; float numberB;

2. Hints for Problem 2: • radius
double radius;

• π value and cubic 𝑟” value
import java.lang.Math; double pi = Math.PI; double cubic = Math.pow(r, 3);

3. Hints for Problem 3:
• calculating wages if (hours < 40) { wages = hours * 8.25
} else { wages = 40 * 8.25 + (hours – 40) * 8.25 * 1.5;
}

• parsing command line arguments public static void main(String[] args) { int hours = Integer.parseInt(args[0]);
}

(a) cd to your .class directory and enter command line: java WageCaculator 45
replace WageCaculator with your class name

(b) in Eclipse: Select “Run Configurations …” (or “Debug Configurations …”) in “Run” menu, then create a new Java application configuration, finally in the “Arguments” tab of the created configuration, input the 45 in “Program arguments” box and click Run.

Page 2 of 2

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.