Have a Question ?

Home / Answered Questions / Other / make-the-attached-screen-or-gui-work-they-must-apply-exception-handling-for-this-program-dayofweek-a-aw675

(Solved): Make The Attached Screen Or GUI Work. They Must Apply Exception Handling For This Program (DayOfWeek...


Make the attached screen or GUI work.

They must apply Exception Handling for this program (DayOfWeek and DayOfWeekDriver)

DayOfWeek.java:

package edu.pupr.DayOfWeek;

import java.util.Scanner;
import java.util.InputMismatchException;
//public class
public class DayOfWee
{
   // find day of week
   static void findweek(int day, int month, int year)
   {
  
   // January month
   if (month == 1)
   {
   month = 13;
   year--;
   }
  
   // February month
   if (month == 2)
   {
   month = 14;
   year--;
   }

   int q = day;
   int m = month;
   int k = year % 100;
   int j = year / 100;

   int h = (q + 26 * ( m + 1) / 10 + k + k / 4 + j / 4 + 5 * j) % 7;
  
   System.out.print("The Day is : ");
//switch and case based on the birthday
   switch (h)
   {
   case 0 :
   System.out.println("Saturday");
   break;
   case 1 :
   System.out.println("Sunday");
   break;
   case 2 :
   System.out.println("Monday");
   break;
   case 3 :
   System.out.println("Tuesday");
   break;
   case 4 :
   System.out.println("Wednesday");
   break;
   case 5 :
   System.out.println("Thursday");
   break;
   case 6 :
   System.out.println("Friday");
   break;
   }
  
   }
//Public void for the ask function
   public void ask()
   {
           Scanner scan = new Scanner(System.in);
      
           int day = 0 ;
       int month = 0 ;
       int year = 0 ;
      
       // Exception handling
       try {
      
       System.out.print("Enter day: ");
       day = scan.nextInt();
      
       if(day < 1 || day > 31)
       {
       System.out.println("Day not valid");
       System.exit(0);
       }
      
       System.out.print("Enter a month: ");
       month = scan.nextInt();
      
       if(month < 1 || month > 12)
       {
       System.out.println("Month not valid");
       System.exit(0);
       }
      
       System.out.print("Enter year: ");
       year = scan.nextInt();
      
       }
      
       catch(InputMismatchException e) {
       System.out.println("Argument not valid");
       System.exit(0);
       }
   }
//public void for the show function
   public void show()
   {
           int day = 0 ;
       int month = 0 ;
       int year = 0 ;
      
       findweek(day,month,year);
   }
}

DayOfWeekDriver.java:

package edu.pupr.DayOfWee;

public class DayOfWeeDriver {
   public static void main(String[] args)
   {
       // Using Scanner for Getting Input from User
      
       DayOfWee in = new DayOfWee();
      
           in.ask();
           in.show();
   }
}

This must contain a GUI along with an exception handling. This must be done in eclipse using Java



We have an Answer from Expert View Expert Answer

Expert Answer


The code belongs to two .java files. DayOfWeek.java and DayOfWeekDriver.java. - The name of the class should be same as the java file name. So either the file name need to be changed or the
We have an Answer from Expert
Buy This Answer $6

-- OR --

Subscribe To View Unlimited Answers
Subscribe $20 / Month