Tutorial Week 12 - Introduction to Java


Home


This tutorial is in the Unix lab.

Question 1

Problem Description

Write a Java program to calculate the area and perimeter of a rectangle. The area of a rectangle is its length multiplied by its width. The perimeter is the distance around the outside of the rectangle. The logic for the problem is specified below. The program/class name is Rectangle, so the file name must be Rectangle.java.

Multiplication in Java uses a "*" like in Basic.

Example Run

Length ? 10
Width ? 5
Area = 50
Perimeter = 30

Pseudo Code

Rectangle()
    Input length, width    area = length * width
    perimeter = (length + width) * 2
    Display area, perimeter
STOP

Data Dictionary

Name Data Type Description
area Integer The area of the rectangle
length Integer The length of the rectangle
perimeter Integer The length of the perimeter of the rectangle
width Integer The width of the rectangle

Question 2

Problem Description

A shop owner requires a program to calculate the GST payable on items purchased. The GST is one-tenth of the pre GST price. For example, if the pre-GST price was $100 then the GST is $10 and the price including GST is $110. The user is to input the pre-GST price and the program is to display the GST and the final price including GST.

Example Program Runs

Run
Pre GST Price ($) ? 100
GST = $10.00
Price Including GST = $110.00
Run
Pre GST Price ($) ? 5.50
GST = $0.55
Price Including GST = $6.05

Write a Java program for the above problem and type it in.

Question 3

Make sure you are up to date with your tutorials.


Written by Tim Whitfort.