THINK FIRST·CODE LATER

← All labs

Employee and Manager: inheritance

Problem

Write a class Employee with private name and salary (double), a constructor, getName(), getSalary(), a method raise(double percent) that increases the salary, and toString() returning name earns 2000.00.

Write Manager extending Employee with an extra field department. Its constructor calls super(...), and it overrides toString() to return name earns 3000.00 (department).

Payroll reads: name, salary, then manager name, manager salary, department. It raises both by 10% and prints the two objects, the manager first.

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below.

l14-1-data-1.txt

Ousmane 2000 Amina 3000 Sales
What your program must print for l14-1-data-1.txt
Amina earns 3300.00 (Sales)

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < l14-1-data-1.txt

Windows PowerShell does not understand <:

Get-Content l14-1-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.