Question: PYTHON TRANSLATE TO JAVA Translate date.py, test1.py, appointment.py, test2.py, and test3.py from Python to Java. date.py class Date: def __init__(self, the_year, the_mon, the_day): self.year =

PYTHON TRANSLATE TO JAVA

Translate date.py, test1.py, appointment.py, test2.py, and test3.py from Python to Java.

date.py

class Date:

def __init__(self, the_year, the_mon, the_day): self.year = the_year self.mon = the_mon self.day = the_day

def __str__(self): return f"{self.mon}/{self.day}/{self.year}"

def next_day(self): days_in_month = [0, 31, 28, 31, 30, \ 31, 30, 31, 31, 30, 31, 30, 31] self.day += 1 if self.day > days_in_month[self.mon]: self.mon += 1 self.day = 1 if self.mon == 13: self.year += 1 self.mon = 1

test1.py

from date import Date

d1 = Date(2013, 9, 18) print(d1) print(d1.year, d1.mon, d1.day) d1.next_day( ) print(d1) print( )

d2 = Date(2013, 9, 31) print(d2) d2.next_day( ) print(d2) print( )

d3 = Date(2013, 12, 31) print(d3) d3.next_day( ) print(d3)

d = Date(2017, 12, 31) for i in range(0, 365): d.next_day( ) print(d)

appointment.py

class Appointment:

def __init__(self, the_appt_type, the_location, \ the_purpose, the_year, the_mon, the_day, \ the_hour, the_min):

# Appointment type can be # "ot": one time appointment and # "mo": monthly appointment. self.appt_type = the_appt_type self.location = the_location self.purpose = the_purpose self.year = the_year self.mon = the_mon self.day = the_day self.hour = the_hour self.min = the_min

def __str__(self): output = f"{self.location} {self.purpose}" return output

def occurs_on(self, the_year, the_mon, the_day):

# A one time appointment only occurs on the # given year, month and day. if self.appt_type == "ot": return self.year == the_year and \ self.mon == the_mon and \ self.day == the_day

# A monthly appointment occurs every month # on the given day. elif self.appt_type == "mo": return self.day == the_day

test2.py

from appointment import Appointment

appt1 = Appointment("ot", "Year End Analysis", \ "Room 207", 2018, 12, 28, 10,0) print(appt1)

print(appt1.occurs_on(2018, 9, 3)) print(appt1.occurs_on(2018, 9, 4))

appt2 = Appointment("mo", "Room 203", \ "Staff Meeting", 0, 0, 3, 8, 30) print(appt2) print( )

print(appt1.occurs_on(2018, 12, 28)) print(appt1.occurs_on(2012, 12, 25)) print(appt2.occurs_on(2018, 9, 3)) print(appt2.occurs_on(2012, 3, 3)) print(appt2.occurs_on(2018, 9, 7)) print(appt2.occurs_on(2012, 3, 7))

test3.py

from appointment import Appointment from date import Date

fin = open("appointments.txt", "r")

# Create list with size greater than needed. arr = list([None] * 100)

line_number = 0 line = fin.readline( ) while line != "": fields = line.split(",") appt_type= fields[0].strip( ) location = fields[1].strip( ) purpose = fields[2].strip( ) year = int(fields[3].strip( )) mon = int(fields[4].strip( )) day = int(fields[5].strip( )) hour = int(fields[6].strip( )) min = int(fields[7].strip( )) appt = Appointment(appt_type, location, \ purpose, year, mon, day, hour, min) arr[line_number] = appt line_number += 1 line = fin.readline( )

fin.close( ) num_appointments = line_number

# Print array of Appointment objects for i in range(0, num_appointments): print(arr[i])

d = Date(2017, 12, 31) for i in range(0, 365): d.next_day( ) for i in range(0, num_appointments): if arr[i].occurs_on(d.year, d.mon, d.day): print(d, end=" ") print("{0:02d}:{1:02d}". \ format(arr[i].hour, arr[i].min)) print(" ", arr[i]) print( )

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!