So I was asked to make a method that tells you what day a 4 of july will fall on
ID: 3621614 • Letter: S
Question
So I was asked to make a method that tells you what day a 4 of july will fall on. the problem is I dont know how to use it, as in how to call it in the tester classpublic class SpeedDating
{
// Note: this class has no instance variables!
/**
* Create an empty SpeedDating object
* (this is known as a "default" constructor)
*/
public SpeedDating()
{} // Constructor has empty body
/**
* Prints the day of the week (e.g. "Thursday") on which the 4th of July
* will fall in 10 consecutive years
* @param startYear the first of the 10 consecutive years
*/
public void print4thOfJulys(int startYear)
{
for (int start = startYear; start ==startYear+10; start++ )
{
Date july4 = new Date(7,14,startYear);
System.out.println("4th of July on the year" + startYear
+ "will fall on " + july4.getDayOfWeek());
}
}
Explanation / Answer
Dear, Here is the code import java.util.Calendar; class Demo//IterativePower { //Begin main function public static void main( String args[] ) { SpeedDating sp=new SpeedDating(); sp.print4thOfJulys(2000); System.exit(0); } } class SpeedDating { // Note: this class has no instance variables! /** * Create an empty SpeedDating object * (this is known as a "default" constructor) */ public SpeedDating() {} // Constructor has empty body /** * Prints the day of the week (e.g. "Thursday") on which the 4th of July * will fall in 10 consecutive years * @param startYear the first of the 10 consecutive years */ public void print4thOfJulys(int startYear) { int day; for (int start = startYear; start ==startYear+10; start++ ) { java.util.Calendar july4= java.util.Calendar.getInstance(); july4.set(7, 4, start); day=july4.getDayOfWeek(); System.out.print("4th of July on the year" + startYear+"will fall on " ); switch(day) { case 1:System.out.print("Sunday " ); break; case 2:System.out.print("Monday " ); break; case 3:System.out.print("Tuesday " ); break; case 4:System.out.print("Wednesday " ); break; case 5:System.out.print("Thursday " ); break; case 6:System.out.print("Friday " ); break; case 7:System.out.print("Saturday " ); break; } } } } Hope this will help you..
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.