I was doing the code as part of my lab tutorial. When I tried running the code, it doesn't work.
Line 68 has an error. Can help?
package t10;
import java.util.*;
class Employee
{
private String name;
private String title;
public void setName(String n)
{
name = n;
}
public void setTitle(String t)
{
title = t;
}
public String getDetails()
{
return "Name: " + name +
"\nTitle: " + title;
}
public Employee(String name, String title)
{
this.name = name;
this.title = title;
}
}
class Worker extends Employee
{
private int hour;
private double rate;
public void setHour(int h)
{
hour = h;
}
public void setRate(double r)
{
rate = r;
}
public double getSalary()
{
return (double) hour * rate;
}
public Worker(int h, double r, String name, String title)
{
super(name, title);
hour = h;
rate = r;
}
}
public class Q1
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
Worker w = new Worker();
System.out.println("Enter your name and title: ");
w.setName(scan.next());
w.setTitle(scan.next());
System.out.println("\nEnter number of hours: ");
w.setHour(scan.nextInt());
System.out.println("\nEnter the pay rate (in $): ");
w.setRate(scan.nextDouble());
System.out.println();
System.out.println(w.getDetails());
System.out.print("\nYour salary: $");
System.out.println(w.getSalary());
}
}