PLZ GIVE THE SUGGESTION,WHERE I MUST PUT THE SENTINEL IN THIS PROGRAME OR CODING
public class DayType{ final static int SUN = 0; final static int MON = 1; final static int TUE = 2; final static int WED = 3; final static int THU = 4; final static int FRI= 5; final static int SAT = 6;
private int day; public DayType(int day) { this.day = day; } public void setDay(int day){ this.day = day; } public int getDay() { return day; } public void print() { System.out.println(this.toString()); } public int nextDay(){ int next; next = day + 1; return next; } public int previousDay(){ int prevDay; prevDay = day - 1; return prevDay; } public int addDays(int days) { return (day + days) % 7; } public String toString() { switch (this.day) { case SUN: return "Sunday"; case MON: return "Monday"; case TUE: return "Tuesday"; case WED: return "Wednesday"; case THU: return "Thursday"; case FRI: return "Friday"; case SAT: return "Saturday"; } return ""; } public static void main(String[] args) { System.out.println("******Test Day******"); System.out.println(); System.out.print("Set day: "); DayType d = new DayType(SUNDAY); d.print(); System.out.print("Next day: "); d.setDay(d.nextDay()); d.print(); System.out.print("Previous day: "); d.setDay(d.previousDay()); d.print(); System.out.print("After 5 days: "); d.setDay(d.addDays(5)); d.print(); }
}
Implementation of DayType class
import java.util.*; public class DayType{ final static int SUN = 0; final static int MON = 1; final static int TUE = 2; final static int WED = 3; final static int THU = 4; final static int FRI= 5; final static int SAT = 6; private int day; public void setDay(int day){ this.day = day; } public int getDay() { return day; } public void print() { System.out.println(this.toString()); } public int nextDay(){ int next; next = day + 1; return next; } public int previousDay(){ int prevDay; prevDay = day - 1; return prevDay; } public int addDays(int days) { return (day + days) % 7; } public String toString() { switch (this.day) { case SUN: return "Sunday"; case MON: return "Monday"; case TUE: return "Tuesday"; case WED: return "Wednesday"; case THU: return "Thursday"; case FRI: return "Friday"; case SAT: return "Saturday"; } return ""; } public static void main(String[] args){ DayType d = new DayType(); Scanner input=new Scanner(System.in); boolean check=false; do{ System.out.println("******Test Day******"); System.out.println("1 Set day"); System.out.println("2 Print day"); System.out.println("3 Return day"); System.out.println("4 Return Previous day"); System.out.println("5 Return Next day"); System.out.println("6 Exit"); System.out.println(); System.out.print("Enter your choice: "); int num=input.nextInt(); switch(num){ case 1: System.out.print("Set day(0-6): "); int day=input.nextInt(); d.setDay(day); break; case 2: d.print(); break; case 3: System.out.print("Next day: "); d.setDay(d.nextDay()); d.print(); break; case 4: System.out.print("Previous day: "); d.setDay(d.previousDay()); d.print(); case 5: System.out.print("Add no of days: "); int no=input.nextInt(); d.setDay(d.addDays(no)); d.print(); break; case 6: check=true; break; } } while(!check); } }
thank you very much friend...
Ads