Question: Problem #1 (8 marks) Create your own two exception classes as follows: NotNumberException NotPositiveIntegerException. Create a Java application that prompts the user to enter an

Problem #1 (8 marks) Create your own two exception classes as follows: NotNumberException NotPositiveIntegerException. Create a Java application that prompts the user to enter an integer in a try block. If the user enters a non-integer, it should throw a NotNumberException. If the user enters 0 or a negative integer, it should throw a NotPositiveIntegerException. The two subsequent catch blocks should catch the exceptions and generate appropriate messages. At the end of the try-catch blocks, include a finally block that prints a message, You need to enter a positive integer. Then the application should repeat the whole process until the user enters a positive integer. When the user enters a positive integer, print an appropriate message and terminate the application.

please give me the solution of problem 1 & 2 in java seperately.

Problem #2 (12 marks) a) Create a class called Gadget that implements the interface Serializable with the following instance data and methods: Instance data: String name: a name of a gadget double price: a price of a gadget Methods: Constructor Getter/setter methods for all instance data toString method: prints information of the instance data b) A text file named textInput.txt is given, which has the following format (comma-separated value): (name of gadget), (price of gadget) (i.e., Oculus Rift, 529.00) c) This file can be downloaded from the Moodle. The file has only four lines. d) Your Java program should read each line of the file using BufferedReader, create a Gadget object with the given information, put it in an array (the array size is 6). e) Serialize the Gadget objects and write them to a file called objectOutput.dat. f) Create two more Gadget objects in your program, which you would like to receive as Christmas gifts. g) Serialize those two Gadget objects and write them to the same file objectOutput.dat. Make sure that your program append the objects in the file, not overwrite the existing objects. h) Read the objects from the file objectOutput.dat, deserialize them, and put them into another array which is different from the previous array. i) Print the information of each Gadget object in the following format: The price of (name of gadget) is $(price of gadget). (i.e., The price of Oculus Rift is $529.00.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!