Java please, output is incorrect and not sure why. In this project we will develop classes to implement a Day Planner pr
Posted: Tue Jul 05, 2022 10:25 am
Java please, output is incorrect and not sure why.
In this project we will develop classes to implementa Day Planner program. Be sure todevelop the code in a step by step manner, finish phase 1 beforemoving on to phase 2.
Phase 1
Completed
Phase 2
Create a class Planner , in thedata area of the class declare an array of20 Appointment objects. Make sure thearray is private (data abstraction).
In this project we are going to build asimple Day Planner programthat allow the user to createvarious Appointment objects and willinsert each into an array. Be sure to inserteach Appointment object into the arrayin the proper position, according to the date and time ofthe Appointment . This means theearliest Appointment object should be atthe start of the array, and thelast Appointment object at the end ofthe array.
Please pre load your array with thefollowing Appointment objects:
Mar 4,17:30 Quiz 1 Apr 1, 17:30Mid May 6, 17:30Quiz 2 Jun 3, 17:30Final
Notice how the objects are ordered, withthe earliest date at the start of the array and the latest at theend of the array.
The program will display the following menu and implement thesefeatures:
A)dd Appointment ,D)elete Appointment ,L)ist Appointment , E)xit
Some methods you must implement inthe Planner class for this project:
You may add additional methods tothe Planner and Appointment classesas long as you clearly document 'what' and 'why' you added themethod at the top of the class.The Appointment class could use one ormore constructor methods. DO NOT in anyway modify the UserInput class. If it so much as refers to a day ormonth or anything else inthe Planner or Appointment classthere will be a major point deduction.
Planner class:
public class Planner { private Appointment[] planner = newAppointment[20]; private String[] months = new String[12]; int numAppointments; public Planner() { Appointment a = new Appointment("Mar",4, 17, 30, "Quiz1"); Appointment b = new Appointment("Apr",1, 17, 30, "Mid"); Appointment c = new Appointment("May",6, 17, 30, "Quiz2"); Appointment d = new Appointment("Jun",3, 17, 30, "Final"); planner[0] = a; planner[1] = b; planner[2] = c; planner[3] = d; months[0] = "Jan"; months[1] = "Feb"; months[2] = "Mar"; months[3] = "Apr"; months[4] = "May"; months[5] = "Jun"; months[6] = "Jul"; months[7] = "Aug"; months[8] = "Sep"; months[9] = "Oct"; months[10] = "Nov"; months[11] = "Dec"; numAppointments = 4; } public void run() { boolean exitMenu = false; do { System.out.println("A)ddApppointment, D)elete Appointment, L)ist Appointment,E)xit"); char value =UserInput.getChar(); value =Character.toUpperCase(value); switch(value) { case'A': addAppointment(); break; case'D': deleteAppointment(); break; case'L': listAppointment(); break; case'E': exitMenu = true; break; default: } } while(!exitMenu); } public boolean compareAppointment(Appointment x,Appointment y){ String xMonth = x.getMonth(); String yMonth = y.getMonth(); int xValue = 0; int yValue = 0; if (x.getMonth() != y.getMonth()){ for (int i = 0; i <months.length; i++) { if (xMonth== months) xValue = i; } for (int i = 0; i <months.length; i++) { if (yMonth== months) yValue = i; } if (xValue < yValue) return true; else return false; } else if (x.getDay() != y.getDay()){ if (x.getDay() <y.getDay()) returntrue; else returnfalse; } else if (x.getHour() != y.getHour()){ if (x.getHour() <y.getHour()) returntrue; else returnfalse; } else if (x.getMinute() !=y.getMinute()) { if (x.getMinute() <y.getMinute()) returntrue; else returnfalse; } else System.out.println("Appointments are identical."); return true; } public void insertAppointment(Appointment x) { int index = 0; for (int i = 0; i < numAppointments;i++) { if (compareAppointment(x,planner)) index = i -1; } numAppointments++; Appointment p1 = planner[index]; planner[index] = x; for (int i = index; i <numAppointments; i++) { Appointment p2 =planner[i+1]; planner[i+1] = p1; p1 = p2; } } public void listAppointment() { int num = 1; for (int i = 0; i < numAppointments;i++) { System.out.println(num +". " + planner.toString()); num++; } } public void deleteAppointment() { listAppointment(); System.out.println("Please select anappointment to delete."); int value = UserInput.getInt(); numAppointments--; for (int i = value - 1; i <numAppointments; i++) { if (i + 1 <=numAppointments) planner= planner[i +1]; } } public void addAppointment() { Appointment x = newAppointment(); x.inputAppointment(); insertAppointment(x); }}Main:
public static void main(String[] args) { Planner a1 = new Planner(); a1.run(); }}
Output:
A)dd Apppointment, D)elete Appointment, L)ist Appointment,E)xitLEnter a character: 1. Month: Mar Day: 0 Hour:Minute: 1730Message: Quiz12. Month: Apr Day: 1 Hour:Minute: 1730 Message: Mid3. Month: May Day: 0 Hour:Minute: 1730 Message: Quiz24. Month: Jun Day: 3 Hour:Minute: 1730 Message: FinalA)dd Apppointment, D)elete Appointment, L)ist Appointment,E)xitAEnter a character: Please enter a Month for your appointment byentering the first 3 characters of the month.JanEnter a string: Please enter a day for your appointment.1Enter an integer: Please enter an hour for your appointment.2Enter an integer: Please enter a minute for your appointment.3Enter an integer: Please enter a message for your appointment thatis under 40 characters.Enter a string: A)dd Apppointment, D)elete Appointment, L)istAppointment, E)xitHello
In this project we will develop classes to implementa Day Planner program. Be sure todevelop the code in a step by step manner, finish phase 1 beforemoving on to phase 2.
Phase 1
Completed
Phase 2
Create a class Planner , in thedata area of the class declare an array of20 Appointment objects. Make sure thearray is private (data abstraction).
In this project we are going to build asimple Day Planner programthat allow the user to createvarious Appointment objects and willinsert each into an array. Be sure to inserteach Appointment object into the arrayin the proper position, according to the date and time ofthe Appointment . This means theearliest Appointment object should be atthe start of the array, and thelast Appointment object at the end ofthe array.
Please pre load your array with thefollowing Appointment objects:
Mar 4,17:30 Quiz 1 Apr 1, 17:30Mid May 6, 17:30Quiz 2 Jun 3, 17:30Final
Notice how the objects are ordered, withthe earliest date at the start of the array and the latest at theend of the array.
The program will display the following menu and implement thesefeatures:
A)dd Appointment ,D)elete Appointment ,L)ist Appointment , E)xit
Some methods you must implement inthe Planner class for this project:
You may add additional methods tothe Planner and Appointment classesas long as you clearly document 'what' and 'why' you added themethod at the top of the class.The Appointment class could use one ormore constructor methods. DO NOT in anyway modify the UserInput class. If it so much as refers to a day ormonth or anything else inthe Planner or Appointment classthere will be a major point deduction.
Planner class:
public class Planner { private Appointment[] planner = newAppointment[20]; private String[] months = new String[12]; int numAppointments; public Planner() { Appointment a = new Appointment("Mar",4, 17, 30, "Quiz1"); Appointment b = new Appointment("Apr",1, 17, 30, "Mid"); Appointment c = new Appointment("May",6, 17, 30, "Quiz2"); Appointment d = new Appointment("Jun",3, 17, 30, "Final"); planner[0] = a; planner[1] = b; planner[2] = c; planner[3] = d; months[0] = "Jan"; months[1] = "Feb"; months[2] = "Mar"; months[3] = "Apr"; months[4] = "May"; months[5] = "Jun"; months[6] = "Jul"; months[7] = "Aug"; months[8] = "Sep"; months[9] = "Oct"; months[10] = "Nov"; months[11] = "Dec"; numAppointments = 4; } public void run() { boolean exitMenu = false; do { System.out.println("A)ddApppointment, D)elete Appointment, L)ist Appointment,E)xit"); char value =UserInput.getChar(); value =Character.toUpperCase(value); switch(value) { case'A': addAppointment(); break; case'D': deleteAppointment(); break; case'L': listAppointment(); break; case'E': exitMenu = true; break; default: } } while(!exitMenu); } public boolean compareAppointment(Appointment x,Appointment y){ String xMonth = x.getMonth(); String yMonth = y.getMonth(); int xValue = 0; int yValue = 0; if (x.getMonth() != y.getMonth()){ for (int i = 0; i <months.length; i++) { if (xMonth== months) xValue = i; } for (int i = 0; i <months.length; i++) { if (yMonth== months) yValue = i; } if (xValue < yValue) return true; else return false; } else if (x.getDay() != y.getDay()){ if (x.getDay() <y.getDay()) returntrue; else returnfalse; } else if (x.getHour() != y.getHour()){ if (x.getHour() <y.getHour()) returntrue; else returnfalse; } else if (x.getMinute() !=y.getMinute()) { if (x.getMinute() <y.getMinute()) returntrue; else returnfalse; } else System.out.println("Appointments are identical."); return true; } public void insertAppointment(Appointment x) { int index = 0; for (int i = 0; i < numAppointments;i++) { if (compareAppointment(x,planner)) index = i -1; } numAppointments++; Appointment p1 = planner[index]; planner[index] = x; for (int i = index; i <numAppointments; i++) { Appointment p2 =planner[i+1]; planner[i+1] = p1; p1 = p2; } } public void listAppointment() { int num = 1; for (int i = 0; i < numAppointments;i++) { System.out.println(num +". " + planner.toString()); num++; } } public void deleteAppointment() { listAppointment(); System.out.println("Please select anappointment to delete."); int value = UserInput.getInt(); numAppointments--; for (int i = value - 1; i <numAppointments; i++) { if (i + 1 <=numAppointments) planner= planner[i +1]; } } public void addAppointment() { Appointment x = newAppointment(); x.inputAppointment(); insertAppointment(x); }}Main:
public static void main(String[] args) { Planner a1 = new Planner(); a1.run(); }}
Output:
A)dd Apppointment, D)elete Appointment, L)ist Appointment,E)xitLEnter a character: 1. Month: Mar Day: 0 Hour:Minute: 1730Message: Quiz12. Month: Apr Day: 1 Hour:Minute: 1730 Message: Mid3. Month: May Day: 0 Hour:Minute: 1730 Message: Quiz24. Month: Jun Day: 3 Hour:Minute: 1730 Message: FinalA)dd Apppointment, D)elete Appointment, L)ist Appointment,E)xitAEnter a character: Please enter a Month for your appointment byentering the first 3 characters of the month.JanEnter a string: Please enter a day for your appointment.1Enter an integer: Please enter an hour for your appointment.2Enter an integer: Please enter a minute for your appointment.3Enter an integer: Please enter a message for your appointment thatis under 40 characters.Enter a string: A)dd Apppointment, D)elete Appointment, L)istAppointment, E)xitHello