wages.java
来自「Java 程序设计教程(第五版)EXAMPLESchap05源码」· Java 代码 · 共 39 行
JAVA
39 行
//********************************************************************
// Wages.java Author: Lewis/Loftus
//
// Demonstrates the use of an if-else statement.
//********************************************************************
import java.text.NumberFormat;
import java.util.Scanner;
public class Wages
{
//-----------------------------------------------------------------
// Reads the number of hours worked and calculates wages.
//-----------------------------------------------------------------
public static void main (String[] args)
{
final double RATE = 8.25; // regular pay rate
final int STANDARD = 40; // standard hours in a work week
Scanner scan = new Scanner (System.in);
double pay = 0.0;
System.out.print ("Enter the number of hours worked: ");
int hours = scan.nextInt();
System.out.println ();
// Pay overtime at "time and a half"
if (hours > STANDARD)
pay = STANDARD * RATE + (hours-STANDARD) * (RATE * 1.5);
else
pay = hours * RATE;
NumberFormat fmt = NumberFormat.getCurrencyInstance();
System.out.println ("Gross earnings: " + fmt.format(pay));
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?