Question

In: Computer Science

Write a complete Java Program to solve the following problem. February 18 is a special date...

Write a complete Java Program to solve the following problem.

February 18 is a special date as this is the date that can be divisible by both 9 and 18

Write a program that asks the user for a numerical month and numerical day of the month and then determines whether that date occurs before, after, or on February 18.

If the date occurs before February 18, output the word Before. If the date occurs after February 18, output the word After. If the date is February 18, output the word Special.

Note: Passing the sample test cases are not enough to earn the full marks. You need to test your program for different months and dates to see whether your program will work in all the cases.

Input

The input consists of two integers each on a separate line. These integers represent a date in 2015.
The first line will contain the month, which will be an integer in the range from 1 (indicating January) to 12 (indicating December).
The second line will contain the day of the month, which will be an integer in the range from 1 to 31. You can assume that the day of the month will be valid for the given month.

Output

Exactly one of Before, After or Special will be printed on one line.

Sample Input 1

1
7

Sample Output 1

Before

Sample Input 2

8
31

Sample Output 2

After

Sample Input 3

2
18

Sample Output 3

Special

Must be coded in java. Easy code for grade 11 class

Solutions

Expert Solution

Code :-

import java.util.Scanner;

class SpecialDay{
public static void main(String[] args){

Scanner sc=new Scanner(System.in);
int month=sc.nextInt();
int day=sc.nextInt();
if(month>=1 && month <=12){

if(month==2 && day==18){
       System.out.println("Special");
     }
else if(month<=2 && day<18){
       System.out.println("Before");
     }
else {
       System.out.println("After");
     }
}

 
}
}

--------------------------------------------------------------------------

Code with explanation :-

import java.util.Scanner;

class SpecialDay{
public static void main(String[] args){

Scanner sc=new Scanner(System.in);
int month=sc.nextInt();
int day=sc.nextInt();
if(month>=1 && month <=12){    //code executes only when the month is a valid input

if(month==2 && day==18){          // if month is 2 and day is 18 then its a special day
       System.out.println("Special");
     }
else if(month<=2 && day<18){      // if month is less than or equal to 2 and day is less than 
                                 //18 then its "Before" is printed.
       System.out.println("Before");
     }
else {                              //In all the other remaining cases output should be "After"
       System.out.println("After");
     }
}
                                 //Note:- Code executes only when valid month is given
                                 // Day is assumed to be correct to the respective month.
 
}
}

--------------------------------------------------------------------------

Output Screenshot :-

-----------------------------------------------------------------

Thank you.


Related Solutions

Write a complete Java program to solve the following problem. Read two positive integers from the...
Write a complete Java program to solve the following problem. Read two positive integers from the user and print all the multiple of five in between them. You can assume the second number is bigger than the first. For example if the first number is 1 and the second number is 10, then your program should output 5 10 Java must be grade 11 work easy to understand and not complicated code
Write a complete and syntactically correct Python program to solve the following problem: You are the...
Write a complete and syntactically correct Python program to solve the following problem: You are the payroll manager for SoftwarePirates Inc. You have been charged with writing a package that calculates the monthly paycheck for the salespeople. Salespeople at SoftwarePirates get paid a base salary of $2000 per month. Beyond the base salary, each salesperson earns commission on the following scale: Sales Commission Rate Bonus <$10000 0% 0 $10000 – $100,000 2% 0 $100,001 - $500,000 15% $1000 $500,001 -...
Write a complete program in java that will do the following:
Write a complete program in java that will do the following:Sports:             Baseball, Basketball, Football, Hockey, Volleyball, WaterpoloPlayers:           9, 5, 11, 6, 6, 7Store the data in appropriate arraysProvide an output of sports and player numbers. See below:Baseball          9 players.Basketball       5 players.Football           11 players.Hockey            6 players.Volleyball        6 players.Waterpolo       7 players.Use Scanner to provide the number of friends you have for a team sport.Provide an output of suggested sports for your group of friends. If your...
Java Complete Example.java to fulfill the following problem statement: Write a program to accept a list...
Java Complete Example.java to fulfill the following problem statement: Write a program to accept a list of numbers, one per line. Input is provided from a file if one is provided as the first command line argument. If a file is not provided, input should be read from the terminal. The numbers can either be whole numbers or floating point numbers. The program should continue to accept input until a number equal to 00 is input. Of course, if the...
DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1....
DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1. Write an abstract Java class called Shape which has only one abstract method named getArea(); 2. Write a Java class called Rectangle which extends Shape and has two data membersnamed width and height.The Rectangle should have all get/set methods, the toString method, and implement the abstract method getArea()it gets from class Shape. 3. Write the driver code tat tests the classes and methods you...
URGENT!!! DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps:...
URGENT!!! DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1. Write an abstract Java class called Shape which has only one abstract method named getArea(); 2. Write a Java class called Rectangle which extends Shape and has two data membersnamed width and height.The Rectangle should have all get/set methods, the toString method, and implement the abstract method getArea()it gets from class Shape. 3. Write the driver code tat tests the classes and methods...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
Write a java program that will ask for a Star Date and then convert it into...
Write a java program that will ask for a Star Date and then convert it into the corresponding Calendar date. without using array and methods.
A: Write a divide-and-conquer program to solve the following problem:
in Java A: Write a divide-and-conquer program to solve the following problem:     1. Let A[1..n] and B[1..n] be two arrays of distinct integers, each sorted in an increasing order.      2. Find the nth smallest of the 2n combined elements. Your program must run in O(log n) time. For example: n = 4If A[1..n] = {2, 5, 8, 9} and B[1..n] = {1, 4, 6, 7}The nth (i.e. 4th) smallest integer is 5.If A[1..n] = {2, 5, 8, 13}...
Write a program ( Java) to solve the 8-puzzle problem (and its natural generalizations) using the...
Write a program ( Java) to solve the 8-puzzle problem (and its natural generalizations) using the A* search algorithm. The problem. The 8-puzzle problem is played on a 3-by-3 grid with 8 square blocks labeled 1 through 8 and a blank square. Your goal is to rearrange the blocks so that they are in order. You are permitted to slide blocks horizontally or vertically into the blank square. The following shows a sequence of legal moves from an initial board...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT