我正在做我的Java類的家庭作業。除了這部分關於流逝的時間外,我得到了大部分內容。我們必須使用方法。這是我的任務和代碼。在Java中消耗的時間?
「你剛剛被一家公司僱傭來做它的每週工資單。你必須每天執行的功能之一是檢查員工的時間卡,並計算他們」衝入「時間和「打出來」,你還必須將小時轉換爲分鐘,從幾天到幾小時,幾分鐘到幾小時,幾小時到幾天,因爲你剛剛完成了第一個編程課程,所以你決定寫一個程序來幫助你完成工作
您決定按以下方式構建您的程序:主功能只是一個菜單,用戶可以從中選擇以獲取他們想要的信息菜單上的每個選項都會調用特定的方法以解決任務和/或ou輸入答案。
你可以假設這個程序的所有經過時間將在一天內完成,但其他時間可能會更長。請務必提供足夠的測試數據以證明您的解決方案是正確的。 (每個轉換顯示至少一個輸出[可能選項#5的幾個輸出])。 「
import java.util.*;
public class Prog671A
{
public static void hoursToMinutes()
{
Scanner input = new Scanner (System.in);
System.out.print("Enter hour(s): ");
int hours = input.nextInt();
System.out.println(hours + " * 60 = " + (hours * 60) + " minutes.");
System.out.println("");
}
public static void daysToHours()
{
Scanner input = new Scanner (System.in);
System.out.print("Enter day(s): ");
int days = input.nextInt();
System.out.println(days + " * 24 = " + (days * 24) + " hours.");
System.out.println("");
}
public static void minutesToHours()
{
Scanner input = new Scanner (System.in);
System.out.print("Enter minute(s): ");
int minutes = input.nextInt();
System.out.println(minutes + "/60 = " + ((double)minutes/60) + " hours.");
System.out.println("");
}
public static void hoursToDays()
{
Scanner input = new Scanner (System.in);
System.out.print("Enter hour(s): ");
int hours = input.nextInt();
System.out.println(hours + "/24 = " + ((double)hours/24) + " days.");
System.out.println("");
}
public static void elapsedTime()
{
Scanner input = new Scanner (System.in);
System.out.print("Enter the beginning hour: ");
int startingHour = input.nextInt();
System.out.print("Enter the beginning minute(s): ");
int startingMinutes = input.nextInt();
System.out.print("Enter AM/PM: ");
String startingAmOrPm = input.nextLine();
System.out.print("Enter the ending hour: ");
int endingHour = input.nextInt();
System.out.print("Enter the ending minute(s): ");
int endingMinutes = input.nextInt();
System.out.print("Enter AM/PM: ");
String endingAmOrPm = input.nextLine();
System.out.println("");
System.out.println("The elapsed time is: " +);
}
public static void main (String args [])
{
int x = 1;
while (x == 1) {
Scanner input = new Scanner (System.in);
System.out.println("Conversion Tasks");
System.out.println("\t1. Hours -> Minutes");
System.out.println("\t2. Days -> Hours");
System.out.println("\t3. Minutes -> Hours");
System.out.println("\t4. Hours -> Days");
System.out.println("\t5. Elapsed time between two times");
System.out.println("\t6. Exit");
System.out.print("Enter a number: ");
int menu = input.nextInt();
System.out.println("");
if (menu == 1)
hoursToMinutes();
if (menu == 2)
daysToHours();
if (menu == 3)
minutesToHours();
if (menu == 4)
hoursToDays();
if (menu == 5)
elapsedTime();
if (menu == 6)
x = 0;
}
}
}
我只需要在這裏幫助
public static void elapsedTime()
{
Scanner input = new Scanner (System.in);
System.out.print("Enter the beginning hour: ");
int startingHour = input.nextInt();
System.out.print("Enter the beginning minute(s): ");
int startingMinutes = input.nextInt();
System.out.print("Enter AM/PM: ");
String startingAmOrPm = input.nextLine();
System.out.print("Enter the ending hour: ");
int endingHour = input.nextInt();
System.out.print("Enter the ending minute(s): ");
int endingMinutes = input.nextInt();
System.out.print("Enter AM/PM: ");
String endingAmOrPm = input.nextLine();
System.out.println("");
System.out.println("The elapsed time is: " +);
}
您是否想減去開始和結束時間,然後打印結果? – hologram
你爲什麼要讓他們分別輸入小時和分鐘?如果你想計算經過的時間,它會讓你的生活變得更容易,只需要將所有的值轉換爲24小時的時間(例如,將12加到任何大於12的任何東西) – Max
我認爲是這樣。老師不是很具體。他只給了我們這個例子輸出。 經過時間換算 輸入起始時間:8 輸入開始分鐘:14 輸入AM/PM:我 輸入結束時間:2 輸入結束分鐘:47 輸入AM/PM:PM 所用時間是:?小時分 –