0% found this document useful (0 votes)
14 views4 pages

Java Program for Monthly Messages

Uploaded by

Sagar Singh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Java Program for Monthly Messages

Uploaded by

Sagar Singh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Date-25/10/2024

---------------------------------------------------------------------------------
Name—Sagar Kumar Singh Id—221001001065
Batch—BCS 3A (Group A) Subject—Java lab

1. Create a class that prints different messages for different


months. It takes a user input and based on the month
entered by the user, It print appropriate message. Use if-
else or switch to implement this.
Code-:
import [Link];

class MonthMessage {
private String month;

public MonthMessage(String month) {


[Link] = [Link]();
}

public void printMessage() {


switch (month) {
case "january":
[Link]("New Year celebrations!");
break;
case "february":
[Link]("Valentine's month!");
break;
case "march":
[Link]("Spring is coming!");
break;
case "april":
[Link]("April showers bring May
flowers.");
break;
case "may":
[Link]("It's almost summer!");
break;
case "june":
[Link]("Halfway through the year!");
break;
case "july":
[Link]("Summer vacation!");
break;
case "august":
[Link]("Back to school month.");
break;
case "september":
[Link]("Fall is near!");
break;
case "october":
[Link]("Halloween season!");
break;
case "november":
[Link]("Thanksgiving time!");
break;
case "december":
[Link]("Holiday season!");
break;
default:
[Link]("Invalid month entered.");
}
}

public static void main(String[] args) {


Scanner scanner = new Scanner([Link]);
[Link]("Enter a month: ");
String month = [Link]();
MonthMessage monthMessage = new
MonthMessage(month);
[Link]();
[Link]();
}
}

You might also like