Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- import java.util.Arrays;
- public class Main
- {
- private class Event implements Comparable<Event>
- {
- public int time;
- public String event;
- public Event(int time, String event){
- this.time = time;
- this.event = event;
- }
- public String toString(){
- return time+":00 - "+event;
- }
- public int compareTo(Event e){
- if(this.time == e.time){
- return 0;
- }
- return (this.time < e.time ? -1 : 1);
- }
- }
- private class EventPlanner
- {
- ArrayList<Event> events = new ArrayList<>();
- public void addEvent(int time,String event){
- if(time > 0 && time < 25){
- Event e = new Event(time,event);
- events.add(e);
- } else {
- System.out.println("Time has to be between 0 and 25");
- }
- }
- public void removeEvent(int time){
- for(int a = 0;a < events.size();++a){
- if(events.get(a).time == time){
- events.remove(a);
- break;
- }
- }
- }
- public void removeEvent(String event){
- for(int a = 0;a < events.size();++a){
- if(events.get(a).event.equalsIgnoreCase(event)){
- events.remove(a);
- }
- }
- }
- public String toString(){
- StringBuilder sb = new StringBuilder(events.size()*20);
- Event[] array = events.toArray(new Event[0]);
- Arrays.sort(array);
- for(Event e : array){
- sb.append(e+"\n");
- }
- return sb.toString();
- }
- }
- public void run(){
- System.out.println("For help, type 'help'");
- Scanner sc = new Scanner(System.in);
- EventPlanner ep = new EventPlanner();
- String input = null;
- String[] split = null;
- while(!"q".equals(input)){
- input = sc.nextLine();
- split = input.split(" ");
- System.out.println("");
- switch(split[0].toLowerCase()) {
- case "add":{
- ep.addEvent(Integer.parseInt(split[1]),split[2]);
- break;
- }
- case "view":{
- System.out.println(ep);
- break;
- }
- case "remove":{
- if(split[1].matches("[0-2]?[0-9]")){
- ep.removeEvent(Integer.parseInt(split[1]));
- } else {
- ep.removeEvent(split[1]);
- }
- break;
- }
- case "help":{
- System.out.println("Command:\tUsage:\t\t\t\tDescription:\nAdd\t\tadd <hour> <description>\tAdd a new event\nremove\t\tremove <hour>\t\t\tRemoves the event\nremove\t\tremove <description>\t\tRemoves the event\nview\t\tview\t\t\t\tShows current tasks\nhelp\t\thelp\t\t\t\tPrints this screen");
- break;
- }
- }
- }
- }
- public static void main(String[] args){
- new Main().run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement