Java polymorphism, abstract classes

profilejosecgb
assn5-cs2410-sp2016.pdf

CS 2410 – Spring 2016 Assignment #5

Introduction This assignment gives you an opportunity to use polymorphism, abstract classes and methods, and inheritance. General requirements In or der to r eceive full cr edit your code must follow appr opr iate class conventions Program overview You will create a simple GUI that will display a number of buttons. Depending on what the user clicks, you will then display some information to the user. Requirements Your program should implement the following

1. A GUI application with a JComboBox (drop down list) on the top and a JTextArea below for displaying output

2. Create an abstract class called Simpleton a. Include the following abstract methods

i. String getName(); ii. String doMath();

iii. String saySomethingSmart(); 3. Create an abstract class called Smarty

a. implement Simpleton b. Include the following methods

i. Non-abstract 1. getIQ()

ii. Abstract 1. getIncome()

4. Create additional classes a. HourlyWorker (works so many hours for so much pay per hour)

i. Uses Simpleton and Smarty (think about what that means first!) ii. Create an appropriate constructor based on needed info

iii. Create necessary data members iv. Overrides all necessary methods

1. Can do multiplication 2. Knows a lot about animals

v. Adds method 1. getHoursWorked

b. ContractWorker i. Uses Simpleton and Smarty

ii. Create an appropriate constructor based on needed info iii. Create necessary data members iv. Overrides all necessary methods

1. Can do division 2. Knows a lot about astronomy

v. Adds method 1. getContractsCompleted

c. Hobbit

i. Uses Simpleton ii. Create an appropriate constructor based on needed info

iii. Create necessary data members iv. Overrides all necessary methods

1. Can do addition 2. Knows a lot about gardening

v. Adds method 1. getCarrotsPicked

5. Create one main class to run the program a. Create single ArrayList that contains at least two instances of each class listed in step

#4 b. For each item selection in your drop down list, print the following. Note: don’t use the

toString() method. Print output based on the getter methods in the classes. Also, you should print info for each object instance that has the information available needed to print.

i. Math 1. Print name name and a math problem they can do.

ii. Income 1. Print name name and a calculation of much money they make

iii. Hours 1. Print name name and a statement of how many hours they worked

iv. IQ 1. Print name and a statement of of what their IQ is

v. Say 1. Print name and a statement of something smart they can say

vi. Carrots 1. Print name and a statement of how many carrots they picked

vii. Contracts 1. Print name and a statement of how many carrots they picked

c. Use a for-each loop to iterate through the ArrayList and print the appropriate information.

What/How To Turn In (READ THIS) Submit your files on Canvas according to class conventions Due: March 4, 2016