SlideShare a Scribd company logo
1 of 7
Download to read offline
AppointmentDemo.java
import java.util.Scanner;
/**
Demonstration of the appointment classes
*/
public class AppointmentDemo
{
public static void main(String[] args)
{
Appointment[] appointments = new Appointment[4];
appointments[0] = new Daily("Brush your teeth.");
appointments[1] = new Monthly(1, "Visit grandma.");
appointments[2] = new Onetime(2015, 11, 1, "Dentist appointment.");
appointments[3] = new Onetime(2015, 10, 31, "Trick or Treat.");
Scanner in = new Scanner(System.in);
int year = in.nextInt();
int month = in.nextInt();
int day = in.nextInt();
for (Appointment a : appointments)
{
if (a.occursOn(year, month, day))
{
System.out.println(a);
}
}
}
}
Appointment.java
/**
A class to keep track of an appointment.
*/
public abstract class Appointment
{
private String description;
/**
Constructs an appointment without a description.
*/
public Appointment()
{
description = "";
}
/**
Sets the description of this appointment.
*/
public void setDescription(String description)
{
this.description = description;
}
/**
Determines if this appointment occurs on the given date.
*/
public abstract boolean occursOn(int year, int month, int day);
/**
Converts appointment to string description.
*/
public String toString()
{
return description;
}
}
Daily.java
public class Daily extends Appointment
{
public Daily (String description)
{
setDescription(description);
}
public boolean occursOn(int year, int month, int day)
{
return true;
}
}
Onetime.java
public class Onetime extends Appointment
{
private int monthApp;
private int yearApp;
private int dayApp;
public Onetime(int yearAppInput, int monthAppInput, int dayAppInput, String description)
{
yearApp = yearAppInput;
monthApp = monthAppInput;
dayApp = dayAppInput;
setDescription(description);
}
public boolean occursOn(int year, int month, int day)
{
if ((year == yearApp) && (month == monthApp) && (day == dayApp))
{
return true;
}
else
{
return false;
}
}
}
Monthly.java
public class Monthly extends Appointment
{
private int dayApp;
public Monthly (int dayAppInput, String description)
{
dayApp = dayAppInput;
setDescription(description);
}
public boolean occursOn(int year, int month, int day)
{
if (day == dayApp)
{
return true;
}
else
{
return false;
}
}
}
Solution
AppointmentDemo.java
import java.util.Scanner;
/**
Demonstration of the appointment classes
*/
public class AppointmentDemo
{
public static void main(String[] args)
{
Appointment[] appointments = new Appointment[4];
appointments[0] = new Daily("Brush your teeth.");
appointments[1] = new Monthly(1, "Visit grandma.");
appointments[2] = new Onetime(2015, 11, 1, "Dentist appointment.");
appointments[3] = new Onetime(2015, 10, 31, "Trick or Treat.");
Scanner in = new Scanner(System.in);
int year = in.nextInt();
int month = in.nextInt();
int day = in.nextInt();
for (Appointment a : appointments)
{
if (a.occursOn(year, month, day))
{
System.out.println(a);
}
}
}
}
Appointment.java
/**
A class to keep track of an appointment.
*/
public abstract class Appointment
{
private String description;
/**
Constructs an appointment without a description.
*/
public Appointment()
{
description = "";
}
/**
Sets the description of this appointment.
*/
public void setDescription(String description)
{
this.description = description;
}
/**
Determines if this appointment occurs on the given date.
*/
public abstract boolean occursOn(int year, int month, int day);
/**
Converts appointment to string description.
*/
public String toString()
{
return description;
}
}
Daily.java
public class Daily extends Appointment
{
public Daily (String description)
{
setDescription(description);
}
public boolean occursOn(int year, int month, int day)
{
return true;
}
}
Onetime.java
public class Onetime extends Appointment
{
private int monthApp;
private int yearApp;
private int dayApp;
public Onetime(int yearAppInput, int monthAppInput, int dayAppInput, String description)
{
yearApp = yearAppInput;
monthApp = monthAppInput;
dayApp = dayAppInput;
setDescription(description);
}
public boolean occursOn(int year, int month, int day)
{
if ((year == yearApp) && (month == monthApp) && (day == dayApp))
{
return true;
}
else
{
return false;
}
}
}
Monthly.java
public class Monthly extends Appointment
{
private int dayApp;
public Monthly (int dayAppInput, String description)
{
dayApp = dayAppInput;
setDescription(description);
}
public boolean occursOn(int year, int month, int day)
{
if (day == dayApp)
{
return true;
}
else
{
return false;
}
}
}

More Related Content

More from rajat630669

What is an example of big data either from your personal experience .pdf
What is an example of big data either from your personal experience .pdfWhat is an example of big data either from your personal experience .pdf
What is an example of big data either from your personal experience .pdfrajat630669
 
