This project is meant to take a user input of month day, year . Where the user i
ID: 3912073 • Letter: T
Question
This project is meant to take a user input of month day, year . Where the user inputs month as a string and day as an integer and year as an integer. We are to convert it into dayOfWeek, month day, year. For example: Enter date to be converted (month day, year): ocTober 1, 1997 Converted date: Monday, October 1, 1997.
We will need to use methods from the String class and Boolean expressions and also the if control structure will need to be utilized. I have added pics of the actual project assignment so you can read it. There is a bonus if you add Error checking.
I thought this was gonna be simple but I can’t seem to get it right, please help me I thank you soooooo much! Computer Science 204 Program #3 The Date Program Due Date: Monday, July 16th 20 Points Objective The purpose of this assignment is to extend students' familiarity with using different classes. In particular, students will be making use of the methods from the String class. In addition, boolean expressions and the if control structure will be utilized. Assignment Summary Write a program named ConvertDate that converts a date entered by the user into another form. The user's input will have the form month day, year The month will be one of the words January, February,.. The letters in the month may be lowercase, uppercase, or any mixture of the two. The day is a one- or two-digit number. The year is a four-digit number. There may be any number of spaces as follows. . before the month, . between the month and the day, , between the day and the year, and , after the year. You may assume there is at least one space between the month and day and between the day and year, and you may assume that there is a comma after the day. You may also assume all input is valid. The converted date must have the form dayOfWeek, month day, year with one space between each of the four outputs. The first letter of the day of week and month must be uppercase, and the remaining letters must be lowercase.
Explanation / Answer
CODE
==============
import java.util.Scanner;
public class ConvertDate {
public static int getMonthIndex(String month) {
if(month.equalsIgnoreCase("march"))
return 3;
if(month.equalsIgnoreCase("april"))
return 4;
if(month.equalsIgnoreCase("may"))
return 5;
if(month.equalsIgnoreCase("june"))
return 6;
if(month.equalsIgnoreCase("july"))
return 7;
if(month.equalsIgnoreCase("august"))
return 8;
if(month.equalsIgnoreCase("september"))
return 9;
if(month.equalsIgnoreCase("october"))
return 10;
if(month.equalsIgnoreCase("november"))
return 11;
if(month.equalsIgnoreCase("december"))
return 12;
if(month.equalsIgnoreCase("january"))
return 13;
if(month.equalsIgnoreCase("february"))
return 14;
return 0;
}
public static String getDayOfWeek(int i) {
if(i == 0)
return "Saturday";
if(i == 1)
return "Sunday";
if(i == 2)
return "Monday";
if(i == 3)
return "Tuesday";
if(i == 4)
return "Wednesday";
if(i == 5)
return "Thursday";
if(i == 6)
return "Friday";
return "";
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String month, dayYear;
int day, year;
System.out.println("Enter date to be converted (month day, year) : ");
String in = sc.nextLine();
String[] splits = in.split(" ");
month = splits[0];
day = Integer.parseInt(splits[1].substring(0, splits[1].length()-1));
year = Integer.parseInt(splits[2]);
int j = year % 100;
int K = year/100;
int m = getMonthIndex(month);
int q = day;
int h = (q + 26*(m+1)/10 + K + K/4 + j/4 + 5*j) % 7;
System.out.println(getDayOfWeek(h) + ", " + month+ " " + day + ", " + year);
}
}
NOTE: The code is partialy correct as I could not understand the logic behind how to get the value of K and m. Please explain it to me properly when to assign January to 13 and Fenruary to 14. Once you do so, I will update this code to give you the correct results.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.