Question: Exercise 2 assigment help needed on Palindrome Dates with using stacks in Java. The program gives a runtime error with year 8190. Please help out

Exercise 2 assigment help needed on Palindrome Dates with using stacks in Java. The program gives a runtime error with year 8190. Please help out in the code

import java.util.Stack;

import javax.swing.JOptionPane;

public class Exercise2 {

public static String getPalindromicDate(int year) { int yeart = year; Stack stack = new Stack (); int div = 1000; int[] numberOfDays = {31, 28, 31, 30, 31, 31, 31, 30, 31}; for(int k = 0; k 1 && mm 0 && numberOfDays[mm] >= dd) { return "" + smm + "-" + sdd + "-" + yeart; } return null; } public static void main(String[] args) { // TODO Auto-generated method stub String s = ""; do { s = JOptionPane.showInputDialog("hi"); System.out.println(getPalindromicDate(Integer.parseInt(s))); } while (!s.equals("-1")); }

}

Exercise 2 assigment help needed on Palindrome Dates with using stacks in

CSC 241 Exercise 2 The following date of the form: MM-DD-YYYY would be palindromic if it read the same way backwards: YY-YY-DDMM. For example, the date: 12-02-2021 is palindromic. Write a method getPalindromicDate that takes an integer (a year) as input and then returns a palindromic date. The palindromic date should be stored in a stack based data structure using dynamic memory allocation (LinkedStack). If the year does not give a palindromic date, then the returned stack will be null. Only Gregorian calendar dates are allowed and the stack should maintain the ordering of the dates as: Where MM is the top of the stack. MM and DD must be two digits, so if there is a single digit a zero must precede it. For example, the following date: 03-12-2130. The following palindrome would not be a valid palindromic date: 40-52-2504, because there is not a 40th month of the year, nor a 52nd day in any given month. Write a driver program that will test the getPalindromicDate method by printing out the stack returned with the appropriate formatting to appear palindromic and as a date, given there is such a date for the given year

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!