S-Se=S with 3 lone pairs on the first S, 1 lone.pdf
                     S-Se=S with 3 lone pairs on the first S,   1 lone.pdf                     S-Se=S with 3 lone pairs on the first S,   1 lone.pdf
S-Se=S with 3 lone pairs on the first S, 1 lone.pdfrajat630669
 
The sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdfThe sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdfrajat630669
 
The formula for calculating Alveolar ventilation is as followsAlv.pdf
The formula for calculating Alveolar ventilation is as followsAlv.pdfThe formula for calculating Alveolar ventilation is as followsAlv.pdf
The formula for calculating Alveolar ventilation is as followsAlv.pdfrajat630669
 
D. This element can only have a -2 oxidation stat.pdf
                     D. This element can only have a -2 oxidation stat.pdf                     D. This element can only have a -2 oxidation stat.pdf
D. This element can only have a -2 oxidation stat.pdfrajat630669
 
solAn object will allocated statically when that object is needed.pdf
solAn object will allocated statically when that object is needed.pdfsolAn object will allocated statically when that object is needed.pdf
solAn object will allocated statically when that object is needed.pdfrajat630669
 
P = 12SolutionP = 12.pdf
P = 12SolutionP = 12.pdfP = 12SolutionP = 12.pdf
P = 12SolutionP = 12.pdfrajat630669
 
carbon moves by A. interstitial diffusion So.pdf
                     carbon moves by A. interstitial diffusion So.pdf                     carbon moves by A. interstitial diffusion So.pdf
carbon moves by A. interstitial diffusion So.pdfrajat630669
 
NH4Cl = acid NaOH = base They react 11 Leftover = 0.26-0..pdf
NH4Cl = acid NaOH = base They react 11 Leftover = 0.26-0..pdfNH4Cl = acid NaOH = base They react 11 Leftover = 0.26-0..pdf
NH4Cl = acid NaOH = base They react 11 Leftover = 0.26-0..pdfrajat630669
 
D is the transition represent!! Solution .pdf
                     D is the transition represent!!  Solution    .pdf                     D is the transition represent!!  Solution    .pdf
D is the transition represent!! Solution .pdfrajat630669
 
CO2 is non polar because C has no lone pairs, so .pdf
                     CO2 is non polar because C has no lone pairs, so .pdf                     CO2 is non polar because C has no lone pairs, so .pdf
CO2 is non polar because C has no lone pairs, so .pdfrajat630669
 
As more halide ions are added, it loses its color.pdf
                     As more halide ions are added, it loses its color.pdf                     As more halide ions are added, it loses its color.pdf
As more halide ions are added, it loses its color.pdfrajat630669
 
Answer.Ltext0         .local   _ZStL8__ioinit         .comm .pdf
Answer.Ltext0         .local   _ZStL8__ioinit         .comm .pdfAnswer.Ltext0         .local   _ZStL8__ioinit         .comm .pdf
Answer.Ltext0         .local   _ZStL8__ioinit         .comm .pdfrajat630669
 
d. t -2.718Solutiond. t -2.718.pdf
d. t  -2.718Solutiond. t  -2.718.pdfd. t  -2.718Solutiond. t  -2.718.pdf
d. t -2.718Solutiond. t -2.718.pdfrajat630669
 
Debt-equity ratio=DebtEQuityHence debt=1.1EquityTotal assets=De.pdf
Debt-equity ratio=DebtEQuityHence debt=1.1EquityTotal assets=De.pdfDebt-equity ratio=DebtEQuityHence debt=1.1EquityTotal assets=De.pdf
Debt-equity ratio=DebtEQuityHence debt=1.1EquityTotal assets=De.pdfrajat630669
 
Gaseous chemical element, chemical symbol O, atom.pdf
                     Gaseous chemical element, chemical symbol O, atom.pdf                     Gaseous chemical element, chemical symbol O, atom.pdf
Gaseous chemical element, chemical symbol O, atom.pdfrajat630669
 
B. Remember this - hydroboration attacks alkenes .pdf
                     B. Remember this - hydroboration attacks alkenes .pdf                     B. Remember this - hydroboration attacks alkenes .pdf
B. Remember this - hydroboration attacks alkenes .pdfrajat630669
 
a). EconomiserAn economiser is a mechanical device which is used a.pdf
a). EconomiserAn economiser is a mechanical device which is used a.pdfa). EconomiserAn economiser is a mechanical device which is used a.pdf
a). EconomiserAn economiser is a mechanical device which is used a.pdfrajat630669
 
A) As it is shown this disease should be partly autosomal recessive .pdf
A) As it is shown this disease should be partly autosomal recessive .pdfA) As it is shown this disease should be partly autosomal recessive .pdf
A) As it is shown this disease should be partly autosomal recessive .pdfrajat630669
 
