Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help on java H/W. Thanks I think the teacher wants me to add the jframe to

ID: 3828427 • Letter: N

Question

Need help on java H/W. Thanks

I think the teacher wants me to add the jframe to another class instead of having it all in one class but I don't know how to do that.

Here is the code for the previous assignemt, the one we have to update for this assignment.

import javax.swing.JOptionPane;

public class Income {

public static double calculateTax(double income)

{

double tax = 0;

if(income > 0 && ++income <= 6000){

tax = income * 0.1;

}

else if(income >= 6001 && ++income <= 27950){

tax = income * 0.15;

}

else if(income >= 27951 && ++income <= 67700){

tax = income * 0.27;

}

else if(income >= 67701 && ++income <= 141250){

tax = income * 0.30;

}

else if(income >= 141251 && ++income <= 307050){

tax = income * 0.35;

}

else if(income > 307050){

tax = income * (38.6/100);

}

return tax;

   }
  
  
  
public static void main(String args[]){
  
  
  
   double income;
  
   double tax = 0;
  
  
   income = Integer.valueOf(JOptionPane.showInputDialog("Please enter $ amount"));
  
   String result = "";
  
   if(income<=0)
  
   {
  
   result = "You entered an invalid $ amount.";
   }
  
   else
  
   tax = calculateTax(income);
  
   if(result == "")
  
   result = String.format("Tax owed $%.2f", tax);
  
   JOptionPane.showMessageDialog(null, result);
   }
           }

LAB ASSIGNMENTS Please focus on the "formatting" of your output. Make sure to prompt the user appropriately and round the output accordingly. UPDATE ASSIGNMENT 16 TASK 1 USE OBJECT ORIENTATED PROGRAMMING AND CLASS STRUCTURE TO COMPLETE THE TAX PROGRAM. USE GET and SET METHODS Create methods for each portion of the program that does the tax calculation. Use get/set method naming conventions where it applies Update Program: Allow the user to input dollar amount in a Option Pane.showInputDialog and output in option sage Dialog Program should not display error messages if the user presses the X or Cance button progra should display a JOptionPane OW essage Dialo box prompting the user. MAKE SURE PROGRAM S STILL BRC) KEN INTO INDIVIDUAL METHOD 1st Task: Write a program that computes a single filer's income tax burden.

Explanation / Answer

I have made changes to the program as you requested. I have written a seperate class which contains the logic for calculating tasks. Aslo I have used setters and getters methods to access the class variables. Here is the modified code.

==========================================

import javax.swing.JOptionPane;

class ComputeTax { // creating a separate class which contains logic for calculating tax.
double tax;

public void ComputeTax(){ // Using constructor to intialize variable tax
tax=0;
}
// Using setters and getters to access variables
public void setTax(double tax) {
this.tax = tax;
}
  
public double getTax() {
return tax;
}
// Your CalculateTax method comes here
public double calculateTax(double income)
{
if(income > 0 && ++income <= 6000){
setTax(income * 0.1); // Using setTax method to assign result
}
else if(income >= 6001 && ++income <= 27950){
setTax(income * 0.15); // Using setTax method to assign result
}
else if(income >= 27951 && ++income <= 67700){
setTax(income * 0.27); // Using setTax method to assign result
}
else if(income >= 67701 && ++income <= 141250){
setTax(income * 0.30); // Using setTax method to assign result
}
else if(income >= 141251 && ++income <= 307050){
setTax(income * 0.35); // Using setTax method to assign result
}
else if(income > 307050){
setTax(income * (38.6/100)); // Using setTax method to assign result
}
return tax;
}


}
      
public class Income{

   public static void main(String args[]){
  
double income;
  
double tax = 0;
       ComputeTax obj = new ComputeTax(); // Creating an object for the class ComputeTax
      
income = Integer.valueOf(JOptionPane.showInputDialog("Please enter $ amount"));
  
String result = "";
  
if(income<=0)
  
result = "You entered an invalid $ amount.";
  
else
  
tax = obj.calculateTax(income);
  
if(result == "")
  
result = String.format("Tax owed $%.2f", tax);
  
JOptionPane.showMessageDialog(null, result);
}
}

===============================

Compile the java program using comand javac Income.java and run the program using command java Income

You should get the same output as mentioned in the question.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote