You are to create a class Appointment.java that will have the following:
5 Instance variables:
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) with these limits:
//the setter for the month must determine if the
//month passed is a valid month
//(January - December), if not
//trap the user until they enter a valid month
public void setMonth(String monthPassed)
//the setter for hour must confirm that the hour is
//between 0 and 23 (inclusive) if it is not
//trap the user until they enter a valid hour
public void setHour(int hourPassed)
//the setter for year must confirm that the year
//is >= 0 and <= 2019, if it is not
//trap the user until they enter a valid year
public void setYear(int yearPassed)
//the setter for minute must confirm that the
//minute is between 0 and 59 (inclusive) if it is
//not trap the user until they enter a valid minute
public void setMinute(int minutePassed)
//the setter for day must confirm that the
//day is a valid day for the month and year passed
//if it is not trap the user to enter a valid day for the
month
//and year passed to the method (i.e. do not have the user
//reenter the month and year, they are to reenter the day
only)
//remember to check if the year is a leap year
public void setDay(int dayPassed, String monthPassed, int yearPassed)
5 getter methods (one for each instance variable) that return the value of the variable
1 toString method
public String toString()
1 equals method
public boolean equals(Appointment appointmentPassed)
import java.util.Scanner;
public class Appointment{
private String month;
private int day;
private int year;
private int hour;
private int minute;
public Appointment()
{
this.month="";
this.day=0;
this.year=0;
this.hour=0;
this.minute=0;
}
public Appointment(String monthPassed, int dayPassed, int yearPassed, int hourPassed, int minutePassed)
{
this.month=monthPassed;
thid.day=dayPassed;
this.year=yearPassed;
this.hour=hourPassed;
this.minute=minutePassed;
}
public void setMonth(String monthPassed)
{
String valid_months[]={"January","February","March","April","May","June","July","August","September","October","November","December"};
int flag=0;
while(flag==0)
{
for(int i=0;i<12;i++)
{
if(valid_months[i].equalsIgnoreCase(monthPassed))
{flag=1;
this.month=monthPassed;
break;}
}
if(flag!=1)
{
System.out.print("Enter a valid month:");
Scanner sc=new Scanner(System.in);
monthPassed=sc.nextLine();
}
}
}
public void setHour(int hourPassed){
int flag=0;
while(flag==0)
{
if(hourPassed>=0 && hourPassed<=23)
{flag=1;this.hour=hourPassed;break;}
else{
System.out.print("Enter a valid hour:");
Scanner sc=new Scanner(System.in);
monthPassed=sc.nextInt();
}
}
}
public void setYear(int yearPassed){
int flag=0;
while(flag==0)
{
if(yearPassed>=0 && year<=2019)
{flag=1;this.year=yearPassed;break;}
else{
System.out.print("Enter a valid year:");
Scanner sc=new Scanner(System.in);
yearPassed=sc.nextInt();
}
}
}
public void setMinute(int minutePassed){
int flag=0;
while(flag==0)
{
if(minutePassed>=0 && minute<=59)
{flag=1;this.minute=minutePassed;break;}
else{
System.out.print("Enter a valid minute:");
Scanner sc=new Scanner(System.in);
minutePassed=sc.nextInt();
}
}
}
public void setDay(int dayPassed,String monthPassed, int yearPassed)
{
int flag=0;
while(flag==0)
{
if(monthPassed.equalsIgnoreCase("January")||monthPassed.equalsIgnoreCase("March")||
monthPassed.equalsIgnoreCase("May")||monthPassed.equalsIgnoreCase("July")||monthPassed.equalsIgnoreCase("August")||monthPassed.equalsIgnoreCase("October")||monthPassed.equalsIgnoreCase("December"))
{
if(dayPassed>=0 && dayPassed<=31)
{this.day=dayPassed;flag=1;break;}
}
else if(monthPassed.equalsIgnoreCase("April")||monthPassed.equalsIgnoreCase("June")||monthPassed.equalsIgnoreCase("September")||monthPassed.equalsIgnoreCase("November")){
if(dayPassed>=0 && dayPassed<=30)
{this.day=dayPassed;flag=1;break;}
}
else if(monthPassed.equalsIgnoreCase("February") && (yearPassed%400==0 )){
if(dayPassed>=0 && dayPassed<=29)
{this.day=dayPassed;flag=1;break;}
}
else if(monthPassed.equalsIgnoreCase("February") && (yearPassed%100==0 ))
{
if(dayPassed>=0 && dayPassed<=28)
{this.day=dayPassed;flag=1;break;}
}
else if(monthPassed.equalsIgnoreCase("February") && (yearPassed%4==0 ))
{
if(dayPassed>=0 && dayPassed<=29)
{this.day=dayPassed;flag=1;break;}
}
else if(monthPassed.equalsIgnoreCase("February") && (yearPassed%4!=0 ))
{
if(dayPassed>=0 && dayPassed<=28)
{this.day=dayPassed;flag=1;break;}
}
else{
System.out.print("Enter a valid day:");
Scanner sc=new Scanner(System.in);
dayPassed=sc.nextInt();
}
}
}
public String getMonth(){return this.month;}
public int getDay(){return this.day;}
public int getHour(){return this.hour;}
public int getMinute(){return this.minute;}
public int getYear(){return this.year;}
public String toString()
{return "Day:"+this.day+" Month:"+this.month+" Year:"+this.year+" hours:"+this.hour+" minutes:"+this.minutes;}
public boolean equals(Appointment appointmentPassed)
{
if(this.month.equalsIgnoreCase(appointmentPassed.getMonth()) && this.day==appointmentPassed.getDay() && this.hour==appointmentPassed.getHour() && this.minute==appointmentPassed.getMinute() && this.year==appointmentPassed.getYear())
return true;
return false;
}
}
You are to create a class Appointment.java that will have the following: 5 Instance variables: private...
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...
public class Car { /* four private instance variables*/ private String make; private String model; private int mileage ; private int year; // /* four argument constructor for the instance variables.*/ public Car(String make) { super(); } public Car(String make, String model, int year, int mileage) { super(); this.make = make; this.model...
We have written the following Class1 class: class Class1 implements SecretInterface { // instance variable private int x = 0; // constructor public Class1(int x) { this.x = x; } // instance methods public double myMethod1(double x, double y) { return x - y; } public void myMethod2(int x) { System.out.println(x); } public String myMethod3(String x) { return "hi " + x; } } We have also written the following Class2 class: class Class2 implements SecretInterface { // instance variable...
In this practical task, you need to implement a class called MyTime, which models a time instance. The class must contain three private instance variables: hour, with the domain of values between 0 to 23. minute, with the domain of values between 0 to 59. second, with the domain of values between 0 to 59. For the three variables you are required to perform input validation. The class must provide the following public methods to a user: MyTime() Constructor. Initializes...
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 Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...
public class Pet { //Declaring instance variables private String name; private String species; private String parent; private String birthday; //Zero argumented constructor public Pet() { } //Parameterized constructor public Pet(String name, String species, String parent, String birthday) { this.name = name; this.species = species; this.parent = parent; this.birthday = birthday; } // getters and setters public String getName() { return name; ...
Lab 7 Add three instance variables to your class RightTriangle from lab 5. The first two are of type int and are called xLoc and yLoc and the third is of type int called ID. Also add a static variable of type double called scaleFactor. This should be initialized to a default value of 1. Update the constructor to set the three new instance variables and add appropriate get and set methods for the four new variables. All set methods...
You may not add any instance variables to any class, though you may create local variables inside of a method to accomplish its task. No other methods should be created other than the ones listed here. Step 1 Develop the following class: Class Name: CollegeDegree Access Modifier: public Instance variables Name: major Access modifier: private Data type: String Name: numberOfCourses Access modifier: private Data type: int Name: courseNameArray Access modifier: private Data type: String [ ] Name: courseCreditArray Access...