2) 5Solution2) 5.pdf
2) 5Solution2) 5.pdf2) 5Solution2) 5.pdf
2) 5Solution2) 5.pdfrajat630669
 

More from rajat630669 (20)

What is an example of big data either from your personal experience .pdf
What is an example of big data either from your personal experience .pdfWhat is an example of big data either from your personal experience .pdf
What is an example of big data either from your personal experience .pdf
 
S-Se=S with 3 lone pairs on the first S, 1 lone.pdf
                     S-Se=S with 3 lone pairs on the first S,   1 lone.pdf                     S-Se=S with 3 lone pairs on the first S,   1 lone.pdf
S-Se=S with 3 lone pairs on the first S, 1 lone.pdf
 
The sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdfThe sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdf
 
The formula for calculating Alveolar ventilation is as followsAlv.pdf
The formula for calculating Alveolar ventilation is as followsAlv.pdfThe formula for calculating Alveolar ventilation is as followsAlv.pdf
The formula for calculating Alveolar ventilation is as followsAlv.pdf
 
D. This element can only have a -2 oxidation stat.pdf
                     D. This element can only have a -2 oxidation stat.pdf                     D. This element can only have a -2 oxidation stat.pdf
D. This element can only have a -2 oxidation stat.pdf
 
solAn object will allocated statically when that object is needed.pdf
solAn object will allocated statically when that object is needed.pdfsolAn object will allocated statically when that object is needed.pdf
solAn object will allocated statically when that object is needed.pdf
 
P = 12SolutionP = 12.pdf
P = 12SolutionP = 12.pdfP = 12SolutionP = 12.pdf
P = 12SolutionP = 12.pdf
 
carbon moves by A. interstitial diffusion So.pdf
                     carbon moves by A. interstitial diffusion So.pdf                     carbon moves by A. interstitial diffusion So.pdf
carbon moves by A. interstitial diffusion So.pdf
 
NH4Cl = acid NaOH = base They react 11 Leftover = 0.26-0..pdf
NH4Cl = acid NaOH = base They react 11 Leftover = 0.26-0..pdfNH4Cl = acid NaOH = base They react 11 Leftover = 0.26-0..pdf
NH4Cl = acid NaOH = base They react 11 Leftover = 0.26-0..pdf
 
D is the transition represent!! Solution .pdf
                     D is the transition represent!!  Solution    .pdf                     D is the transition represent!!  Solution    .pdf
D is the transition represent!! Solution .pdf
 
CO2 is non polar because C has no lone pairs, so .pdf
                     CO2 is non polar because C has no lone pairs, so .pdf                     CO2 is non polar because C has no lone pairs, so .pdf
CO2 is non polar because C has no lone pairs, so .pdf
 
As more halide ions are added, it loses its color.pdf
                     As more halide ions are added, it loses its color.pdf                     As more halide ions are added, it loses its color.pdf
As more halide ions are added, it loses its color.pdf
 
Answer.Ltext0         .local   _ZStL8__ioinit         .comm .pdf
Answer.Ltext0         .local   _ZStL8__ioinit         .comm .pdfAnswer.Ltext0         .local   _ZStL8__ioinit         .comm .pdf
Answer.Ltext0         .local   _ZStL8__ioinit         .comm .pdf
 
d. t -2.718Solutiond. t -2.718.pdf
d. t  -2.718Solutiond. t  -2.718.pdfd. t  -2.718Solutiond. t  -2.718.pdf
d. t -2.718Solutiond. t -2.718.pdf
 
Debt-equity ratio=DebtEQuityHence debt=1.1EquityTotal assets=De.pdf
Debt-equity ratio=DebtEQuityHence debt=1.1EquityTotal assets=De.pdfDebt-equity ratio=DebtEQuityHence debt=1.1EquityTotal assets=De.pdf
Debt-equity ratio=DebtEQuityHence debt=1.1EquityTotal assets=De.pdf
 
Gaseous chemical element, chemical symbol O, atom.pdf
                     Gaseous chemical element, chemical symbol O, atom.pdf                     Gaseous chemical element, chemical symbol O, atom.pdf
Gaseous chemical element, chemical symbol O, atom.pdf
 
B. Remember this - hydroboration attacks alkenes .pdf
                     B. Remember this - hydroboration attacks alkenes .pdf                     B. Remember this - hydroboration attacks alkenes .pdf
B. Remember this - hydroboration attacks alkenes .pdf
 
a). EconomiserAn economiser is a mechanical device which is used a.pdf
a). EconomiserAn economiser is a mechanical device which is used a.pdfa). EconomiserAn economiser is a mechanical device which is used a.pdf
a). EconomiserAn economiser is a mechanical device which is used a.pdf
 
