Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- public class Menue {
- // public static void printLeapyear(int year) {
- // for (int i = 0; i <= year; i++) {
- // System.out.println(i + ": " + isLeapyear(i));
- // }
- // }
- private static Calendar calendar = new Calendar();
- public static int[] parseInput() {// Hier wird das Datum eingelesen.
- while (true) {
- System.out.println("Bitte geben Sie das Datum ein (dd.mm.yyyy):");
- Scanner scan = new Scanner(System.in);
- String scanned = scan.nextLine();
- String[] splitted = scanned.split("\\.");
- System.out.println(Arrays.toString(splitted));
- if (splitted.length == 3) {
- try {
- int day = Integer.parseInt(splitted[0]);
- int month = Integer.parseInt(splitted[1]);
- int year = Integer.parseInt(splitted[2]);
- if (isValidDate(day, month, year)) {
- int[] dateArray = { day, month, year };
- return dateArray;
- } else {
- System.out.println("Ungültiges Datum");
- System.out.println();
- }
- } catch (NumberFormatException e) {
- System.out
- .println("Tut mir Leid, das war kein lesbares Datum");
- System.out.println();
- }
- } else {
- System.out.println("Tut mir Leid, das war kein lesbares Datum");
- System.out.println();
- }
- }
- }
- private static String addDateName() {// Hier wird der Name des Termins
- // eingelesen
- System.out.println("Bitte Terminnamen eingeben:");
- Scanner scan = new Scanner(System.in);
- String name = scan.nextLine();
- if (name.isEmpty()) {
- return addDateName();
- } else {
- System.out.println(name);
- return name;
- }
- }
- private static int[] addDateTime() {// Hier wird die Zeit des Termins
- // eingelesen
- System.out.println("Bitte Uhrzeit eingeben(hh:mm):");
- Scanner scan = new Scanner(System.in);
- String scannedTime = scan.nextLine();
- String[] splitted = scannedTime.split("\\:");
- if (splitted.length == 2){
- try {
- int hours = Integer.parseInt(splitted[0]);
- int minutes = Integer.parseInt(splitted[1]);
- if (isValidTime(hours, minutes)) {
- System.out.println("Zeit: " + hours + ":" + minutes + " Uhr");
- int[] timeArray = { hours, minutes };
- return timeArray;
- } else {
- System.out.println("Fehler");
- return addDateTime();
- }
- } catch (NumberFormatException e) {
- System.out.println("Ungültige Zeitangabe!");
- return addDateTime();
- }
- }
- else {
- System.out.println("Ungültige Zeitangabe!");
- return addDateTime();
- }
- }
- private static String addDateDescription() {
- System.out.println("Bitte Beschreibung eingeben:");
- Scanner scan = new Scanner(System.in);
- String description = scan.nextLine();
- if (description.isEmpty()) {
- return addDateDescription();
- } else {
- System.out.println("Beschreibung: " + description);
- return description;
- }
- }
- public static boolean isValidTime(int hours, int minutes) {
- if ((hours < 24) && (hours >= 0) && (minutes < 60) && (minutes >= 0)) {
- return true;
- } else {
- return false;
- }
- }
- public static boolean isLeapyear(int year) {
- if ((year % 4) == 0) {
- if ((year % 100) == 0) {
- if ((year % 400) == 0) {
- return true;
- } else {
- return false;
- }
- } else {
- return true;
- }
- } else {
- return false;
- }
- }
- public static boolean isValidDate(int day, int month, int year) {
- if (month > 0 && month < 13) {
- switch (month) {
- case 1:
- return ((day <= 31) && (day > 0));
- case 2:
- if ((isLeapyear(year))) {
- return ((day <= 29) && (day > 0));
- } else {
- return ((day <= 28) && (day > 0));
- }
- case 3:
- return ((day <= 31) && (day > 0));
- case 4:
- return ((day <= 30) && (day > 0));
- case 5:
- return ((day <= 31) && (day > 0));
- case 6:
- return ((day <= 30) && (day > 0));
- case 7:
- return ((day <= 31) && (day > 0));
- case 8:
- return ((day <= 31) && (day > 0));
- case 9:
- return ((day <= 30) && (day > 0));
- case 10:
- return ((day <= 31) && (day > 0));
- case 11:
- return ((day <= 30) && (day > 0));
- case 12:
- return ((day <= 31) && (day > 0));
- default:
- return false;
- }
- } else {
- return false;
- }
- }
- public static void addDate() {
- Date date = new Date(parseInput(), addDateTime(), addDateName(),
- addDateDescription());
- calendar.addDate(date);
- }
- public void editDate() {
- calendar.printCalendar();
- System.out.println("Bitte geben Sie die Terminnummer des zu ändernden Termins ein!");
- Scanner scan = new Scanner(System.in);
- int scanned = scan.nextInt();
- if (scan.hasNextInt()) {
- Date date = calendar.getDate(scanned);
- scanNewDate();
- scanNewTime();
- scanNewName();
- scanNewDescription();
- } else {
- System.out.println("Bitte die Terminnummer eingeben!");
- editDate();
- }
- }
- public int[] scanNewDate() {
- System.out.println("Bitte geben Sie das neue Datum ein (dd.mm.yyyy):");
- Scanner scan = new Scanner(System.in);
- String scanned = scan.nextLine();
- String[] splitted = scanned.split("\\.");
- System.out.println(Arrays.toString(splitted));
- if (splitted.length == 3) {
- try {
- int newDay = Integer.parseInt(splitted[0]);
- int newMonth = Integer.parseInt(splitted[1]);
- int newYear = Integer.parseInt(splitted[2]);
- if (isValidDate(newDay, newMonth, newYear)) {
- int[] newDateArray = { newDay, newMonth, newYear };
- Date.setDay(newDay);
- } else {
- System.out.println("Ungültiges Datum");
- System.out.println();
- return scanNewDate();
- }
- } catch (NumberFormatException e) {
- System.out.println("Tut mir Leid, das war kein lesbares Datum");
- System.out.println();
- return scanNewDate();
- }
- } else {
- System.out.println("Tut mir Leid, das war kein lesbares Datum");
- System.out.println();
- return scanNewDate();
- }
- }
- private static String scanNewName() {// Hier wird der neue Name des Termins
- // eingelesen
- System.out.println("Bitte neuen Terminnamen eingeben:");
- Scanner scan = new Scanner(System.in);
- String newName = scan.nextLine();
- if (newName.length() > 0) {
- System.out.println(newName);
- return newName;
- } else {
- return scanNewName();
- }
- }
- private static int[] scanNewTime() {// Hier wird die neue Zeit des Termins
- // eingelesen
- System.out.println("Bitte Uhrzeit eingeben(hh:mm):");
- Scanner scan = new Scanner(System.in);
- String scannedTime = scan.nextLine();
- String[] splitted = scannedTime.split("\\:");
- if (splitted.length == 2){
- try {
- int newHours = Integer.parseInt(splitted[0]);
- int newMinutes = Integer.parseInt(splitted[1]);
- if (isValidTime(newHours, newMinutes)) {
- System.out.println("Zeit: " + newHours + ":" + newMinutes + " Uhr");
- int[] timeArray = { newHours, newMinutes };
- return timeArray;
- } else {
- System.out.println("Fehler");
- return addDateTime();
- }
- } catch (NumberFormatException e) {
- System.out.println("Ungültige Zeitangabe!");
- return addDateTime();
- }
- }
- else {
- System.out.println("Ungültige Zeitangabe!");
- return addDateTime();
- }
- }
- private static String scanNewDescription() {
- System.out.println("Bitte Beschreibung eingeben:");
- Scanner scan = new Scanner(System.in);
- String newDescription = scan.nextLine();
- if (newDescription.isEmpty()) {
- return scanNewDescription();
- } else {
- System.out.println("Beschreibung: " + newDescription);
- return newDescription;
- }
- }
- public static void main(String[] args) {
- for (int i = 1; i < 8; i++) {
- int[] dateArray = { 12, 1, 2012 };
- int[] timeArray = { 8, 00 };
- String name = "Besprechung " + i;
- String description = "Treffen mit Senfgesicht Nummer " + i;
- Date date = new Date(dateArray, timeArray, name, description);
- calendar.addDate(date);
- }
- boolean running = true;
- while (running) {
- System.out.println("Was möchten Sie machen?");
- System.out.println();
- System.out.println("1. Termine anzeigen");
- System.out.println("2. Termin hinzufügen");
- System.out.println("3. Termine ändern");
- System.out.println("4. Programm beenden");
- Scanner scan = new Scanner(System.in);
- String scanned = scan.nextLine();
- int scannedInt = 0;
- try {
- scannedInt = Integer.parseInt(scanned);
- } catch (NumberFormatException e) {
- System.out.println("Bitte eine Zahl eingeben!");
- System.out.println();
- }
- switch (scannedInt) {
- case 1:
- calendar.printCalendar();
- System.out.println();
- break;
- case 2:
- addDate();
- break;
- case 3:
- System.out.println("Punkt 3");
- System.out.println();
- break;
- case 4:
- System.out.println("Programm beendet");
- running = false;
- break;
- default:
- System.out
- .println("Bitte einen der oben genannten Menüpunkte eingeben!");
- System.out.println();
- break;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment