Question: How would i get this code to display graphical user interface ( GUI ) using JOptionPane. ive been trying to do it but when i

How would i get this code to display graphical user interface (GUI) using JOptionPane. ive been trying to do it but when i try to display the outputs like the tax information and calculations but for the tax inforamtion it gives me zeros and for the names after putting it into the GUI and gives me the output it shows up as null. or now just gives me a blank screen with no information.

(Original Code)

import java.util.Scanner;

import javax.swing.JOptionPane;

// class TaxCalculation definition

public class TaxCalculation

{

// Scanner class object created Scanner sc = new Scanner(System.in); // Instance variable declaration String firstName, lastName; String SSN; String houseNumber, street, city, state, zipCode; double grossIncome; int incomeBracket; double federalIncomeTax; double NYStateTax, NYCLocalCityTax, NYCSSTax, NYCMedicareTax, NYCUnemployTax; // Method to accept employee data void acceptEmployeeData() { JOptionPane.showMessageDialog(null,"2016 Income Tax Filling Data - prepared by: J21 Rodelyn Polanco" +" Enter all your in the information that is asked. Do not space out the city, State or street for example: " + " Street: Valleyrd, City: PortWashington, State: NewYork"); // Accepts data from the user System.out.print(" Enter first name: "); firstName = sc.next(); System.out.print(" Enter last name: "); lastName = sc.next(); System.out.print(" Enter SSN: "); SSN = sc.next(); System.out.print(" Enter Address Infog "); System.out.print(" Enter House Number: "); houseNumber = sc.next(); System.out.print(" Enter Street: "); street = sc.next(); System.out.print(" Enter City: "); city = sc.next(); System.out.print(" Enter State: "); state = sc.next(); System.out.print(" Enter Zip code: "); zipCode = sc.next(); System.out.print(" Enter 2016 gross income: "); grossIncome = sc.nextDouble(); // Closes the scanner class //sc.close(); }// End of method

// Method to calculate tax

void calculateTax() { // Checks if gross income is less than or equals to 9325

if(grossIncome <= 9325) { // Set the income bracket to 1 incomeBracket = 1; // Calculate 10% of gross income plus 0 as federal tax federalIncomeTax = grossIncome * .1 + 0; }// End of if condition // Otherwise checks if gross income is less than or equals to 37950 else if(grossIncome <= 37950) { // Set the income bracket to 2 incomeBracket = 2; /* * Calculate 10% of gross income plus 0 for up to 9325 and adds it with * extra income above 9325 by deduction it from gross income * Calculates 15% on above 9325 and adds 933 as federal tax */ federalIncomeTax = (grossIncome * .1 + 0) + ((grossIncome - 9325) * .15 + 933);

}// End of else if condition

// Otherwise checks if gross income is less than or equals to 91900

else if(grossIncome <= 91900) { // Set the income bracket to 3 incomeBracket = 3; /* * Calculate 10% of gross income plus 0 for up to 9325 and adds it with * Calculates 15% of gross income plus 933 for up to 37950 and adds it with * Calculates 25% of extra income on above 37950 and adds 5226 as federal tax */ federalIncomeTax = (grossIncome * .1 + 0) + ((grossIncome - 9325) * .15 + 933) + ((grossIncome - 37950) * .25 + 5226); }// End of else if condition // Otherwise checks if gross income is less than or equals to 919650 else if(grossIncome <= 191650) { // Set the income bracket to 4 incomeBracket = 4; /* * Calculate 10% of gross income plus 0 for up to 9325 and adds it with * Calculates 15% of gross income plus 933 for up to 37950 and adds it with * Calculates 25% of gross income plus 5226 for up to 91900 and adds it with * Calculates 28% of extra income on above 91900 and adds 18714 as federal tax */ federalIncomeTax = (grossIncome * .1 + 0) + ((grossIncome - 9325) * .15 + 933) + ((grossIncome - 37950) * .25 + 5226) + ((grossIncome - 91900) * .28 + 18714);

}// End of else if condition

// Otherwise checks if gross income is less than or equals to 416700

else if(grossIncome <= 416700) { // Set the income bracket to 5 incomeBracket = 5; /* * Calculate 10% of gross income plus 0 for up to 9325 and adds it with * Calculates 15% of gross income plus 933 for up to 37950 and adds it with * Calculates 25% of gross income plus 5226 for up to 91900 and adds it with * Calculates 28% of gross income plus 18714 for up to 191650 and adds it with * Calculates 33% of extra income on above 191650 and adds 46644 as federal tax */ federalIncomeTax = (grossIncome * .1 + 0) + ((grossIncome - 9325) * .15 + 933) + ((grossIncome - 37950) * .25 + 5226) + ((grossIncome - 91900) * .28 + 18714) + ((grossIncome - 191650) * .33 + 46644);

}// End of else if condition

// Otherwise checks if gross income is less than or equals to 418400 else if(grossIncome <= 418400) { // Set the income bracket to 6 incomeBracket = 6; /* * Calculate 10% of gross income plus 0 for up to 9325 and adds it with * Calculates 15% of gross income plus 933 for up to 37950 and adds it with * Calculates 25% of gross income plus 5226 for up to 91900 and adds it with * Calculates 28% of gross income plus 18714 for up to 191650 and adds it with * Calculates 33% of gross income plus 46644 for up to 416700 and adds it with * Calculates 35% of extra income on above and adds 120910 as federal tax */ federalIncomeTax = (grossIncome * .1 + 0) + ((grossIncome - 9325) * .15 + 933) + ((grossIncome - 37950) * .25 + 5226) + ((grossIncome - 91900) * .28 + 18714) + ((grossIncome - 191650) * .33 + 46644) + ((grossIncome - 416700) * .35 + 120910); } // End of else if condition // Otherwise above 418400

else

{ // Set the income bracket to 7 incomeBracket = 7; /* * Calculate 10% of gross income plus 0 for up to 9325 and adds it with * Calculates 15% of gross income plus 933 for up to 37950 and adds it with * Calculates 25% of gross income plus 5226 for up to 91900 and adds it with * Calculates 28% of gross income plus 18714 for up to 191650 and adds it with * Calculates 33% of gross income plus 46644 for up to 416700 and adds it with * Calculates 35% of gross income plus 120910 for up to 418400 and adds it with * Calculates 40% of extra income on above and adds 121500 as federal tax */ federalIncomeTax = (grossIncome * .1 + 0) + ((grossIncome - 9325) * .15 + 933) + ((grossIncome - 37950) * .25 + 5226) + ((grossIncome - 91900) * .28 + 18714) + ((grossIncome - 191650) * .33 + 46644) + ((grossIncome - 416700) * .35 + 120910) + ((grossIncome - 418400) * .4 + 121500);

}// End of else // Calculates 6.45% of gross income as NY State Tax NYStateTax = grossIncome * 0.0645; // Calculates 3.59% of gross income as NYC Local City Tax NYCLocalCityTax = grossIncome * 0.0359; // Calculates 6.25% of gross income as NYC SS Tax NYCSSTax = grossIncome * 0.0625; // Calculates 1.45% of gross income as NYC Medicare Tax NYCMedicareTax = grossIncome * 0.0145; // Calculates 4% of gross income as NYC Unemployment Tax NYCUnemployTax = grossIncome * 0.04;

}// End of method

// Method to display employee information with tax

void displayTax()

{

System.out.println(" \t2016 INCOME TAX FILLING DATA"); System.out.println("Tax payer name: " + lastName + ", " + firstName); System.out.println("SSN: " + SSN); System.out.println("Address: " + houseNumber + " "+ street + ", " + city + ", " + state + ", " + zipCode); System.out.printf("2016 Taxable Income: $%5.2f", grossIncome); System.out.printf(" Federal Tax : $%5.2f ", federalIncomeTax); System.out.printf("\t\t Income bracket: %d", incomeBracket); System.out.printf(" NYS tax: $%5.2f", NYStateTax); System.out.printf(" Local tax: $%5.2f", NYCLocalCityTax); System.out.printf(" SS tax: $%5.2f", NYCSSTax); System.out.printf(" Medical: $%5.2f", NYCMedicareTax); System.out.printf(" Unemployment: $%5.2f", NYCUnemployTax); System.out.printf(" TOTAL NYS TAX: $%5.2f ", (NYStateTax + NYCLocalCityTax + NYCSSTax + NYCMedicareTax + NYCUnemployTax));

}// End of method

// main method definition

public static void main(String[] args)

{ boolean flag = true; String s1 = null;

while(flag)

{

// TaxCalculation class object created TaxCalculation tc = new TaxCalculation(); // Calls the method to accept data tc.acceptEmployeeData(); // Calls the method to calculate tax tc.calculateTax(); // Calls the method to display information tc.displayTax(); System.out.println("Do you want to continue (yes/no) :"); tc.sc.nextLine(); s1 = tc.sc.nextLine(); if(s1.equalsIgnoreCase("yes")) flag = true; else flag = false;

} JOptionPane.showMessageDialog(null,"End Of Job"); }// End of main method

}// End of class

