[Solved]Create Java Class File Named Paycalculatorjava Main Method Add Following Methods Class Pub Q37297842
Create a Java Class file named PayCalculator.java with a main()method. Add the following methods to your class:
- public static String getName() { } prompts the user for theirname using JOptionPane.showInputDialog() and returns the name.
- You will call this method from main() and “catch” the returnedString variable. For debugging purposes, print the name to theconsole using the method System.out.println()
- public static double getHours() { } prompts the user for thenumber of hours worked using JOptionPane.showInputDialog(),converts the value to a number, and returns the hours worked.
- You will call this method from main() and “catch” the returneddouble variable. For debugging purposes, print the hours worked tothe console using the method System.out.println()
- public static double getRate() { } prompts the user for theirpay rate using JOptionPane.showInputDialog(), converts the value toan number, and returns the pay rate.
- You will call this method from main() and “catch” the returneddouble variable. For debugging purposes, print the hourly pay rateto the console using the method System.out.println()
- public static double getBonus() { }asks the user if they workedon a holiday using
- JOptionPane.showConfirmDialog(). If they click OK (true), thenit returns 50.0. Otherwise, it returns 0.0. Example shown in thebox above .
- You will call this method from main() and “catch” the returneddouble variable. For debugging purposes, print the bonus to theconsole using the method System.out.println()
- public static double calcTotal(double hours, double rate,double bonus) { }takes hours, rate, and bonus as parameters. Themethod should use those three values to calculate the total, andthen return the total.
- You will call this method from main() and “catch” the returneddouble variable. For debugging purposes, print the bonus to theconsole using the method System.out.println()
- public static void displayResults(String name, double total) {} takes the name and the total as parameters, and displays“Name, you earned total.” in aJOptionPane.showMessageDialog() box.
- You will call this method from main() and there will not be areturn value so there is no need to “catch” the returnedvalue.
- By the end of the program public static void main(String[]args) { } should:
- Call getName() and assign the result to a variable
- Call getHours() and assign the result to a variable
- Call getRate() and assign the result to a variable
- Call getBonus() and assign the result to a variable
- Pass hours, rate, and bonus to thecalcTotal(hours,rate,bonus)
method, and return the result to a variable - Pass name and total to displayResults(name,total)
This is one whole java program and here is what I got. Pleaseadd comment so I can understand
import javax.swing.JOptionPane;
public class PayCalculator {
public static void main(String[] args) {
//call gethours
doublehours=PayCalculator.getHours();
System.out.println(hours);
//cal usre name
String name=getName();
System.out.println(name);
//call getBonjs
double Bonus= getBonus();
System.out.println(Bonus);
}// end of main
public static String getName() {
return
JOptionPane.showInputDialog(null,”Enter your name”);
}// end of getname
public static double getBonus() {
int holiday=JOptionPane.showConfirmDialog(null, “Did you workedHoliday?”);
if (holiday==0) {
return50.0;
}
else {
return0.0;
}
}
public static double getRate() {
String payRate=
JOptionPane.showInputDialog (null, “Enter yourname”);
return payRate;
}//end of get rate
public static double getHours() {
String strHours=
JOptionPane.showInputDialog(null, “Enter hoursworked”);
returnDouble.parseDouble(strHours);
}//end of
}//end of class
Expert Answer
Answer to Create a Java Class file named PayCalculator.java with a main() method. Add the following methods to your class: public … . . .
OR

