PLEASE help me create Method in Java

Watch
cha0ticg00d
Badges: 2
Rep:
?
#1
Report Thread starter 1 year ago
#1
This is my first time Creating Methods in Java. I need to create THREE methods for this project. Help with ONE would be amazing for me to then reference from and create the other two, if you do not want to help with all three. I will post all 3 for you to choose and the code I have thus far. THANK YOU!!!

Modification One: Change the tax-calculation statement to a method call statement. 1. Currently the program calculates the taxpayer's tax by simply multiplying the gross pay times the tax rate. You need to replace this tax calculation statement with a statement that calls the method calculate Tax and passes the appropriate parameters to the method. You must pass three parameters to the calculate Tax method: (1) gross pay (type double), (2) tax rate (type double), and (3) type of taxpayer (type char).

Write the calculate Tax METHOD named calculate Tax. Place this method definition code below the main method of the existing program class. Include the modifier static in the method header.


Modification Two: Write the calculateNetPay method named calculate NetPay. Place this method definition code below the main method of the existing program class. Include the modifier static in the method header

The calculateNetPay method must: Take two parameters as input: (1) gross pay (type double), and (2) tax (type double). Calculate net pay by simply subtracting the tax amount from the gross pay. Return a result of type double, namely the calculated net pay for the pay period.

Modification Three: Write the getTaxpayer TypeName method. The getTaxpayer TypeName method must: Take one parameter as input, which is the taxpayer type as a value of type char. Determine the full name of the taxpayer type, either Weekly, Biweekly, or Monthly Return the full name of the taxpayer type as a string.

My Code for Reference:

//make sure have correct package modify next line
package lab03;

import javax.swing.*;

public class BasicMethodsLab {

public static void main( String args[] ) {

String grossPayStr; // Value entered by user; string type
String taxRateStr; // Value entered by user; string type
double grossPay; // The double form of the user-entered gross pay
double taxRate = 0; // The double form of the user-entered tax rate
double tax = 0; // The tax for the pay period
int resp = 0; // The user's response as to whether to continue

// Initialize the output string to the empty string
String outputStr = "";

while (true) {
// Read in gross pay from user as a string
grossPayStr = JOptionPane.showInputDialog("Ent er gross pay for the pay period");

// Convert from type String to type double
grossPay = Double.parseDouble(grossPayStr);

// Read in tax rate from user as a string
taxRateStr = JOptionPane.showInputDialog("Ent er tax rate as a percent");

// Convert from type String to type double
taxRate = Double.parseDouble(taxRateStr);

// Echo print the entered values
outputStr = outputStr + "Gross pay: " + grossPay + ", ";
outputStr = outputStr + "Tax rate: " + taxRate + ", ";

// Calculate tax for the pay period
tax = grossPay * (taxRate / 100.0);

// Print the tax
outputStr = outputStr + ", " + "Tax: " + tax + "\n";

// Determine whether the user wants to continue the loop
resp = JOptionPane.showConfirmDialog(nu ll, outputStr + "\nContinue?", "Confirm",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);

if (resp == JOptionPane.NO_OPTION)
break;
}

// Display final output to the user
JOptionPane.showMessageDialog(
null, outputStr, "Final Results", JOptionPane.INFORMATION_MESSAGE) ;


}
}
Last edited by cha0ticg00d; 1 year ago
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

Have you experienced financial difficulties as a student due to Covid-19?

Yes, I have really struggled financially (60)
17.44%
I have experienced some financial difficulties (96)
27.91%
I haven't experienced any financial difficulties and things have stayed the same (132)
38.37%
I have had better financial opportunities as a result of the pandemic (45)
13.08%
I've had another experience (let us know in the thread!) (11)
3.2%

Watched Threads

View All