Read (hoursWorked) Read(payRate) grossPayßhoursWorked
* payRate
write (grossPay)
Algorithm
1. Write “Please input the number of hours worked”
2. Read hours
3. Write “Please input the pay per hour”
4. Read payRate
5. Compute grossPay=payRate * hours
6. Write “The grossPay is “ grossPay
import java.util.Scanner;
public class GrossPay {
/** This program will calculate grossPay by
* reading in hoursWorked and payrate and then
*
multiplying those values together to find gross pay
* Author:
Dean DeFino
*
Date: February 10, 2010
*/
public static
void main(String[] args) {
Scanner keyboard=new
Scanner(System.in);
System.out.print("Please
input the hours worked "); // Write
line 1
double hours; //
This variable contains the number of hours worked
double payRate; // This contains the pay per
hour
double grossPay; // This contains the gross pay
hours = keyboard.nextDouble(); // Read
line 2
System.out.print("Please
input the pay rate"); // Write line 3
payRate = keyboard.nextDouble(); // Read
line 4
grossPay = hours * payRate; //
Assignment line 5
System.out.println("The grossPay is "+ grossPay);
//Write line 6
}
}
Convert dollars
to Euros
eurosß dollars * exchangeRate
Read(dollars) Read (exchangeRate)
Write(euros) Write (dollars)
Algorithm
import java.util.Scanner;
public class DollarsToEurosConverter
{
/**This program
will convert the amount of dollars typed
* by the user to euros
*
Programmer: Dean DeFino
*
Date: September 16, 2014
*/
public static
void main(String[] args) {
Scanner keyboard=new Scanner(System.in);
double dollars;
double eurosPerDollar;
double euros;
System.out.print("How many dollars do you want to
convert? ");
dollars=keyboard.nextDouble();
System.out.print("What
is the euros-per-dollar exchange rate? ");
eurosPerDollar = keyboard.nextDouble();
euros=dollars * eurosPerDollar;
System.out.printf("%.2f dollars = %.2f euros",
dollars,euros);
}
}