5.Implement a superclass Appointment and subclasses Onetime, Daily and Monthly. An appointment has a description (for example, “see the dentist”) and a date. Write a method occursOn(year,month,day) that checks whether the appointment occurs on that date. For example for a monthly appointment, you must check whether the day of the month matches and the appointment date started before the date entered. Then, fill a list of Appointment objects with a mixture of appointments. Have the user enter a date and print out all appointments that occur on that date. List will be created for you from the data.txt file as your input file and demo-appointment.py for your program that calls your class Appointment.
a) Your code with comments
b) A screenshot of the execution
Test Cases:
Add 2 appointments: Day Month Year Description
1. D 13 6 2010 Jog
2. M 15 1 2012 Haircut
Test 1 for List Function
List: Day Month Year 15 2 2016
Expected Results:
1 1 2013 Do pushups
15 8 2012 Backup important data
13 6 2010 Jog
15 1 2012 Haircut
Test 2 for List Function
4 4 2013
Expected Results:
1 1 2013 Do pushups
4 4 2013 Dentist
Provided Python Program
Currently already
-creates a list from the .txt file
-Asks the user for Add,List,Quit
-Can Add items to the list based on user input
-Functions for List and Save
Still Needs
An Appointment Super-class
Daily,Monthly,OneTime Sub-classes
An occursOn function for each class
A save function for each Class
Integration between the Classes and the List and Save function
def main() :
# Load the list of appointments.
appList = loadAppointments("data.txt")
choice = input("A)dd, L)ist or Q)uit? ").upper()
while choice != "Q" :
if choice == "L" :
listAppointments(appList)
if choice == "A" :
addAppointment(appList)
choice = input("A)dd, L)ist or Q)uit? ").upper()
# Save all of the appointments.
print("Saving appointments to data.txt")
outf = open("data.txt", "w")
for app in appList :
app.save(outf)
outf.close()
## Prompt the user for the information for an appointment and
add it to the
# list of appointments.
# @param appList the list of appointments
#
def addAppointment(appList) :
print("Adding a new appointment: ")
day = int(input(" Day? "))
month = int(input(" Month? "))
year = int(input(" Year? "))
desc = input(" Description? ")
app_type = input("O)netime, D)aily or M)onthly? ").upper()
if app_type == "O" :
appList.append(Onetime(day, month, year, desc))
elif app_type == "D" :
appList.append(Daily(day, month, year, desc))
elif app_type == "M" :
appList.append(Monthly(day, month, year, desc))
else :
print("That wasn't a valid appointment type.")
## Ask the user for the day, month and year, then list all
appointments on
# the provided date.
# @param appList the list of appointments to search
#
def listAppointments(appList) :
# Read a date from the user and display all of its
appointments.
day = int(input("Enter the day: "))
month = int(input("Enter the month: "))
year = int(input("Enter the year: "))
# Find all of the appointments on the entered date.
for app in appList :
if app.occursOn(day, month, year) :
app.printappt()
## Load the appointments from the file whose name is
provied.
# @param fname the name of the file to load
#
def loadAppointments(fname) :
# Try to open the file. If that fails, return an empty list of
appointments.
try :
inf = open(fname, "r")
except :
return []
# Load all of the appointments from the file, saving them in the
list retval.
retval = []
for line in inf :
line = line.strip()
parts = line.split("|")
if parts[0] == "O" :
retval.append(Onetime(int(parts[1]), int(parts[2]), int(parts[3]),
parts[4]))
elif parts[0] == "D" :
retval.append(Daily(int(parts[1]), int(parts[2]), int(parts[3]),
parts[4]))
elif parts[0] == "M" :
retval.append(Monthly(int(parts[1]), int(parts[2]), int(parts[3]),
parts[4]))
# Close the data file.
inf.close()
# Return the list of appointments.
return retval
# Call the main function.
main()
Here is the Text File
D|1|1|2013|Do Pushups
M|15|8|2012|Backup important data
O|4|4|2013|Dentist
O|15|4|2013|Big party
O|10|10|2013|Mom's birthday party
As per the given data
import java.util.ArrayList; //library file
public abstract class Appointment
{//opening loop for the instruction
protected String description;
protected int day, month, year;
public Appointment(String desc, int Day, int Month, int Year)
{//opening loop for the instruction
description = desc;
day = Day;
month = Month;
year = Year;
}//closing loop for the instruction
public String getDescription()
{//opening loop for the instruction
return description;
}
public void setDescription(String description)
{//opening loop for the instruction
this.description = description;
}//closing loop for the instruction
public int getDay()
{//opening loop for the instruction
return day;
}//closing loop for the instruction
public void setDay(int day)
{//opening loop for the instruction
this.day = day;
}
public int getMonth()
{//opening loop for the instruction
return month;
}//closing loop for the instruction
public void setMonth(int month) {//opening loop for the
instruction
this.month = month;
}//closing loop for the instruction
public int getYear()
{//opening loop for the instruction
return year;
}//closing loop for the instruction
public void setYear(int year)
{//opening loop for the instruction
this.year = year;
}//closing loop for the instruction
public boolean occursOn(int day, int month, int year)
{//opening loop for the instruction
if(getDay() == day && getMonth() == month &&
getYear() == year)
return true;
else
return false;
}//closing loop for the instruction
public String toString()
{//opening loop for the instruction
return description +" on "+ day +"/"+month+"/" +year ;
}//closing loop for the instruction
}//closing loop for the instruction
import java.util.ArrayList;
public class AppointmentInheritance
{//opening loop for the instruction
ArrayList<Appointment> appointments;
public AppointmentInheritance()
{//opening loop for the instruction
appointments = new ArrayList<Appointment>();
}//closing loop for the instruction
public void makeAppointment(Appointment a)
{//opening loop for the instruction
appointments.add(a);
}//closing loop for the instruction
public void checkAppointments()
{//opening loop for the instruction
for(Appointment a : appointments)
System.out.println(a.toString());
}//closing loop for the instruction
public void show(int day, int month, int year)
{//opening loop for the instruction
for(Appointment a : appointments)
if(a.occursOn(day, month, year))
System.out.println(a.toString());
}//closing loop for the instruction
}//closing loop for the instruction
import java.util.Scanner;
public class TestAppointment
{//opening loop for the instruction
public static void main(String[] args)
{//opening loop for the instruction
AppointmentInheritance myAppts = new AppointmentInheritance();
myAppts.makeAppointment(new Monthly("Visit
grandma",10,12,2018));
myAppts.makeAppointment(new Daily("Brush your teeth",18,10,2017));
myAppts. makeAppointment(new OneTime("Dentist appointment", 19, 11, 2017));
System.out.println("********The appointments in the book are*****\n");//output of the system prints
myAppts.checkAppointments();
Scanner scanner = new Scanner(System.in);
String ans, desc;
int type, day, month, year;
Appointment app;
while(true)
{//opening loop for the instruction
System.out.println("Please press yes/no to add "
+ "an appointment? y/n: ");
ans = scanner.next();
if(!ans.equalsIgnoreCase("y"))
break;
else
{//opening loop for the instruction
while(true)
{//opening loop for the instruction
System.out.println("1. One time Appointment");
System.out.println("2. Daily Appointment");
System.out.println("3. Monthly Appointment");
System.out.println("Please make a selection of "
+ "appointment type: ");
type = scanner.nextInt();
if(type>=1 && type<=3)
break;
}//closing loop for the instruction
scanner.nextLine();
System.out.println("Enter the description: ");
desc = scanner.nextLine();
System.out.println("Enter the day: ");
day = scanner.nextInt();
System.out.println("Enter the month: ");
month = scanner.nextInt();
System.out.println("Enter the year: ");
year = scanner.nextInt();
if(type == 1)
app = new OneTime(desc, day, month, year);
else if(type == 2)
app = new Daily(desc, day, month, year);
else
app = new Monthly(desc, day, month, year);
myAppts.makeAppointment(app);
}//closing loop for the instruction
}//closing loop for the instruction
System.out.println("\n*****The appointments in the book
are****\n");
myAppts.checkAppointments();
System.out.println("\nEnter date to show appointments for the date");
System.out.println("Enter the day: ");
day = scanner.nextInt();
System.out.println("Enter the month: ");
month = scanner.nextInt();
System.out.println("Enter the year: ");
year = scanner.nextInt();
myAppts.show(day, month, year);
}//closing loop for the instruction
}//closing loop for the instruction
public class Daily extends Appointment
{//opening loop for the instruction
public Daily(String desc, int day, int month, int year) {
super(desc, day, month, year);
}//closing loop for the instruction
public boolean occursOn(int day, int month, int year)
{//opening loop for the instruction
return true;
}//closing loop for the instruction
public String toString()
{//opening loop for the instruction
return "[Daily] "+description;
}//closing loop for the instruction
}//closing loop for the instruction
public class Monthly extends Appointment
{//opening loop for the instruction
public Monthly(String desc, int day, int month, int year)
{//opening loop for the instruction
super(desc, day, month, year);
}//closing loop for the instruction
public boolean occursOn(int day, int month, int year)
{//opening loop for the instruction
if(getDay() == day)
return true;
else
return false;
}//closing loop for the instruction
public String toString()
{//opening loop for the instruction
return "[Monthly] "+ description + " on day "+day+" of the month";
}//closing loop for the instruction
}//closing loop for the instruction
public class OneTime extends Appointment
{//opening loop for the instruction
public OneTime(String desc, int day, int month, int year)
{//opening loop for the instruction
super(desc, day, month, year);
}//closing loop for the instruction
public String toString()
{//opening loop for the instruction
return "[OneTime] "+super.toString();
}//closing loop for the instruction
}//closing loop for the instruction
5.Implement a superclass Appointment and subclasses Onetime, Daily and Monthly. An appointment has a description (for...
Programming language: JAVA Implement a superclass Appointment and subclasses OneTime, Daily, and Monthly. An appointment has a description (for example "see the dentist") and a date. Write a method OccursOn (int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, check whether the day of the month matches. Ask the user to enter a date to check (for example, 2006 10 5), and ask to user if they want...
(JAVA) In this assignment, you will implement a superclass Appointment and subclasses Onetime, Daily, and Monthly. An appointment has a description (for example, “see the dentist”) and a date. Write a method occursOn(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the mon.th matches. In your application part, fill an array of Appointment objects with a mixture of appointments. Have the...
*PYTHON* Implement a superclass Appointment and subclasses Onetime, Daily, and Monthly. An appointment has the date, the month, the year, and the description of an appointment (e.g., “see the dentist”). Then, write a method occcursOn(year, month, day) that checks whether the appointment occurs on that date. In the test program, you should create a list of appointments using your subclasses of Onetime, Daily, and Monthly. Once you have those appointments available, allow the user to input day, month, and year...
Help me with a python program : Implement a superclass appointment and subclasses Onetime, Daily and Monthly. An appointment has a description(for example, "See the dentist") and a date. Write a method occursOn(year, month, day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill a list of appointment objects with a mixture of appointments. Have the user enter a date and print...
Write a Java program that implements a superclass Appointment and subclasses Onetime, Daily, and Monthly. An appointment has a description (for example, “see the dentist”) and a date. It writes a method occursOn (int year, int month, int day) that checks whether the appointmentoccurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then it will fill an array of Appointment objects with a mixture of appointments. When the user...
Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will have four instance variables: • An instance variable called “year” which will be of type int • An instance variable called “month” which will be of type int • An instance variable called “day” which will be of type int • An instance variable called “description” which will be of type String The “Appointment” class must also implement the following methods: • A getter...
python 3 8.12 LAB: Python cross reference In addition to editors and compilers, a software developer may use tools to analyze the software they are writing to examine the names being used for variables and functions, and list the line numbers where the variables and functions names appear. For example, consider the following program savings.py used to compute the month to month interest gained from a certificate of deposit: 1: Input the CD APR, no years and initial deposit 2:...
You need not run Python programs on a computer in solving the following problems. Place your answers into separate "text" files using the names indicated on each problem. Please create your text files using the same text editor that you use for your .py files. Answer submitted in another file format such as .doc, .pages, .rtf, or.pdf will lose least one point per problem! [1] 3 points Use file math.txt What is the precise output from the following code? bar...
The administration of President Barack Obama has made Patient Protection and Affordable Care Act, often called “Obamacare”, its chief domestic accomplishment and the centerpiece of Obama’s legacy. Essential to Obama’s health care reform plan is Healthcare.gov, a health insurance exchange Web site that facilitates the sale of private health insurance plans to U.S. residents, assists people eligible to sign up for Medicaid, and has a separate marketplace for small businesses. The site allows users to compare prices on health insurance...