COMPUTING SUBJECT:

advertisement
COMPUTING SUBJECT:
PROGRAMMING
TYPE:
WORKING ASSIGNMENT
IDENTIFICATION:
CALCULATORTEST
COPYRIGHT:
Michael Claudius, 2012
REVISED BY:
Michael Claudius, 10th September 2012, BlueJ
LEVEL:
ELEMENTARY
DURATION:
1 hour
SIZE:
15 lines
OBJECTIVES:
System commands during keying in, main().
Loading, printing, calculations on numbers..
PREREQUISITES:
COMMANDS:
int <variable> =
Constructor and method
IDENTIFIKATION:
CALCULATORTEST/MC
Problem
To write a program which can make use of an utility class for reading in numbers and apply a
model class for calculations on these numbers.
Assignment 1
Create a new project TestCalculator.
Then from your teacher’s home page download the Keyboard file and save it in the project
folder.
Application class
We are to write an application using & testing objects of the class Calculator. Therefore we
introduce a new application class, TestCalculator with a special main method. The
TestCalculator class must first resemble the following template:
public static void main(String[] args)
{
Calculator calc = //call constructor do it yourself
//call printdata method doit yourself
}// main
}// Test
Assignment 2. Application class TestCalculator
In the TestCalculator project create a Java Class TestCalculator.
In main() in TestCalculator declare a new variable "calc" using the default constructor.
Save it. Compile it. Call the main() method.
Remark: Now you will get a compile – error like “Calculator is unknow”.
Why?
Tip: Find out how one can import a class from another project.
Assignment 3: Application class TestCalculator
In main use the object calc and the printData method to print out the calculations.
Call the main method.
Also try out to use findSum on three fixed numbers..
Assignment 4. Utility class Keyboard
In main() in TestCalculator read in 3 numbers using Keyboard class. Use constructions like
System.out.print("First number:");
int a = Keyboard.readInt();
Assignment 5. Create an object
In main() in TestCalculator declare a new variable "calc1" with the data read in and use the
printData method to print out the calculations.
Download