Question: So doing a Calendar Assignment 1 projects My problem is that when I enter the date I can't use a / when asking the user

So doing a Calendar Assignment 1 projects

My problem is that when I enter the date I can't use a / when asking the user for input. such as 03/18. it works sort of with 03 18. but I don't know how to get the date to post

Here is the code:

import java.util.*;

public class CalendarPart1 { public static final int SIZE = 7; public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.print("What date do you want to look at?(mm/dd): "); int x = console.nextInt(); Calendar display = Calendar.getInstance(); int f = display.get(Calendar.MONTH) + 1; int h = display .get(Calendar.DATE); //monthFromDate(); drawMonth(5, x); displayDate(x, 7); System.out.println(); System.out.println("This is the current month: "); drawMonth(5, f); displayDate(f,h); } public static void drawRow(int row) { int day = 1; for(int i = 0; i < row; i++) { System.out.print("|"); for(int a = 1; a <= 7; a++) { int length=String.valueOf(day).length(); for(int j = 1; j < SIZE - length; j++) { System.out.print(" "); } System.out.print(day); day++; System.out.print("|"); } System.out.println(); for(int t = 1; t < (SIZE /2); t++) { System.out.print("|"); for(int h = 1; h<=7; h++) { for(int f = 1; f <= SIZE - 1; f++) { System.out.print(" "); } System.out.print("|"); } System.out.println(); } for(int e = 1; e <= SIZE * 7; e++) { System.out.print("="); } System.out.println(); } } public static void drawMonth(int num, int month) { for(int i = 1; i <= 1; i++) { for(int j = 1; j <= (SIZE * 7) / 2; j++) { System.out.print(" "); } System.out.print(month); for(int d = 1; d <= (SIZE * 7) / 2 ; d++) { System.out.print(" "); } System.out.println(); } for(int g =1; g <= SIZE * 7; g++) { System.out.print("="); } System.out.println(); drawRow(num); } public static void displayDate(int month, int day) { System.out.println("Month:" + month); System.out.println("Day:" + day); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!