소스 검색

Changed ActTime to a gregorian calendar

jancoow 11 년 전
부모
커밋
9d48b3c51d
3개의 변경된 파일40개의 추가작업 그리고 25개의 파일을 삭제
  1. 3 3
      src/agenda/Act.java
  2. 34 19
      src/agenda/ActTime.java
  3. 3 3
      src/agenda/Agenda.java

+ 3 - 3
src/agenda/Act.java

@@ -13,10 +13,10 @@ public class Act {
     private String genre;
     private ActTime actTime;
 
-    public Act(Stage stage, String genre, Time startTime, Time endTime, Artist... artists){
+    public Act(Stage stage, String genre, ActTime actTime, Artist... artists){
         this.stage = stage; 
         this.genre = genre;
-        this.actTime = new ActTime(startTime, endTime);
+        this.actTime = actTime;
 
         this.artists = new ArrayList<Artist>();
         for(Artist artist: artists) {
@@ -52,7 +52,7 @@ public class Act {
      * * return the act time.
      * @return the act time in minutes
      */
-    public int getActTime() {
+    public long getActTime() {
         return this.actTime.getLength();
     }
     

+ 34 - 19
src/agenda/ActTime.java

@@ -1,37 +1,52 @@
 package agenda;
 
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+
 /**
  * Created by gjoosen on 06/02/15.
  */
 public class ActTime {
     
-    private Time beginTime, endTime;
+	private GregorianCalendar beginTime, endTime;
     
-    public ActTime(Time beginTime, Time endTime){
-        this.beginTime = beginTime;
-        this.endTime = endTime;
+    public ActTime(int y1, int m1, int d1, int hh1, int mm1, int y2, int m2, int d2, int hh2, int mm2){
+    	beginTime = new GregorianCalendar();
+    	endTime = new GregorianCalendar();
+    	setBeginTime(y1, m1, d1, hh1, mm1);
+    	setEndTime(y2, m2, d2, hh2, mm2);
     }
 
-    /**
-     * *
-     * @return the length of the act in minutes.
-     */
-    public int getLength(){
-        int difHours = this.endTime.getHours() - this.beginTime.getHours();
-        int difMinutes = this.endTime.getMinutes() - this.beginTime.getMinutes();
-        return difHours  * 60 + difMinutes;
+    public void setBeginTime(int y, int m, int d, int hh, int mm){
+    	beginTime.set(y,m-1,d,hh,mm);
     }
-
-    public Time getBeginTime() {
-        return beginTime;
+    
+    public void setEndTime(int y, int m, int d, int hh, int mm){
+    	endTime.set(y,m-1,d,hh,mm);
     }
-
-    public Time getEndTime() {
-        return endTime;
+    
+    public String getBeginTime(){
+    	return 	beginTime.get(Calendar.YEAR) + "-" + 
+    			beginTime.get(Calendar.MONTH) + "-" + 
+    			(beginTime.get(Calendar.DATE)+1) + " " + 
+    			beginTime.get(Calendar.HOUR_OF_DAY) + ":" +
+    			beginTime.get(Calendar.MINUTE);
     }
     
+    public String getEndTime(){
+    	return 	endTime.get(Calendar.YEAR) + "-" + 
+    			endTime.get(Calendar.MONTH) + "-" + 
+    			(endTime.get(Calendar.DATE)+1) + " " + 
+    			endTime.get(Calendar.HOUR_OF_DAY) + ":" +
+    			endTime.get(Calendar.MINUTE);
+    }
+   
+    public long getLength(){
+    	return (endTime.getTimeInMillis()/60000)-(beginTime.getTimeInMillis()/60000);
+    }
+  
     @Override
     public String toString(){
-        return "start time: " + this.beginTime + "\nend time: " + this.endTime;
+        return "start time: " + this.getBeginTime() + "\nend time: " + this.getEndTime() + "\nlength: " + getLength() + " Minuts";
     }
 }

+ 3 - 3
src/agenda/Agenda.java

@@ -31,9 +31,9 @@ public class Agenda {
         this.artists.add(new Artist("Sabaton", "Power metal"));
 
         //acts
-        this.acts.add(new Act(this.stages.get(0), "Heavy metal", new Time(21, 00), new Time(23, 00), this.artists.get(0)));
-        this.acts.add(new Act(this.stages.get(1), "Test metal" ,new Time(10, 10), new Time(10, 50), this.artists.get(1)));
-        this.acts.add(new Act(this.stages.get(0), "Power metal" ,new Time(10, 10), new Time(10, 50), this.artists.get(2)));
+        this.acts.add(new Act(this.stages.get(0), "Heavy metal", new ActTime(2015,02,11,21,00  ,2015,02,11,23,00), this.artists.get(0)));
+        this.acts.add(new Act(this.stages.get(1), "Test metal" , new ActTime(2015,02,11,23,00  ,2015,02,12,04,30), this.artists.get(1)));
+        this.acts.add(new Act(this.stages.get(0), "Power metal" ,new ActTime(2015,02,11,20,00  ,2015,02,11,23,00), this.artists.get(2)));
         
         System.out.println(this);
     }