Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help correcting the following code: import java.util.*; //class Employee class Employee { //private members private String firstName; private String lastName; private String socialSecurityNumber; //constructor

Need help correcting the following code:

import java.util.*;

//class Employee class Employee { //private members private String firstName; private String lastName; private String socialSecurityNumber;

//constructor public Employee(String firstName, String lastName, String socialSecurityNumber) { this.firstName = firstName; this.lastName = lastName; this.socialSecurityNumber = socialSecurityNumber; }

//set method to set empNumber public void setSocialSecurityNumber(String socialSecurityNumber) { this.socialSecurityNumber = socialSecurityNumber; }

//set method to set firstName public void setFirstName(String firstName) { this.firstName = firstName; }

//set method to set lastName public void setLastName(String lastName) { this.lastName = lastName; }

//get method to return socialSecurityNumber public String getSocialSecurityNumber() { return this.socialSecurityNumber; }

//get method to return firstName public String getFirstName() { return this.firstName; }

//get method to return lastName public String getLastName() { return this.lastName; } }

class HourlyEmployee extends Employee { //private members private double hours; private double wage;

//constructor public HourlyEmployee(String firstName, String lastName, String socialSecurityNumber, double hours, double wage) { super(firstName, lastName, socialSecurityNumber); this.hours = hours; this.wage = wage; }

//get method to return hours public double getHours() { return this.hours = hours; }

//set method to set hours public void setHours(double hours) { if (hours >= 0 && hours

//get method to return wage public double getWage() { return this.wage = wage; }

//set method to set wage public void setWage(double wage) { if (wage >= 0) this.wage = wage; else this.wage = 0; }

//get method to return earning public double getEarning() { return this.wage * this.hours; }

//method to return String public String toString() { String e = String.format("%.2f", getEarning()); return "hourly employee: " + getFirstName() + " " + getLastName() + " " + "social security number: " + getSocialSecurityNumber() + " " + "hours: " + getHours() + " " + "wage: " + getWage() + " " + " " + "earnings: " + e; } }

//class Driver class Driver { //main method public static void main(String[] args) { //object of Scanner class Scanner sc = new Scanner(System.in);

//read a Employee Name System.out.print("Enter first name:"); String fname = sc.nextLine(); System.out.print("Enter last name:"); String lname = sc.nextLine();

//read a Employee social security number System.out.print("Enter social security number:"); String number = sc.nextLine();

System.out.print("Enter hours worked:"); double hours = sc.nextDouble();

System.out.print("Enter wage:"); double wage = sc.nextDouble();

//create an object HourlyEmployee he = new HourlyEmployee(fname, lname, number, hours, wage); //print information System.out.print(he); } }

image text in transcribed

Given the following was entered from the keyboard: Mazies Payner 633385740 455 22.5 you displayed: Enter-first=name:Enter:last=name:Enterssocialssecurity=number:Entershours:worked:Enter=wage:hourly=employee:-Mazie:Paynes socialsesecurity=number: 633385740 hours: 445.0 wage: 22.5=10 earnings: 1012.50 instead of: socialssecurity=number: 633385740 hours: 45.0= wage: 22.50=0 earnings: 1012.50 Failed 2 out of 2 test runs. Failed Test Run \#1 The contents of your standard output is incorrect. Highlight: Show Highlighted Only Expected Result: Your Code's Actual Result: Enter.first.name:Bobbid Enter. first. name: Bobbit Enter.last.name: Bentont Enter.last.name:Bentont Enter.social-security.number: 765-42-0092- Enter.hours.worked: 53+ Enter.hours - worked: 53 Enter-wage:15.8 Enter.wage:15.8 hourly-employee: Bobbi.Bentond hourly-employee: Bobbi-Bentont social.security number: 765420092+ social-security.number: 765420092 hours: 530.0 hours: 53. wage: 15.80 wage: 15.84 earnings: .837,4 earnings:-837. 4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions