Question
What's wrong with my Java program, when I try to compile it I get 6 errors. Employee_Salary_List.java package driver; public class Employee_Salary_List { String name;
What's wrong with my Java program, when I try to compile it I get 6 errors.
Employee_Salary_List.java
package driver;
public class Employee_Salary_List {
String name;
Employee_Salary_List()
{
name = "No name yet";
}
public Employee_Salary_List(String initialName)
{
name = initialName;
}
public void setName(String newName)
{
name = newName;
}
public String getName()
{
return name;
}
public void writeOutput()
{
System.out.println("Name: " + name);
}
public boolean hasSameName(Employee_Salary_List otherEmployee_Salary_List)
{
return this.name.equalsIgnoreCase(otherEmployee_Salary_List.name);
}
}
Employee.java
package driver;
// Class Employee
public class Employee extends Employee_Salary_List{
String SSN;
double salary;
// Constructor
Employee()
{
// Call constructor in Employee_Salary_List
super();
SSN="";
salary=0.0;
}
// Parametrized constructor
public Employee(String nam,String sn,double sal)
{
// Call parametrized constructor in Employee_Salary_List
super(nam);
setSSN(sn);
salary=sal;
}
public void setSSN(String sn)
{
int count=0;
// Check the length of SSN is 9 excluding space and dashes
for(int i=0;i
{
if(sn.charAt(i)!=' '&&sn.charAt(i)!='-')
count++;
}
try{
if(count!=9)
{
throw new SSNLengthException();
}
else
{
for(int i=0;i
{
if((sn.charAt(i)>'9' || sn.charAt(i)
{
// Check the characters other than space and dash is digit
if(sn.charAt(i)!=' ' && sn.charAt(i)!='-')
throw new SSNCharacterException();
}
}
SSN = sn;
}
}
catch(Exception ex){System.out.println(ex.getMessage());}
SSN=sn;
}
// Set salary
public void setSalary(double sal)
{
salary=sal;
}
// Set SSN
public String getSSN()
{
return SSN;
}
// Return the salary
public double getSalary()
{
return salary;
}
// Write output to console
public void writeOutput()
{
super.writeOutput();
System.out.println("SSN: " + SSN);
System.out.println("Salary: " + salary);
}
}
SSNLengthException.java
package driver;
class SSNLengthException extends Exception {
public SSNLengthException() {
System.out.println("Not valid length");
}
public SSNLengthException(String ms) {
super(ms);
}
}
SSNCharacterException.java
package driver;
class SSNCharacterException extends Exception {
public SSNCharacterException() {
System.out.println("Not digit");
}
public SSNCharacterException(String ms) {
super(ms);
}
}
Driver.java
package driver;
import java.util.Scanner;
public class Driver {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
Employee[] e=new Employee[100];
double avg;
double sum=0.0;
int count;
System.out.print("Enter the number of records: ");
count=sc.nextInt();
String name,ssn;
double salary;
// Read the values from user
for(int i=0;i
{
sc.nextLine();
System.out.print("Enter the name: ");
name=sc.nextLine();
System.out.print("Enter the SSN: ");
ssn=sc.nextLine();
System.out.print("Enter the salary: ");
salary=sc.nextDouble();
e[i]=new Employee(name,ssn,salary);
}
// Fimd the total salary
for(int i=0;i
{
sum=sum+e[i].getSalary();
}
// Find the average
avg=sum/count;
for(int i=0;i
{
// Check the salary is above and below average
if(e[i].getSalary()
{
System.out.println("Below average");
e[i].writeOutput();
}
else
{
System.out.println("Above average");
e[i].writeOutput();
}
System.out.println();
System.out.println();
}
}
}
Employee_Salary_List.java
package driver;
public class Employee_Salary_List {
String name;
Employee_Salary_List()
{
name = "No name yet";
}
public Employee_Salary_List(String initialName)
{
name = initialName;
}
public void setName(String newName)
{
name = newName;
}
public String getName()
{
return name;
}
public void writeOutput()
{
System.out.println("Name: " + name);
}
public boolean hasSameName(Employee_Salary_List otherEmployee_Salary_List)
{
return this.name.equalsIgnoreCase(otherEmployee_Salary_List.name);
}
}
Employee.java
package driver;
// Class Employee
public class Employee extends Employee_Salary_List{
String SSN;
double salary;
// Constructor
Employee()
{
// Call constructor in Employee_Salary_List
super();
SSN="";
salary=0.0;
}
// Parametrized constructor
public Employee(String nam,String sn,double sal)
{
// Call parametrized constructor in Employee_Salary_List
super(nam);
setSSN(sn);
salary=sal;
}
public void setSSN(String sn)
{
int count=0;
// Check the length of SSN is 9 excluding space and dashes
for(int i=0;i
{
if(sn.charAt(i)!=' '&&sn.charAt(i)!='-')
count++;
}
try{
if(count!=9)
{
throw new SSNLengthException();
}
else
{
for(int i=0;i
{
if((sn.charAt(i)>'9' || sn.charAt(i)
{
// Check the characters other than space and dash is digit
if(sn.charAt(i)!=' ' && sn.charAt(i)!='-')
throw new SSNCharacterException();
}
}
SSN = sn;
}
}
catch(Exception ex){System.out.println(ex.getMessage());}
SSN=sn;
}
// Set salary
public void setSalary(double sal)
{
salary=sal;
}
// Set SSN
public String getSSN()
{
return SSN;
}
// Return the salary
public double getSalary()
{
return salary;
}
// Write output to console
public void writeOutput()
{
super.writeOutput();
System.out.println("SSN: " + SSN);
System.out.println("Salary: " + salary);
}
}
SSNLengthException.java
package driver;
class SSNLengthException extends Exception {
public SSNLengthException() {
System.out.println("Not valid length");
}
public SSNLengthException(String ms) {
super(ms);
}
}
SSNCharacterException.java
package driver;
class SSNCharacterException extends Exception {
public SSNCharacterException() {
System.out.println("Not digit");
}
public SSNCharacterException(String ms) {
super(ms);
}
}
Driver.java
package driver;
import java.util.Scanner;
public class Driver {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
Employee[] e=new Employee[100];
double avg;
double sum=0.0;
int count;
System.out.print("Enter the number of records: ");
count=sc.nextInt();
String name,ssn;
double salary;
// Read the values from user
for(int i=0;i
{
sc.nextLine();
System.out.print("Enter the name: ");
name=sc.nextLine();
System.out.print("Enter the SSN: ");
ssn=sc.nextLine();
System.out.print("Enter the salary: ");
salary=sc.nextDouble();
e[i]=new Employee(name,ssn,salary);
}
// Fimd the total salary
for(int i=0;i
{
sum=sum+e[i].getSalary();
}
// Find the average
avg=sum/count;
for(int i=0;i
{
// Check the salary is above and below average
if(e[i].getSalary()
{
System.out.println("Below average");
e[i].writeOutput();
}
else
{
System.out.println("Above average");
e[i].writeOutput();
}
System.out.println();
System.out.println();
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started