Question: create a class within a project that throws exceptions for blank or empty inputs. test.java import java.util.Scanner; public class test { public static void

create a class within a project that throws exceptions for blank or empty inputs. 

 


test.java

import java.util.Scanner; public class test { public static void main(String[] args) { //accepting the required values from user using Scanner class String name2,nameS,name1,title; double salF,salS; Scanner sc=new Scanner(System.in); System.out.print(" Enter the faculty name: "); name2=sc.nextLine(); //name2 System.out.print("Enter the salary: "); salF=sc.nextDouble(); //salF System.out.print("Enter the department name: "); name1=sc.next(); //name1 //Working Exception **fix illegalstaffnameargumentexception, test2 to catch invalid arguments if (name2 == null || name2.isBlank() || name2.isEmpty()) throw new IllegalArgumentException("Im Sorry, a faculty name has not been entered into the system."); sc.nextLine(); System.out.print(" Enter the staff name: "); nameS=sc.next(); //nameS System.out.print("Enter the salary: "); salS=sc.nextDouble(); //salS System.out.print("Enter the Job title: "); title=sc.next(); //title //Instantiation of Faculty class Faculty fac=new Faculty(name2,salF,name1); System.out.println(" Details of Faculty:"); System.out.println("-*-*-*-*-*"); System.out.println(fac); //displays details of faculty //constructor for Exceptions //Instantiation of staff class Staff i =new Staff(title, salS, title); System.out.println(" Details of Staff:"); System.out.println("-*-*-*-*-*"); System.out.println(i); //prints job title System.out.println(nameS); //prints name System.out.println(" "); // gives space System.out.println("Alvin Sarkadi, Discussion 3, CMIS 242 - 6384 1/29/2022"); } } 

IllegalStaffNameArgumentException

public class IllegalStaffNameArgumentException extends IllegalArgumentException { public String noStaff; public IllegalStaffNameArgumentException(String nameS) { if (nameS == null) noStaff = "Staff cannot be named null"; else if (nameS.isBlank()) noStaff = "Staff name cannot be blank."; else if (nameS.isEmpty()) noStaff = "Staff name cannot be empty."; } public String toString() { return this.getClass().getSimpleName() + " : " + noStaff; } }

test2.java

 public class test2 { public static void main(String[] args) { try { test2 IllegalStaffNameArgumentException= new test2(); } catch (IllegalStaffNameArgumentException i) { System.out.println(i.toString()); }catch (IllegalArgumentException i2) { System.out.println("Exception has been caught: IllegalArgumentException"); } } }

Step by Step Solution

3.44 Rating (144 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres the corrected code for your requirements IllegalStaffNameArgumentExceptionjava public class Il... View full answer

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 Programming Questions!