(Code with GUI attemted)

import java.util.Scanner;

import javax.swing.JOptionPane;

// class TaxCalculation definition

public class TaxCalculationGUI

{

// Scanner class object created

Scanner sc = new Scanner(System.in);

// Instance variable declaration

String firstName, lastName;

String SSN;

String houseNumber, street, city, state, zipCode;

double grossIncome;

int incomeBracket;

double federalIncomeTax;

double NYStateTax, NYCLocalCityTax, NYCSSTax, NYCMedicareTax, NYCUnemployTax;

// Method to accept employee data

void acceptEmployeeData()

{

JOptionPane.showMessageDialog(null,"2016 Income Tax Filling Data - prepared by: J21 Rodelyn Polanco"

+" Enter all your in the information that is asked. Do not space out the city, State or street for example: "

+ " Street: Valleyrd, City: PortWashington, State: NewYork");

// Accepts data from the user

String int1 = " Enter first name: ";

String int2 = "Enter last name: ";

String int3 = "Enter SSN: ";

String int4 = " Enter Address Info" ;

String int5 = "Enter House Number: ";

String int6 = "Enter Street: ";

String int7 = "Enter City: ";

String int8 = "Enter State: ";

String int9 = "Enter Zip code: ";

String int10 = "Enter 2016 gross income: ";

String inputValue = JOptionPane.showInputDialog(int1);

String inputValu = JOptionPane.showInputDialog(int2);

int n3 = Integer.parseInt(JOptionPane.showInputDialog(int3));

JOptionPane.showMessageDialog(null, int4);

int n5 = Integer.parseInt(JOptionPane.showInputDialog(int5));

String inputVal = JOptionPane.showInputDialog(int6);

String inputVa = JOptionPane.showInputDialog(int7);

String inputV= JOptionPane.showInputDialog(int8);

int n9 = Integer.parseInt(JOptionPane.showInputDialog(int9));

int n10 = Integer.parseInt(JOptionPane.showInputDialog(int10));

// Closes the scanner class

//sc.close();

}// End of method

// Method to calculate tax

void calculateTax()

{

// Checks if gross income is less than or equals to 9325

if(grossIncome <= 9325)

{

// Set the income bracket to 1

incomeBracket = 1;

// Calculate 10% of gross income plus 0 as federal tax

federalIncomeTax = grossIncome * .1 + 0;

}// End of if condition

// Otherwise checks if gross income is less than or equals to 37950

else if(grossIncome <= 37950)

{

// Set the income bracket to 2

incomeBracket = 2;

/*

* Calculate 10% of gross income plus 0 for up to 9325 and adds it with

* extra income above 9325 by deduction it from gross income

* Calculates 15% on above 9325 and adds 933 as federal tax

*/

federalIncomeTax = (grossIncome * .1 + 0) + ((grossIncome - 9325) * .15 + 933);

}// End of else if condition

// Otherwise checks if gross income is less than or equals to 91900

else if(grossIncome <= 91900)

{

// Set the income bracket to 3

incomeBracket = 3;

/*

* Calculate 10% of gross income plus 0 for up to 9325 and adds it with

* Calculates 15% of gross income plus 933 for up to 37950 and adds it with

* Calculates 25% of extra income on above 37950 and adds 5226 as federal tax

*/

federalIncomeTax = (grossIncome * .1 + 0) + ((grossIncome - 9325) * .15 + 933) +

((grossIncome - 37950) * .25 + 5226);

}// End of else if condition

// Otherwise checks if gross income is less than or equals to 919650

else if(grossIncome <= 191650)

{

// Set the income bracket to 4

incomeBracket = 4;

/*

* Calculate 10% of gross income plus 0 for up to 9325 and adds it with

* Calculates 15% of gross income plus 933 for up to 37950 and adds it with

* Calculates 25% of gross income plus 5226 for up to 91900 and adds it with

* Calculates 28% of extra income on above 91900 and adds 18714 as federal tax

*/

federalIncomeTax = (grossIncome * .1 + 0) + ((grossIncome - 9325) * .15 + 933) +

((grossIncome - 37950) * .25 + 5226) + ((grossIncome - 91900) * .28 + 18714);

}// End of else if condition

// Otherwise checks if gross income is less than or equals to 416700

else if(grossIncome <= 416700)

{

// Set the income bracket to 5

incomeBracket = 5;

/*

* Calculate 10% of gross income plus 0 for up to 9325 and adds it with

* Calculates 15% of gross income plus 933 for up to 37950 and adds it with

* Calculates 25% of gross income plus 5226 for up to 91900 and adds it with

* Calculates 28% of gross income plus 18714 for up to 191650 and adds it with

* Calculates 33% of extra income on above 191650 and adds 46644 as federal tax

*/

federalIncomeTax = (grossIncome * .1 + 0) + ((grossIncome - 9325) * .15 + 933) +

((grossIncome - 37950) * .25 + 5226) + ((grossIncome - 91900) * .28 + 18714) +

((grossIncome - 191650) * .33 + 46644);

}// End of else if condition

// Otherwise checks if gross income is less than or equals to 418400

else if(grossIncome <= 418400)

{

// Set the income bracket to 6

incomeBracket = 6;

/*

* Calculate 10% of gross income plus 0 for up to 9325 and adds it with

* Calculates 15% of gross income plus 933 for up to 37950 and adds it with

* Calculates 25% of gross income plus 5226 for up to 91900 and adds it with

* Calculates 28% of gross income plus 18714 for up to 191650 and adds it with

* Calculates 33% of gross income plus 46644 for up to 416700 and adds it with

* Calculates 35% of extra income on above and adds 120910 as federal tax

*/

federalIncomeTax = (grossIncome * .1 + 0) + ((grossIncome - 9325) * .15 + 933) +

((grossIncome - 37950) * .25 + 5226) + ((grossIncome - 91900) * .28 + 18714) +

((grossIncome - 191650) * .33 + 46644) + ((grossIncome - 416700) * .35 + 120910);

} // End of else if condition

// Otherwise above 418400

else

{

// Set the income bracket to 7

incomeBracket = 7;

/*

* Calculate 10% of gross income plus 0 for up to 9325 and adds it with

* Calculates 15% of gross income plus 933 for up to 37950 and adds it with

* Calculates 25% of gross income plus 5226 for up to 91900 and adds it with

* Calculates 28% of gross income plus 18714 for up to 191650 and adds it with

* Calculates 33% of gross income plus 46644 for up to 416700 and adds it with

* Calculates 35% of gross income plus 120910 for up to 418400 and adds it with

* Calculates 40% of extra income on above and adds 121500 as federal tax

*/

federalIncomeTax = (grossIncome * .1 + 0) + ((grossIncome - 9325) * .15 + 933) +

((grossIncome - 37950) * .25 + 5226) + ((grossIncome - 91900) * .28 + 18714) +

((grossIncome - 191650) * .33 + 46644) + ((grossIncome - 416700) * .35 + 120910) +

((grossIncome - 418400) * .4 + 121500);

}// End of else

// Calculates 6.45% of gross income as NY State Tax

NYStateTax = grossIncome * 0.0645;

// Calculates 3.59% of gross income as NYC Local City Tax

NYCLocalCityTax = grossIncome * 0.0359;

// Calculates 6.25% of gross income as NYC SS Tax

NYCSSTax = grossIncome * 0.0625;

// Calculates 1.45% of gross income as NYC Medicare Tax

NYCMedicareTax = grossIncome * 0.0145;

// Calculates 4% of gross income as NYC Unemployment Tax

NYCUnemployTax = grossIncome * 0.04;

// End of method

// Method to display employee information with tax

}

void displayTax()

{

System.out.println(" \t2016 INCOME TAX FILLING DATA");

JOptionPane.showMessageDialog(null, "Tax payer name: " + lastName + ", " + firstName

+ "SSN: " + SSN

+ "Address: " + houseNumber + " "+ street + ", " + city + ", " + state + ", " + zipCode

+ "2016 Taxable Income: " + grossIncome

+ " Federal Tax : " + federalIncomeTax

+ "\t\t Income bracket: " + incomeBracket

+ " NYS tax: " + NYStateTax

+ " Local tax: " + NYCLocalCityTax

+ " SS tax: " + NYCSSTax

+ " Medical: " + NYCMedicareTax

+ " Unemployment: " + NYCUnemployTax

+ " TOTAL NYS TAX: " + (NYStateTax + NYCLocalCityTax + NYCSSTax + NYCMedicareTax + NYCUnemployTax));

System.out.println(" \t2016 INCOME TAX FILLING DATA");

System.out.println("Tax payer name: " + lastName + ", " + firstName);

System.out.println("SSN: " + SSN);

System.out.println("Address: " + houseNumber + " "+ street + ", " + city + ", " + state + ", " + zipCode);

System.out.printf("2016 Taxable Income: $%5.2f", grossIncome);

System.out.printf(" Federal Tax : $%5.2f ", federalIncomeTax);

System.out.printf("\t\t Income bracket: %d", incomeBracket);

System.out.printf(" NYS tax: $%5.2f", NYStateTax);

System.out.printf(" Local tax: $%5.2f", NYCLocalCityTax);

System.out.printf(" SS tax: $%5.2f", NYCSSTax);

System.out.printf(" Medical: $%5.2f", NYCMedicareTax);

System.out.printf(" Unemployment: $%5.2f", NYCUnemployTax);

System.out.printf(" TOTAL NYS TAX: $%5.2f ", (NYStateTax + NYCLocalCityTax + NYCSSTax + NYCMedicareTax + NYCUnemployTax));

}// End of method

// main method definition

public static void main(String[] args)

{

boolean flag = true;

String s1 = null;

int ans;

while(flag)

{

// TaxCalculation class object created

TaxCalculationGUI tc = new TaxCalculationGUI();

// Calls the method to accept data

tc.acceptEmployeeData();

// Calls the method to calculate tax

tc.calculateTax();

// Calls the method to display information

tc.calculateTax();

tc.sc.nextLine();

s1 = tc.sc.nextLine();

ans = JOptionPane.showConfirmDialog(null,"Calcuate more tax report?",

"Click Yes or No:", JOptionPane.YES_NO_OPTION);

if (ans == JOptionPane.YES_OPTION) continue;

else {

JOptionPane.showMessageDialog(null,"End Of Job");

flag = false;

System.exit(0);

}

}// End of main method

}

}

// End of class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!