I need to figure out how to call a method that is located in a different class. For example, I am trying to make a tax calculator that multiplies a payers income by a corporate rate. However, I cannot figure out how to call the income method. Nothing I have tried is working. Is there any chance you can guide me? I am just trying to make this equation work. Is there something else that is stopping this from working?

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter4: More Object Concepts
Section: Chapter Questions
Problem 15RQ
icon
Related questions
Question

I need to figure out how to call a method that is located in a different class. For example, I am trying to make a tax calculator that multiplies a payers income by a corporate rate. However, I cannot figure out how to call the income method. Nothing I have tried is working. Is there any chance you can guide me? I am just trying to make this equation work. Is there something else that is stopping this from working?

public class TaxCalculator {
double tax;
/**
* Creates a TaxCalculator using 2021-2022 tax rates;
public TaxCalculator() {
}
/**
* Calculates a tax payer's tax assuming they are a corporation.
*
@precondition payer != null AND payer.isCorporation ()==true
@postcondition none
@param payer the tax payer
public static final double corporaterate = 0.21;
*
*
*
public double calculatecaparate Income Tax(TaxPayer payer) {
tax = corporaterate income k
if (tax < 0) {
tax = 0;
return tax;
}
return tax;
}
Transcribed Image Text:public class TaxCalculator { double tax; /** * Creates a TaxCalculator using 2021-2022 tax rates; public TaxCalculator() { } /** * Calculates a tax payer's tax assuming they are a corporation. * @precondition payer != null AND payer.isCorporation ()==true @postcondition none @param payer the tax payer public static final double corporaterate = 0.21; * * * public double calculatecaparate Income Tax(TaxPayer payer) { tax = corporaterate income k if (tax < 0) { tax = 0; return tax; } return tax; }
9 public class Taxpayer {
private String name;
10
private int age;
private boolean isCorporation;
private double income;
11
12
13
14
150
16
17
18
19
20
21
22
23
24
25
260
27
28
29
30
31
32
33
340
35
36
37
380
39
40
41
420
43
44
45
460
47
48
49
500
51
52
53
540
55
56
57
/**
* Creates a new taxpayer.
E
* @precondition name != null AND !name.isEmpty() AND age >= 0
@postcondition getName()==name AND getAge()==age AND getIsBusiness ()=isBusiness
*
*
@param name the person or business' name
@param age the person's age (ignored if it is a business)
@param income the annual income
* @param isCorporation true if the taxpayer is a business, false otherwise
*
*
E
public Taxpayer (String name, int age, double income, boolean isCorporation) {
super();
this.name = name;
this.age = age;
this.isCorporation = isCorporation;
this.income = income;
}
/**
* Gets the name
@return the name
public String getName() {
return this.name;
}
/**
* Gets the age
E
@return the age
*/
public int getAge() {
return this.age;
}
/**
* Gets the taxpayer's annual income.
*
@return the taxpayer's annual income.
public double getIncome() {
return this.income;
}
Transcribed Image Text:9 public class Taxpayer { private String name; 10 private int age; private boolean isCorporation; private double income; 11 12 13 14 150 16 17 18 19 20 21 22 23 24 25 260 27 28 29 30 31 32 33 340 35 36 37 380 39 40 41 420 43 44 45 460 47 48 49 500 51 52 53 540 55 56 57 /** * Creates a new taxpayer. E * @precondition name != null AND !name.isEmpty() AND age >= 0 @postcondition getName()==name AND getAge()==age AND getIsBusiness ()=isBusiness * * @param name the person or business' name @param age the person's age (ignored if it is a business) @param income the annual income * @param isCorporation true if the taxpayer is a business, false otherwise * * E public Taxpayer (String name, int age, double income, boolean isCorporation) { super(); this.name = name; this.age = age; this.isCorporation = isCorporation; this.income = income; } /** * Gets the name @return the name public String getName() { return this.name; } /** * Gets the age E @return the age */ public int getAge() { return this.age; } /** * Gets the taxpayer's annual income. * @return the taxpayer's annual income. public double getIncome() { return this.income; }
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Math class and its different methods
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT