以下是我的JAVA課程作業,希望能夠得到源代碼的參考
。
一節課的長度為2小時30分鐘,課間休息時間為10分鐘,現在要求用戶輸入時間以後,求出下課的時間以及課間休息開始和結束的試看。
以下是用戶界面的輸出結果。
When does this lecture start (please indicate hours and minutes)? Hour: 14
Minute: 55
This lecture will end at
Hour: 17
Minute: 25
The mid-lecture break start time is
Hour: 16
Minute: 5
The mid-lecture break end time is
Hour: 16
Minute: 15
以下是我的源代碼
package jave.util;
import java.util.Scanner;
public class Assignment1 {
public static void main(String[] args) {
Scanner M= new Scanner(System.in);
Scanner H= new Scanner(System.in);
int numberofmin=M.nextInt();
int numberofh=H.nextInt();
final int classlength=150;
final int breaklength=30;
int numberofhourover = (numberofh*60+numberofmin+classlength)/60;
int numberofminover = (numberofh*60+numberofmin+classlength)%60;
int numberofhourbreakstart = (numberofh*60+numberofmin+classlength/2)/60;
int numberofminbreakstart = (numberofh*60+numberofmin+classlength/2)%60;
int numberofhourbreakover = (numberofh*60+numberofmin+classlength/2)/60;
int numberofminbreakover = (numberofh*60+numberofmin+classlength/2)%60;
System.out.println("The lecture will end at");
System.out.println("HOUR:"+numberofhourover);
System.out.println("MIN:"+numberofminover);
// TODO Auto-generated method stub
}
}
輸出的結果是錯的,是什麼回事呢?
import java.util.*;
import java.text.SimpleDateFormat;
public class TestRest{
public static void main(String args[])throws Exception{
//輸入格式18:00
Scanner sc=new Scanner(System.in);
String time=sc.nextLine()+":00";
SimpleDateFormat format = new SimpleDateFormat("hh:mm:ss");
Long l=format.parse(time).getTime();
//加上70分鐘
l=l+70*60*1000L;
Date date=new Date();
date.setTime(l);
System.out.println("Begin Time :"+time);
System.out.println("Rest Time :"+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds());
//剩下按照上面的+10分鐘
//再加70分鐘
}
}