0% found this document useful (0 votes)
16 views

Java 1

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)
16 views

Java 1

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
You are on page 1/ 4

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 java.util.Scanner;

class MonthMessage {
private String month;

public MonthMessage(String month) {


this.month = month.toLowerCase();
}

public void printMessage() {


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

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);
System.out.print("Enter a month: ");
String month = scanner.nextLine();
MonthMessage monthMessage = new
MonthMessage(month);
monthMessage.printMessage();
scanner.close();
}
}

You might also like