Created
November 4, 2013 08:52
-
-
Save DScoder/7299876 to your computer and use it in GitHub Desktop.
Homework 8(not ended)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package myhomework; | |
public class Lesson { | |
private String name; | |
private Week weekDay; | |
public Lesson(){} | |
public Lesson(String name, Week weekDay){ | |
this.name = name; | |
this.weekDay = weekDay; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public Week getWeekDay() { | |
return weekDay; | |
} | |
public void setWeekDay(Week weekDay) { | |
this.weekDay = weekDay; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package myhomework; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
public class Main { | |
public static void main(String[] args) throws IOException { | |
Schedule schedule = new Schedule("School Schedule"); | |
Lesson math = new Lesson("Mathematics", Week.Monday); | |
Lesson prog = new Lesson("Programming", Week.Tuesday); | |
Lesson lang = new Lesson("Language", Week.Wednesday); | |
schedule.addLesson(math); | |
schedule.addLesson(prog); | |
schedule.addLesson(lang); | |
System.out.println(math.getName() + " " + math.getWeekDay()); | |
schedule.printLesson(1); | |
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | |
printMenu(); | |
String line = null; | |
while (!(line = reader.readLine().trim()).equals("exit")) { | |
int choice = 0; | |
try { | |
choice = Integer.parseInt(line); | |
} catch (NumberFormatException e) { | |
System.out.println("Pls enter correct number"); | |
continue; | |
} | |
switch (choice) { | |
case 1: | |
Lesson lesson = createLesson(reader); | |
schedule.addLesson(lesson); | |
break; | |
} | |
printMenu(); | |
} | |
} | |
static Lesson createLesson(BufferedReader reader) { | |
try{ | |
System.out.println("Pls enter lesson name"); | |
String name = reader.readLine(); | |
Schedule sc = new Schedule(name); | |
return sc; | |
}catch(IOException e){ | |
}catch(ArrayIndexOutOfBoundsException e){ | |
Lesson s = createLesson(reader); | |
if (s != null) | |
return s; | |
} | |
return null; | |
} | |
static void printMenu() { | |
System.out.println("1 - add lesson"); | |
System.out.println("2 - show lessons of week day"); | |
System.out.println("3 - show week days of lesson"); | |
System.out.println("'exit' - exit"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package myhomework; | |
public class Schedule extends Lesson { | |
private String name; | |
private Lesson[] lessons; | |
private final int LESSONSDAYCOUNT = 5; | |
private int capacity = 100; | |
private int lessonsCount = 0; | |
public Schedule(String name) { | |
this.name = name; | |
this.lessons = new Lesson[capacity]; | |
} | |
public void printLesson(int a){ | |
System.out.println(lessons[a].getName() + " " + lessons[a].getWeekDay()); | |
} | |
public void addLesson(Lesson lesson) { | |
lessons[lessonsCount++] = lesson; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package myhomework; | |
public enum Week { | |
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment