Please find the required program after adding the codes for all the above questions in the program. Also find the its corresponding output:
class Date { private int day; private int month; private int year; public Date(int day, int month, int year) { if(day <= 29 && month == 2) this.day = day; else if(month == 4 || month == 6 || month == 9 || month == 11){ if(day>30) this.day = 1; else this.day = day; }else { this.day = day; } if(month >= 1 && month <= 12) this.month = month; else this.month = 1; if(year > 0) this.year = year; else this.year = 2019; } public int getDay() { return day; } public void setDay(int day) { if(this.day <= 29 && this.month == 2) this.day = day; else if(this.month == 4 || this.month == 6 || this.month == 9 || this.month == 11){ if(this.day>30) System.out.println("Invalid day"); else this.day = day; }else { this.day = day; } } public int getMonth() { return month; } public void setMonth(int month) { if(month >= 1 && month <= 12) this.month = month; System.out.println("Invalid month"); } public int getYear() { return year; } public void setYear(int year) { if(year > 0) this.year = year; else System.out.println("Invalid year"); } public boolean equals(Date that){ return (this.day == that.day)&& (this.month == that.month)&& (this.year == that.year); } } class Event { private String location; private Date eventDate; public Event(String l, Date d) { if(l.length() >= 2) this.location = l; else this.location = "Mishref"; if(d.getYear() >= 2019) this.eventDate = d; else { this.getEventDate().setYear(2019); this.getEventDate().setYear(d.getMonth()); this.getEventDate().setYear(d.getDay()); } } public String toString(){ String details = "Location:" + location + ", Date: "+eventDate.getDay()+ "/" + eventDate.getMonth() + "/" + eventDate.getYear(); return details; } public String getLocation() { return location; } public void setLocation(String location) { if(location.length() >= 2) this.location = location; else System.out.println("Invalid location"); } public Date getEventDate() { return eventDate; } public void setEventDate(Date eventDate) { if(eventDate.getYear() >= 2019) this.eventDate = eventDate; else System.out.println("Invalid date"); } } class Main { public static void main(String[] args) { Event e1 = new Event("Mishref", new Date(1,1,2019)); Event e2 = new Event("Bayan", new Date(1,1,2019)); System.out.println("The event is " + e1.getLocation()+ " is scheduled on " + e1.getEventDate().getDay()+"/" + e1.getEventDate().getMonth()+ e1.getEventDate().getYear()); if(e1.getEventDate().equals(e2.getEventDate())){ System.out.println(e1.getLocation() + " and " + e2.getLocation()+ "are scheduled on the same date"); }else { System.out.println("The two events are not scheduled on the same date"); } System.out.println(e1); System.out.println(e2); } }
--------------------------------------
OUTPUT:
SaffSpring 2019 Professor Question 1: Answer ALL of the following questions based on this provide...
C++ Programming Step 1. Design a new ADT that implements a class named Date, add 3 private member variables month, day, year along with their appropriate public constructor / getter / setter member functions inside Date.h and Date.cpp. Step 2. Design another ADT that implements a class named Watch, add 3 private member variables hour, minute, second, along with their appropriate public constructor / getter / setter member functions inside Watch.h and Watch.cpp. Step 3. Next, implement the additional SmartWatch...
JAVA programing Question 1 (Date Class): 5 Points Create a class Date with the day, month and year fields (attributes). Provide constructors that: A constructor that takes three input arguments to initialize the day, month and year fields. Note 1: Make sure that the initialization values for the day, month and year fields are valid where the day must be between 1 and 31 inclusive, the month between 1 and 12 inclusive and the year a positive number. Note 2:...
You are to create a class Appointment.java that will have the following: 5 Instance variables: private String month private int day private int year private int hour private int minute 1 default constructor public Appointment() 1 non-default constructor that accepts arguments for all instance variables, your constructor must call the setter methods below to set the values of the instance variables public Appointment(String monthPassed, int dayPassed, int yearPassed, int hourPassed, int minutePassed) 5 setter methods (one for each instance variable)...
QUESTION 5 (15 Marks) Inheritance and Polymorphism Design a Ship class that has the following members: • A private String data field named name for the name of the ship. • A private String data field named yearBuilt for the year that the ship was built. • A constructor that creates a ship with the specified name and the specified year that the ship was built. • Appropriate getter and setter methods. A toString method that overrides the toString method...
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...
Part 1. (60 pts) 1. Define an Address class in the file Address.h and implement the Address class in Address.cpp. a. This class should have two private data members, m_city and m_state, that are strings for storing the city name and state abbreviation for some Address b. Define and implement public getter and setter member functions for each of the two data members above. Important: since these member functions deal with objects in this case strings), ensure that your setters...
answer the questions throughout this program public class Day implements Comparable { Private Boolean atWork; Private String Weather; Private int fuNumber; } public Day ( boolean Atwork, String Weather, int funNumber) { Atwork = Atwork; Weather = Weather; funNumber = funNumber; } //question 1: implement the getter and setter (mutatto of the funNumber data member. if the number is outside the range 0-10 make the fuNumebr=5; public boolean equals (Day rhs) { //...
Design and implement a C++ class called Date that has the following private member variables month (int) day (nt) . year (int Add the following public member functions to the class. Default Constructor with all default parameters: The constructors should use the values of the month, day, and year arguments passed by the client program to set the month, day, and year member variables. The constructor should check if the values of the parameters are valid (that is day is...
Project_10_base_files.zipMakefile (2).txtProject_10_main 1.JPGProject_10_main 2.JPGProject_10_main 3.JPGProject_10 h.JPGProject_10 cpp.JPGAny C++ technique covered in Chapters 1 through 12is allowedexcept for global variablesYou are not allowed to use any global variables.If necessary, global constants may be used.Project 10DescriptionFor this project a Date class(specifiedin the file Project_10.h) will be constructed and all function definitions will be written in the file Project_10.cpp. A makefileis provided to compile this project. The file Project_10_main.cppcontainsthe main functionthat is used to run the program.On Canvas, download the files Project_10.h, Project_10_main.cpp...
Do that with C++ and please add more comment that make
it understandable
In this hormework, you will implement a simple caledar application The implernentation shauld include a class narned Calendar, an abstract class named Event and two concrete classes narmed Task and Appointment which irherit from the Evernt class. The Event Class This will be an abstract class. It will have four private integer members called year, month, day and hour which desigate the tirne of the event. It...