1 Reply Latest reply: Sep 28, 2012 6:47 AM by notivago RSS

    Need help with Beginner java code

    965011
      Hi guys i am currently taking a java class and have never programmed before. i need to write a program that takes 3 parameters (month, day, year). Then outputs the day of the week, the date, whether or not the year is a leap year and the number of days left in the year. I have everything working except for the day of the week and the number of days left in the year.
      Here is my code:
      import java.util.*;
      import java.util.GregorianCalendar;
      import java.text.DateFormat;
       public class leapYear {
      
       public static void main(String[] args) throws Exception {
       
       
      GregorianCalendar newCal = new GregorianCalendar();
      
           int m = Integer.parseInt (args[0]);
           int d = Integer.parseInt (args[1]);
           int y = Integer.parseInt (args[2]);
      
      
          newCal.set(y, m, d);
      
           
      
          String[] months = new String[]{
                "January",
              "February",
              "March",
              "April",
              "May",
              "June",
              "July",
                "August",
                "September",
                "October",
                "November",
                "December",
          };
      
           System.out.println( (newCal.get(Calendar.DAY_OF_WEEK)) + " - " + (months[newCal.get(Calendar.MONTH) - 1]) + " " + d + ", " + y);
           
           if(newCal.isLeapYear(y) == true)
           {
                System.out.println(y + " is a leap year");
           }
           else
           {
                System.out.println(y + " is Not a leap year");
           }
           
      int dayOfYear = newCal.get(newCal.DAY_OF_YEAR);
      int lastDayOfYear = newCal.getActualMaximum(Calendar.DAY_OF_YEAR);
      int diff = lastDayOfYear - dayOfYear;
      System.out.println("There are " + diff + " days left in the year.");
      
      
           
           
      
                
       }
      
      }
      i would really appreciate if someone can help me out.
      Thank You.