Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 1 [40%] Exercise 1A [15%] Create a class called Employee that implements Comparable for type Employee. The Employee class should be able to store

Exercise 1 [40%] Exercise 1A [15%] Create a class called Employee that implements Comparable for type Employee. The Employee class should be able to store role, name and salary of an employee. Role and name should be one word each, the salary a numerical value. The compareTo method should sort first by role, then name, then salary. Additionally override the toString method to print role, name and salary of that employee separated by a single space. Exercise 1B [10%] Create a class called EmployeeInput. This class should have a main() method. In the main method read one line of user input and split it into separate strings using one or more spaces. Use the first value as name, the second as role and the third as salary for creating a new Employee object. Add this employee to an ArrayList containing Employee objects. This should run in a loop until the program is terminated by the user. For example: Please enter name, role and salary of new employee. Sebastian JavaMan 1000000 Adding JavaMan Sebastian 1000000.0 to list of employees. Please enter name, role and salary of new employee. David GodOfThunder 2000000 Adding GodOfThunder David 2000000.0 to list of employees. Exercise 1C [15%] Add the following functionality: Detect if more or less than three values are entered by the user and print an error if this is the case Detect if the user enters a non-numerical value for salary and print an error if this is the case Detect if the user enters quit and if they do print the sorted list of employees and exit the loop For example: Please enter name, role and salary of new employee. Bob Builder None Please enter a number for salary. Please enter name, role and salary of new employee. Bob 10000000 Please check number of entries. Please enter name, role and salary of new employee. Alice Builder 10000000 Adding Builder Alice 1.0E7 to list of employees. Please enter name, role and salary of new employee. Bob Builder 10000 Adding Builder Bob 10000.0 to list of employees. Please enter name, role and salary of new employee. Ben Builder 100000 Adding Builder Ben 100000.0 to list of employees. Please enter name, role and salary of new employee. quit Added the following employees: [Builder Alice 1.0E7, Builder Ben 100000.0, Builder Bob 10000.0] Bye!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And Transact SQL

Authors: Lucy Scott

1st Edition

1974679985, 978-1974679980

More Books

Students also viewed these Databases questions

Question

1. Are my sources credible?

Answered: 1 week ago