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

Can anyone help me out with this? In this assignment, you will write a Java prog

ID: 3671797 • Letter: C

Question

Can anyone help me out with this? In this assignment, you will write a Java program that first asks the user for a list of dates, and then prints the earliest date and the latest date. Here is an example run of the program (user input is in red, and your print statements are in black): Enter a list of dates: 3/12/2005, 6/16/2015, 4/9/1999, 8/31/2015, 2/1/1999 Earliest date: 2/1/1999 Latest date: 8/31/2015 Requirements This program should contain a single class (called Proj6) with a main method that compiles and runs in BlueJ. Here are some additional requirements: The dates from the user must be stored in an int[][] array. Each row in the array will represent a different date from the list. The first column will represent the month, the second column will represent the day, and the last column will represent the year. For example, in the list of dates above, index [0][1] in your array should be 12. (The 0 means the first date, 3/12/2005, and the 1 means the month for that date -- 12.) You must use a StringTokenizer to break apart the list of dates and store them in your array. A suggested algorithm is provided below. This project is somewhat similar to the "Max and Min" example in the Arrays chapterPreview the documentView in a new window. Just like this example, you will want to keep a current "smallest" date and a current "largest" date. You will need to do more work to see if one date is "less than" another date, though. When finding the earliest and latest dates, remember that several dates can have the same year and the same month. For example, 8/31/2015 is later than 8/16/2015. This means that if you are comparing a date in your array to your current "smallest" date, if the years of the two dates are the same, you will then need to compare the month values and possibly the day values. Here is a suggested algorithm for breaking apart the list of dates into an array: Get the list of dates as a String from the user Use a StringTokenizer, st, on the list, with ", /" (space, comma, slash) as your delimeters Create an array with st.countTokens() rows and 3 columns For each row in the array (start i at 0, use .length to get the number of rows in your array) Set spot [i][0] in your array to the next token from the StringTokenizer (the month) Set spot [i][1] in your array to the next token from the StringTokenizer (the day) Set spot [i][2] in your array to the next token from the StringTokenizer (the year)

Explanation / Answer

import java.util.Scanner;
import java.util.StringTokenizer;

/*
* This program is to find square of first 20 numbers
*/
class Proj6{
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int[][] dates = new int[20][3];
       System.out.println("How many years you want to enter: ");
       int n = sc.nextInt();
       for(int i=0;i<n;i++){
           String date = sc.next(); //reading dates
          
           StringTokenizer token = new StringTokenizer(date, "/");// tokenizing string using '/'
           dates[i][0] = Integer.parseInt(token.nextToken()); // getting month
           dates[i][1] = Integer.parseInt(token.nextToken()); // getting days number
           dates[i][2] = Integer.parseInt(token.nextToken()); // getting year
       }
       sc.close();
       int minM = dates[0][0],minD =dates[0][1],minY = dates[0][2]; // initializing minimum date from first date
       int maxM = dates[0][0] ,maxD = dates[0][1],maxY = dates[0][2];//initializing maximum with first date
      
       for(int i=1;i<n;i++){ // iterating from second date to last
      
           if(minY >= dates[i][2]){// if current date year is equal or greater than minY
               if(dates[i][2] < minY){ // if year is less
                   minY = dates[i][2]; minM = dates[i][0]; minD = dates[i][1];
               }else if(minM > dates[i][0]){// if year is same as minY but month is lesser than minM
                   minM = dates[i][0]; minD = dates[i][1];
               }else if(minD > dates[i][1])// year and month is same as minY and minM but date is lesser than minD
                   minD = dates[i][1];
           }else if(maxY >= dates[i][2]){// else if current year is greater or equal to maxY
               if(dates[i][2] > maxY){// if maxY == current year
                   maxY = dates[i][2]; maxM = dates[i][0]; maxD = dates[i][1]; // year is same but month is greateer than maxM
               }else if(maxM < dates[i][0]){//year is same but month is greater than maxM
                   maxM = dates[i][0]; maxD = dates[i][1];
               }else if(maxD < dates[i][1])// year and month is same but date is greater than maxD
                   maxD = dates[i][1];
           }
       }
      
       System.out.println("Max Date: "+maxM+"/"+maxD+"/"+maxY);
       System.out.println("Min Date: "+minM+"/"+minD+"/"+minY);
}
}

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