我正在高中comp sci课上做作业,我遇到了这个问题。总数不加。有人能告诉我为什么吗?
import javax.swing.*;
public class TimeSheets {
public static void main(String[] args) {
String loc;
String[] day = new String[7];
String time1;
String time2;
int location;
double total = 0;
int num = 1;
int x = 0;
int y = 0;
double clock1 = 0;
double clock2 = 0;
double hour;
loc = JOptionPane.showInputDialog(null, "Enter your Work Location");
location = Integer.parseInt(loc);
while (x < 7 && y < 7) {
day[x] = JOptionPane.showInputDialog(null, "Enter Day "+num+" 's Starting code");
day[y] = JOptionPane.showInputDialog(null, "Enter Day "+num+" 's Ending code");
time1 = day[x];
time2 = day[y];
if (time1 == "1") {
clock1 = 9;
}
if (time1 == "2") {
clock1 = 9.5;
}
if (time1 == "3") {
clock1 = 10;
}
if (time1 == "4") {
clock1 = 10.5;
}
if (time1 == "5") {
clock1 = 11;
}
if (time1 == "6") {
clock1 = 11.5;
}
if (time1 == "7") {
clock1 = 12;
}
if (time1 == "8") {
clock1 = 12.5;
}
if (time1 == "9") {
clock1 = 13;
}
if (time1 == "A") {
clock1 = 13.5;
}
if (time1 == "B") {
clock1 = 14;
}
if (time1 == "C") {
clock1 = 14.5;
}
if (time1 == "D") {
clock1 = 15;
}
if (time1 == "E") {
clock1 = 15.5;
}
if (time1 == "F") {
clock1 = 16;
}
if (time1 == "G") {
clock1 = 16.5;
}
if (time1 == "H") {
clock1 = 17;
}
if (time2 == "1") {
clock2 = 9;
}
if (time2 == "2") {
clock2 = 9.5;
}
if (time2 == "3") {
clock2 = 10;
}
if (time2 == "4") {
clock2 = 10.5;
}
if (time2 == "5") {
clock2 = 11;
}
if (time2 == "6") {
clock2 = 11.5;
}
if (time2 == "7") {
clock2 = 12;
}
if (time2 == "8") {
clock2 = 12.5;
}
if (time2 == "9") {
clock2 = 13;
}
if (time2 == "A") {
clock2 = 13.5;
}
if (time2 == "B") {
clock2 = 14;
}
if (time2 == "C") {
clock2 = 14.5;
}
if (time2 == "D") {
clock2 = 15;
}
if (time2 == "E") {
clock2 = 15.5;
}
if (time2 == "F") {
clock2 = 16;
}
if (time2 == "G") {
clock2 = 16.5;
}
if (time2 == "H") {
clock2 = 17;
}
hour = clock2 - clock1;
total = hour + hour;
JOptionPane.showMessageDialog(null, "total hour" + total);
x++;
y++;
num++;
}
}
}