Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a java application, Date, that reads an 8-digit integer value (indicating

ID: 3672770 • Letter: W

Question

Write a java application, Date, that reads an 8-digit integer value (indicating a date) from the keyboard; the first two digits indicate the month, the second two digits represent the day and the last 4 digits represent the year.

After calculating the month, the application will implement a switch statement to output the month.

After displaying the date, the application will implement a nested if else statement to output the appropriate century. i.e

Prev17th century, 18th century, 19th century, 20th century, 21th century, Post 21stcentury.

So the output should look like this:

Enter a 8-digit integer date: 06171993

Entered date is June 17, 1993

20th Century

Explanation / Answer

import java.io.*;

import java.util.Scanner;

public class myDate

{

public static void main(String args[])

{

long m,d,y,in;

Scanner user = new Scanner(System.in);

System.out.println("enter 8 digit integer mmddyyyy");

in=user.nextInt();

m=(in/1000000);

switch('m')

{

case 01: System.out.print("January");

break;

case 02: System.out.print("February");

break;

case 03: System.out.print("March");

break;

case 04: System.out.print("April");

break;

case 05: System.out.print("May");

break;

case 06: System.out.print("June");

break;

case 07: System.out.print("July");

break;

case 08: System.out.print("August");

break;

case 09: System.out.print("September");

break;

case 10: System.out.print("October");

break;

case 11: System.out.print("November");

break;

case 12: System.out.print("December");

break;

default:

break;

}

long x=(in/10000);

d=x%100;

System.out.print(d+",");

y=in%10000;

System.out.println(y);

long c = (y/100)+1;

if(c <18)

System.out.println("Prev17th century");

else if(c==18)

System.out.println("18th century");

else if(c==19)

System.out.println("19th century");

else if(c==20)

System.out.println("20th century");

else if(c==21)

System.out.println("21st century");

else

System.out.println("post 21st century");

}

}

There can be little issue with the type conversion, otherwise, the logic and code is correct.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote