You are on page 1of 2

CPSC6548 - Lab Assignment #5: Creating and Using Methods in Classes

Date Assigned: Week 5 Date Due: Week 6 Points: 40

Write a Java application called CalcApp (with a main() method), and an additional class called
Calculator. The Calculator class will be an engine with many methods (some overloaded from
others) to perform various arithmetic and calculating tasks. You can instantiate one object in
main() to perform all of the functions by calling for example:

Calculator calcEngine = new Calculator();

Then, subsequently call the functions listed below such as calcEngine.table(10,10),


calcEngine.table(3.0,2), calcEngine.primes(), etc. as the task to perform from the menu
selection in a switch() statement.

Alternatively, you can put main() into the class, but a separate application class with main() is
recommended. All methods you create should start with lowercase, except the constructors.

The Calculator class will:

1. Have necessary constructor methods, in addition to the default constructor (0 argument


constructor). The constructor is a function (method) which allocates memory and initializes
member variables. Encapsulate data members (member variables) as needed.
2. Include getters/setters for to serve as mutators (setters) and accessors (getters) as needed for each
variable.
3. Create the following member methods for the class:
a. A Multiplication Table method called void table(int, int) which takes as parameters, rows
and columns, nicely formatted with headings, using printf().
b. Overload the void table(double, int) function and create an Exponentiation Table which
takes as parameters, rows and columns (which would be the base and exponent).
c. You can have the table() function call other functions which you create called multiply(n, n)
or power(n, e)
d. A member method called void primes(void) which generates the first 10 prime numbers,
nicely formatted using printf().
e. An overload of primes called void primes(int) which accepts a value inputted from the user
in main() (up to 50) and generates that number of primes, nicely formatted with printf()
f. A method called void circle(void) which prompts the user for the radius and displays the
area and circumference of a circle.
g. A method called double stats(int n) which prompts the user to enter n (1-10) values and
returns the mean (average) of the values.
h. An overload of stats() called void stats() which generates 10 random numbers and displays
the mean and sum of the values.
i. A method called void ascii() which takes the start and end values validated in main() and
generates a table with the following columns:
Character Int Value Octal Value Hex Value Binary Value

The void ascii() method will need to call a method you create called binary() to generate a
binary number from the ASCII code.

j. A void conversion() method with a menu which will prompt the user to convert an
inputted value from the following list of options:
 volume (CI to CC)
 length (feet to meters)
 weight (lbs to kg)
 temperature (F to C).

The Java application class (with a main method) will:


a. Create a menu of options for the user to enter a char value for input (1..9, a..d) as such:

Welcome to the Calculator Program!

1. Create Multiplication Table (up to 10x10)


2. Create Exponentiation Table (up to 5x5)
3. Show the first 10 prime numbers
4. Show a list of prime numbers (up to 50)
5. Find the area and circumference of a circle (provide diameter)
6. Generate statistics for a list of inputted values (up to 10), including mean, and sum
7. Generate statistics for a list of random values (up to 10), including mean, and sum
8. Generate a table showing ASCII values for a range (validated between 32 and 126)
9. Conversion of
a. Cubic Inches to Cubic Centimeters
b. Feet to Meters
c. Pounds to Kilograms
d. Fahrenheit to Celsius:

Please enter your selection:

Required Output: Generate output samples demonstrating all of your member functions,
adequately testing them and showing their functionality (i.e. inputting values, outputting
values (displaying them), performing calculations, etc.).

You might also like