我一直在尝试编写一个Java程序来根据每天的工作时间来计算日薪。如果是周末或否。 (布尔值) 用户需要写的时间是0824,等于08:24(不知道如何要求小时:分钟模式并将其减去)。 我一直只使用一个循环一次又一次要求每小时付款一次,如果用户放置的值低于28.00 $或高于100.00 $ 当要求付款PerHour之后运行的程序未显示时,程序停止。 将不胜感激。谢谢! :) (不要注意班级名称)
package ouzanFirstProject;
import java.util.Scanner;
public class convertDecToBinary {
public static void main(String[] args) {
Scanner in= new Scanner(System.in);
int paymentPerHour , entryHour = 0 , exitHour = 0;
float totalHour= (exitHour-entryHour)/100;
boolean workedAtWeekend;
float salary = 0;
System.out.println("Please enter the hour you arrived to work (HHMM)");
entryHour=in.nextInt();
System.out.println("Please enter the hour you exit from work(HHMM)");
exitHour=in.nextInt();
System.out.println("Please enter payment per hour (bitween 28.00 and 100.00):");
paymentPerHour=in.nextInt();
while(paymentPerHour>0) {
if(paymentPerHour<28 ||paymentPerHour>100) {
System.out.println("Please enter payment per hour");
paymentPerHour=in.nextInt();
}
if(paymentPerHour>=28 &&paymentPerHour<=100) {
continue;
}
}
System.out.println("Did you work on weekend ? (True/False)");
workedAtWeekend=in.hasNext();
if(workedAtWeekend){
salary= (float) ((totalHour)*0.20+100);
}
else if (totalHour>=9) {
salary=(float) ((float)(totalHour)*paymentPerHour*1.5);
if(totalHour>11) {
salary = (float)((float)(totalHour)*paymentPerHour*2);
}
}
else if(totalHour<9) {
salary=(float)((float)(totalHour)*paymentPerHour*0.1);
if(totalHour<=1) {
salary= 0;
}
if(totalHour>=15) {
System.out.println("You cant work more than 15 hours a day");
}
if(totalHour<0) {
salary=Math.abs(totalHour)*paymentPerHour;
}
}
System.out.println("You've been working for: "+totalHour+" Hours"+",And your payment is: "+salary);
}
}