In JAVA •use JOptionPane (not Scanner) •Write a method called calcWage which tak
ID: 3698657 • Letter: I
Question
In JAVA
•use JOptionPane (not Scanner)
•Write a method called calcWage which takes two parameters:
•Hours worked
•Hourly Rate
calcWage will return the amount needed to be paid, by multiplying the hours worked by the hourly rate.
•Write a main method that asks the user for the number of hours they worked on 3 different days and their daily rate. Call calcWage to calculate the total wage. Use String.format to format the output. Use a LOOP!
•Add documentation comments to your methods and generate the Javadoc. Attach a screenshot of the Javadoc for your method.
Explanation / Answer
// INPUT USING A SCANNER
Firstly create a new eclipse project named SCANNER_INPUT_1
Add a main class (with main method)
Type (or copy/paste) code and then run the following program:
import java.util.scanner;
/*complete the program that prompts the user to enter two integers, then outputs the integer which is smaller and which is larger.
*/
public class main{
public static void main(String[] args) {
Scanner kbd= new Scanner(System.in);
// TODO: declare input 1 and input 2 as integers, each initailized to 0
// then declare mininput and maxinput as integer and initialized to 0 each
// prompt the user for the user for the first input value
//get the value of input input1 as user input, using the kdb Scanner
// then prompt the second value as input
// get the value of input2 as user input using the kdb Scanner
// set the mininput to the smaller of input1 and input2
minInput= Math.min(input1,input2);
// set the maxinput to the larger of input1 and input2
maxIput=Math.max(input1,input2);
//output the smaller integer
//output the larger integer
} // end main method
} // end main class
THEN TEST THE PROGRAM USING THE INPUTS:
1. 12 and 23, and
2. 23 and 12.
//INPUT USING AN INPUT DIALOG
now, write a program that implements input using more graphical dialog boxes.
create a new Eclipse project named SCANNER_INPUT_2
add a main class (with a main method)
Type (or copy/paste) code and then run the following program:
import javax.swing.JOptionPane;
public class Main{
public static void main(String[] args) {
String Input;
// TODO: declare input 1 and input 2 as integers, each initailized to 0
// then declare mininput and maxinput as integer and initialized to 0 each
// Get the value of input1 as user input using an input dialog
Input = JOptionPane.showInputDialog("Enter the first integer");
input2 = Integer.parseInt(Input);
// get the value of input2 as user input using an input dialog(using previous step as a guide)
//set mininput to the smaller of input1 and input2
minInput=Math.min(input1,input2);
//set maxinput to the larger of input1 and input2
maxInput=Math.max(input1,input2);
// using a message dialog ,output the smaller integer
JOptionPane.showMessageDialog("smaller number"+minInput);
// using a message dialog ,output the larger integer
JOptionPane.showMessageDialog("larger number"+maxInput);
} // end main method
} // end main class
now test the program using the inputs:
1. 12 and 23, and
2. 23 and 12
// CalcWage.java
// Employee.java
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.