public class Question1
{
/* For this part of the assignment you will need to make a custom
Exception class
before you continue.
1) Create a class (in this same package) with the name
MyException
that inherits directly from the Exception class.
2) Complete the body of the method below by adding a single line
that
generates an instance of the exception class you just
created.
When creating your myException object use the following message as
an argument to the Constructor method:
"Look ma, I can throw exceptions now."
3) Make sure to modify the method header to declare that the
method
throws instances of the MyException class.
*/
public static void Question1()
{
}
}
public class Question1
{
/* For this part of the assignment you will need to
make a custom Exception class
before you continue.
1) Create a class (in this same package) with the name
MyException
that inherits directly from the Exception class.
2) Complete the body of the method below by adding a single line
that
generates an instance of the exception class you just
created.
When creating your myException object use the following message as
an argument to the Constructor method:
"Look ma, I can throw exceptions now."
3) Make sure to modify the method header to declare that the
method
throws instances of the MyException class.
*/
public static void main(String[] args) throws
MyException {
question1();
}
//declared as throws MyException
public static void question1() throws
MyException
{
// throwing the exception using the
keyword new MyException
throw new MyException("Look ma, I
can throw exceptions now.");
}
}
class MyException extends Exception{
public MyException(String s) {
super(s);
}
}

Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me
public class Question1 { /* For this part of the assignment you will need to make...
File Factorials.java contains a program that calls the factorial method of the MathUtils class to compute the factorials of integers entered by the user. In this program, two things can possibly occur: The program always returns 1 if negative integers are entered by the user. Returning 1 as the factorial of any negative integer is not correct. The program also returns negative numbers when the user enters integers greater than 16. Returning a negative number for values over 16 also...
given the following two classes Within a file named Rational.java, define a public class named Rational such that … the Rational class has two private instance variables, numerator and denominator, both of type int the Rational class defines two public accessor methods, numerator() and denominator() the Rational class defines a constructor that has one String parameter a throws clause indicates that this constructor could potentially throw a MalformedRationalException this constructor throws a MalformedRationalException in the following circumstances … When the...
Given the following class: public class Vehicle { protected String manufacturer; // vehicle manufacturer protected int year; // model year protected char fuelType; // G = gas, E = electric, D = diesel, W = wind, U = unknown protected String VIN; // an String to hold the 17 characters of the vehicle's VIN number. ... // no-arg constructor defined, as are all get/set methods. } Write me: An overloaded constructor (takes the four data members as parameters): assume that...
Needs Help In Java Programming language Exceptional Cars Purpose To review interfaces and exception usage. Directions Your task is to write a class called Car. Your class should have the following fields and methods: private int position private boolean headlightsOn public Car() - a constructor which initializes position to 0 and headlightsOn to false public Car(int position) - a constructor which initializes position to the passed in value and headlightsOn to false, and it should throw a NegativeNumberException with a...
Assume that you have a String "name" attribute in a Java class definition. Write a public method to return this "name" attribute. public String getName() { return name; } 1.) Write a statement that throws an IllegalArgumentException with the error message “Argument cannot be negative”. 2.) The method getValueFromFile is public and returns an int. It accepts no arguments. The method is capable of throwing an IOException and a FileNotFoundException. Write the header for this method.
JAVA PROG HW Problem 1 1. In the src −→ edu.neiu.p2 directory, create a package named problem1. 2. Create a Java class named StringParser with the following: ApublicstaticmethodnamedfindIntegerthattakesaStringandtwocharvariables as parameters (in that order) and does not return anything. The method should find and print the integer value that is located in between the two characters. You can assume that the second char parameter will always follow the firstchar parameter. However, you cannot assume that the parameters will be different from...
Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram) Author -name:String -email:String -gender:char +Author(name:String, email:String, gender:char) +getName():String +getEmail):String +setEmail (email:String):void +getGender():char +tostring ):String . Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'): One constructor to initialize the name, email and gender with the given values . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...
public class TutorialSpace { // slots — the number of available slots in a tutorial class private int slots; // activated — true if the tutorial class has been activated private boolean activated; /** * TutorialSpace(n) — a constructor for a tutorial class with n slots. * * @param n */ public TutorialSpace(int n) { this.slots = n; this.activated = false; } /** * activate() — activates the tutorial class. Throws an exception if the * tutorial class has already been activated. * * @throws NotActivatedException */ public void activate() throws NotActivatedException { if (activated) { throw new NotActivatedException("Already Activated"); } else { activated = true; } } /** * reserveSlot()—enrol a student into the tutorial class by decreasing the * number of slots left for enrolling in the class. Throws an exception if slot * is either completely used or the tutorial class is not active. * * @throws EmptyException */ public void reserveSlot() throws EmptyException { if (!activated || slots == 0) { throw new EmptyException("Tutorial space is empty"); } else { slots--; } } /** * slotsRemaining()—returns the number of slots remaining in the tutorial class. */ public int slotsRemaining() { return slots; } } public class NotActivatedException extends Exception { /** * */ private static final long serialVersionUID = 1L; public NotActivatedException(String msg) { super(msg); } } public class EmptyException extends Exception { /** * */ private static final long serialVersionUID = 1L; public EmptyException(String msg) { super(msg); } ...
Advanced Object-Oriented Programming using
Java
Assignment 4: Exception Handling and Testing in
Java
Introduction - This assignment is
meant to introduce you to design and implementation of
exceptions in an object-oriented language. It will
also give you experience in testing an
object-oriented support class.
You will be designing and implementing a version of the game
Nim. Specifically, you will design and implement a
NimGame support class that stores all actual
information about the state of the game, and detects and throws...
put everything together in an object-oriented manner! create a class named PositiveNumberStatistics that has the following: A private double 1D array instance variable named numbers. A constructor that takes one parameter, a 1D double array. The constructor should throw an IllegalArgumentException with the message "Array length of zero" if the parameter has a length of 0. If the exception is not thrown, the constructor should create the numbers array and copy every element from the parameter into the numbers instance...