A) As it is shown this disease should be partly autosomal recessive .pdf
A) As it is shown this disease should be partly autosomal recessive .pdfA) As it is shown this disease should be partly autosomal recessive .pdf
A) As it is shown this disease should be partly autosomal recessive .pdf
 
2) 5Solution2) 5.pdf
2) 5Solution2) 5.pdf2) 5Solution2) 5.pdf
2) 5Solution2) 5.pdf
 

Recently uploaded

會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxLimon Prince
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 

Recently uploaded (20)

會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 

AppointmentDemo.javaimport java.util.Scanner;    Demonstrat.pdf

  • 1. AppointmentDemo.java import java.util.Scanner; /** Demonstration of the appointment classes */ public class AppointmentDemo { public static void main(String[] args) { Appointment[] appointments = new Appointment[4]; appointments[0] = new Daily("Brush your teeth."); appointments[1] = new Monthly(1, "Visit grandma."); appointments[2] = new Onetime(2015, 11, 1, "Dentist appointment."); appointments[3] = new Onetime(2015, 10, 31, "Trick or Treat."); Scanner in = new Scanner(System.in); int year = in.nextInt(); int month = in.nextInt(); int day = in.nextInt(); for (Appointment a : appointments) { if (a.occursOn(year, month, day)) { System.out.println(a); } } } } Appointment.java /** A class to keep track of an appointment. */ public abstract class Appointment { private String description; /**
  • 2. Constructs an appointment without a description. */ public Appointment() { description = ""; } /** Sets the description of this appointment. */ public void setDescription(String description) { this.description = description; } /** Determines if this appointment occurs on the given date. */ public abstract boolean occursOn(int year, int month, int day); /** Converts appointment to string description. */ public String toString() { return description; } } Daily.java public class Daily extends Appointment { public Daily (String description) { setDescription(description); } public boolean occursOn(int year, int month, int day) {
  • 3. return true; } } Onetime.java public class Onetime extends Appointment { private int monthApp; private int yearApp; private int dayApp; public Onetime(int yearAppInput, int monthAppInput, int dayAppInput, String description) { yearApp = yearAppInput; monthApp = monthAppInput; dayApp = dayAppInput; setDescription(description); } public boolean occursOn(int year, int month, int day) { if ((year == yearApp) && (month == monthApp) && (day == dayApp)) { return true; } else { return false; } } } Monthly.java public class Monthly extends Appointment { private int dayApp; public Monthly (int dayAppInput, String description) {
  • 4. dayApp = dayAppInput; setDescription(description); } public boolean occursOn(int year, int month, int day) { if (day == dayApp) { return true; } else { return false; } } } Solution AppointmentDemo.java import java.util.Scanner; /** Demonstration of the appointment classes */ public class AppointmentDemo { public static void main(String[] args) { Appointment[] appointments = new Appointment[4]; appointments[0] = new Daily("Brush your teeth."); appointments[1] = new Monthly(1, "Visit grandma."); appointments[2] = new Onetime(2015, 11, 1, "Dentist appointment."); appointments[3] = new Onetime(2015, 10, 31, "Trick or Treat."); Scanner in = new Scanner(System.in); int year = in.nextInt(); int month = in.nextInt();
  • 5. int day = in.nextInt(); for (Appointment a : appointments) { if (a.occursOn(year, month, day)) { System.out.println(a); } } } } Appointment.java /** A class to keep track of an appointment. */ public abstract class Appointment { private String description; /** Constructs an appointment without a description. */ public Appointment() { description = ""; } /** Sets the description of this appointment. */ public void setDescription(String description) { this.description = description; } /** Determines if this appointment occurs on the given date. */ public abstract boolean occursOn(int year, int month, int day); /**
  • 6. Converts appointment to string description. */ public String toString() { return description; } } Daily.java public class Daily extends Appointment { public Daily (String description) { setDescription(description); } public boolean occursOn(int year, int month, int day) { return true; } } Onetime.java public class Onetime extends Appointment { private int monthApp; private int yearApp; private int dayApp; public Onetime(int yearAppInput, int monthAppInput, int dayAppInput, String description) { yearApp = yearAppInput; monthApp = monthAppInput; dayApp = dayAppInput; setDescription(description); } public boolean occursOn(int year, int month, int day)
  • 7. { if ((year == yearApp) && (month == monthApp) && (day == dayApp)) { return true; } else { return false; } } } Monthly.java public class Monthly extends Appointment { private int dayApp; public Monthly (int dayAppInput, String description) { dayApp = dayAppInput; setDescription(description); } public boolean occursOn(int year, int month, int day) { if (day == dayApp) { return true; } else { return false; } } }