Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help my output is coming out null for tax type and need it fixed asap. the instructions for that tax type are the following:

Please help my output is coming out null for tax type and need it fixed asap. the instructions for that tax type are the following:

The customers served by the office supply store are of two types: tax-exempt or non-tax-exempt. For a tax-exempt customer, the tax liability field on the file is the reason for the tax exemptions: education, non-profit, government, other (String). For a non-tax exempt customer, the tax liability field is the percent of tax that the customer will pay (numeric) based on the state where the customers business resides.

import java.io.IOException;

import java.net.URL;

import java.util.Scanner;

public class project5 {

public static void main(String[] arg) throws IOException {

Customers[] createdarray;

URL url;

url = new

URL("http://yoda.kean.edu/~pawang/CPS2231/program5_customers.txt");

Scanner scanner = new Scanner(url.openStream());

int num = scanner.nextInt();

createdarray = new Customers[num];

String name;

int id;

double balance;

String emails;

double taxrate;

String liability;

for (int i = 0; i < createdarray.length; i++) {

name = scanner.next();

id = scanner.nextInt();

balance = scanner.nextDouble();

emails = scanner.next();

if (scanner.hasNextDouble())

{

taxrate = scanner.nextDouble();

createdarray[i] = new nonTaxExmpte(name, id, balance, emails, taxrate);

}

else {

liability = scanner.next();

createdarray[i] = new TaxExmpte(name, id, balance, emails, liability);

}

}

print(createdarray);

// sort(createdarray);

}

private static void print(Customers[] createdarray) {

int pageCount = 1;

for (int i = 0; i < createdarray.length; i++) {

if(i%45==0){

System.out.println(" Best Office Supplies Inc. Customer Report Page "+pageCount++);

System.out.println("==========================================================================================================");

System.out.printf("%15s %10s %30s %15s %15s %15s", "Customer", "ID", "Email Address", "Balance", "Tax Type", "Tax Amount");

System.out.println();

System.out.println("==========================================================================================================");

}

Customers customer = createdarray[i];

System.out.format("%15s %10d %30s %15.02f %15s %15.02f", customer.getName(),

customer.getId(), customer.getemails(), customer.getBalance(), customer.getliability(), customer.gettaxrate());

System.out.println();

}

System.out.println("==========================================================================================================");

}

// print Customers

}

abstract class Customers implements Comparable {

private String name;

private int id;

private String emails;

private double balance;

private String liability;

private double liabilityD;

private double taxrate;

public Customers(String name, int id, double balance, String

emails) {

this.name = name;

this.id = id;

this.balance = balance;

this.emails = emails;

this.liability = liability;

this.liabilityD = liabilityD;

}

public String toString() {

return "Name " + name + " Id " + id + " Balance " + balance + " email " + emails;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public void setEmails(String emails) {

this.emails = emails;

}

public String getemails() {

return emails;

}

public double gettaxrate() {

return taxrate;

}

public double getliabilityD() {

return liabilityD;

}

public void settaxrate() {

this.taxrate = taxrate;

}

public double getBalance() {

return balance;

}

public void setBalance(double balance) {

this.balance = balance;

}

public String getliability() {

return liability;

}

public void setliabilty() {

this.liability = liability;

}

public int compareTo(Customers o)

{

if (this.getId() == o.getId())

return 0;

else if (this.getId() < o.getId())

return 900;

else

return 900;

}

}

class nonTaxExmpte extends Customers {

public nonTaxExmpte(String name, int id, double balance, String

email, double liability) {

super(name, id, balance, email);

this.liability = liability;

}

private double liability;

private double taxAmount = getBalance() * liability;

public String toString() {

return super.toString() + liability + taxAmount;

}

public double getliabilityD() {

return liability;

}

}

class TaxExmpte extends Customers {

public TaxExmpte(String name, int id, double balance, String emails,

String liability) {

super(name, id, balance, emails);

this.liability = liability;

}

private String liability;

public String toString() {

return super.toString() + liability;

}

public String getliability() {

return liability;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

More Books

Students also viewed these Databases questions

Question

Why did you want to work in HR?

Answered: 1 week ago