Question
Please help correct the Java error below: Error: Exception in thread main java.lang.Error: Unresolved compilation problems: TaxNonExemptCustomer cannot be resolved to a type TaxExemptCustomerClass cannot
Please help correct the Java error below:
Error:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
TaxNonExemptCustomer cannot be resolved to a type
TaxExemptCustomerClass cannot be resolved to a type
at Program8.main(Program8.java:341)
Code:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Program8 {
public class OfficeCustomerClass {
private String nameElement;
private int id = 0;
private double billBalanceElement;
private String email;
public OfficeCustomerClass()
{
nameElement="";
id=0;
billBalanceElement=0;
email="";
}
public class TaxExemptCustomerClass extends OfficeCustomerClass{
private String taxLiabilityElement;
public TaxExemptCustomerClass()
{
super();
taxLiabilityElement= "";
}
public TaxExemptCustomerClass(String nameElement, int id, double billBalanceElement, String email,String taxLiabilityElement)
{
super(nameElement,id,billBalanceElement,email);
this.taxLiabilityElement = taxLiabilityElement;
}
public void settaxLiabilityElement(String taxLiabilityElement)
{
this.taxLiabilityElement = taxLiabilityElement;
}
public String gettaxLiabilityElement()
{
return taxLiabilityElement;
}
public String toString()
{
return (super.toString()+"\t"+taxLiabilityElement);
}
}
public class TaxNonExemptCustomer extends OfficeCustomerClass{
private double taxLiabilityElement;
public TaxNonExemptCustomer()
{
super();
taxLiabilityElement=0;
}
public TaxNonExemptCustomer(String nameElement, int id, double billBalanceElement, String email,double taxLiabilityElement)
{
super(nameElement,id,billBalanceElement,email);
settaxLiabilityElement(taxLiabilityElement);
}
public void settaxLiabilityElement(double taxLiabilityElement)
{
this.taxLiabilityElement = ((taxLiabilityElement*getbillBalanceElement())/100);
}
public double gettaxLiabilityElement()
{
return taxLiabilityElement ;
}
public String toString()
{
return(super.toString()+"\t"+taxLiabilityElement);
}
}
//
public OfficeCustomerClass(String nameElement, int id, double billBalanceElement, String email)
{
this.nameElement = nameElement;
this.id = id;
this.billBalanceElement = billBalanceElement;
this.email = email;
}
public void setnameElement(String nameElement)
{
this.nameElement = nameElement;
}
public void setId(int id)
{
this.id = id;
}
public void setbillBalanceElement(double billBalanceElement)
{
this.billBalanceElement = billBalanceElement;
}
public void setEmail(String email)
{
this.email = email;
}
public String getnameElement()
{
return nameElement;
}
public int getId()
{
return id;
}
public double getbillBalanceElement()
{
return billBalanceElement;
}
public String getEmail()
{
return email;
}
public String toString()
{
return (nameElement+"\t"+id+"\t"+billBalanceElement+"\t\t"+email);
}
}
public static void sort(OfficeCustomerClass customersObject[],int index)
{
int min;
for (int i = 0; i < index; i++)
{
min = i;
for (int j = i + 1; j < index; j++)
if (customersObject[j].getId() < customersObject[min].getId())
min = j;
if (min != i)
{
OfficeCustomerClass temp = customersObject[i];
customersObject[i] = customersObject[min];
customersObject[min] = temp;
}
}
}
public static void main(String[] args) throws FileNotFoundException {
OfficeCustomerClass customersObject[];
File file = new File("OfficeCustomerClass.txt");
Scanner fileScan = new Scanner(file);
int records;
records = Integer.parseInt(fileScan.nextLine());
customersObject = new OfficeCustomerClass[records];
int index = 0;
String nameElement = "", email = "", taxLiabilityElement = "";
int id = 0;
double bill = 0;
while (fileScan.hasNext() && index < records)
{
String line = fileScan.nextLine();
String words[] = line.split(" ");
try {
nameElement = words[0];
id = Integer.parseInt(words[1]);
bill = Double.parseDouble(words[2]);
email = words[3];
taxLiabilityElement = words[4];
double tax = Double.parseDouble(taxLiabilityElement);
customersObject[index] = new TaxNonExemptCustomer(nameElement, id, bill, email, tax);
index++;
} catch (NumberFormatException ex)
{
customersObject[index] = new TaxExemptCustomerClass(nameElement, id, bill, email, taxLiabilityElement);
index++;
}
}
fileScan.close();
sort(customersObject,index);
int page = 0;
int i = 0;
while (i < index) {
page++;
int j = 0;
System.out.println(" \t Office Supplies Inc \t Page : " + page);
System.out.println("Customer Name \t ID \t Bill balance \t email \t\t Tax Liability");
// displaying 2 records per page, change this to display the desired
// number of records per page
while (i < customersObject.length && j < 2) {
System.out.println(customersObject[i]);
i++;
j++;
}
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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