I have the user enter their location.
and based on their location there is a pay difference.
the if statements doesn’t change the variable “pay”
can someone help me?
import java.util.HashMap;
import javax.swing.*;
public class TimeSheet {
public static void main(String[] args) {
String loc;
String[] startday = new String[7];
String[] endday = new String[7];
int x = 0;
int y = 0;
int num = 1;
int location;
double starttime;
double endtime;
double hour = 0;
double total = 0;
double pay = 0;
double totalpay;
loc = JOptionPane.showInputDialog(null, "Enter your Work Location");
location = Integer.parseInt(loc);
if (location == 100 && location < 200 ) {
pay = 10.00;
}
else if (location == 200 && location < 300) {
pay = 7.50;
}
else if (location == 300 && location < 400) {
pay = 9.25;
}
else if (location == 400 && location < 500) {
pay = 13.50;
}
else if (location == 500 && location < 600) {
pay = 8.00;
}
HashMap<String, Double> map = new HashMap<String, Double>();
map.put("1",9.0);
map.put("2",9.5);
map.put("3",10.0);
map.put("4",10.5);
map.put("5",11.0);
map.put("6",11.5);
map.put("7",12.0);
map.put("8",12.5);
map.put("A",13.0);
map.put("B",13.5);
map.put("C",14.0);
map.put("D",14.5);
map.put("E",15.0);
map.put("F",15.5);
map.put("G",16.0);
map.put("H",16.5);
map.put("I",17.0);
while (x < 7 && y < 7) {
startday[x] = JOptionPane.showInputDialog(null, "Enter Day "+num+" 's Starting code");
endday[y] = JOptionPane.showInputDialog(null, "Enter Day "+num+" 's Ending code");
starttime = map.get(startday[x]);
endtime = map.get(endday[y]);
hour = endtime - starttime;
total = total + hour;
totalpay = total*pay;
JOptionPane.showMessageDialog(null, "total hour" + total);
JOptionPane.showMessageDialog(null, "total pay for the week is " + totalpay);
x++;
y++;
num++;
}
}
}
your conditions are like:
translate to english
if location is exactly 200 and less than 300.
You probably want to change it to
if location is greater or equals than 200 and less than 300.