Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Some of the class here have already answered but I needed the code asap implementing the exception for Factorial and Address Book. Only NetBeans project

Some of the class here have already answered but I needed the code asap implementing the exception for Factorial and Address Book.

Only NetBeans project compressed in .rar or .zip format will be accepted.

Catching Exceptions

Implement Exception handling for the programs you have written in the laboratory exercises as listed below. Note that all data to be used for processing must be input data (data entry from the user). When an invalid data is entered, the program should loop back to data entry until the input becomes valid.

Lab Exercise 004 Factoria

Lab Exercise 007 Address Book

I don't have a code for Factorial but I request for the code implementing exception.

image text in transcribed

Even the instruction says specifically for negative values, I also needed the code for any invalid input like letters etc.

image text in transcribed

Here is my code for Address Book without implementing exception:

package lab7_nunez_maryaileen;

import java.util.Scanner;

class AddressBook { //attributes private String Name;//Name of the person in the address book private String Address;//Address of the person private String Mobile_Number;//Mobile number of the person private String Email_Address;//Email address of the person //constructors AddressBook() { } AddressBook(String n,String a,String m,String e) { Name = n; Address = a; Mobile_Number = m; Email_Address = e; } //Accessors String get_Name() { return Name; } String get_Address() { return Address; } String get_Mobile_Number() { return Mobile_Number; } String get_Email_Address() { return Email_Address; } //mutators void set_Name(String n) { Name=n; } void set_Address(String a) { Address=a; } void set_Mobile_Number(String m) { Mobile_Number=m; } void set_Email_Address(String e) { Email_Address=e; } }

package lab7_nunez_maryaileen;

import java.util.Scanner; public class AddressBookTest { public static void main(String argv[]) { AddressBook book[] = new AddressBook[100];//Instantiating an array of AddressBook objects of 100 entries for(int i=0;i

System.out.print("Enter Mobile number of the person:"); s =sc.next(); book[n].set_Mobile_Number(s); System.out.print("Enter Email address of the person:"); s =sc.next(); book[n].set_Email_Address(s); size++; n++;

} else if(c==2 && size !=0)//checking entry added or not { int m; s=""; System.out.print("Enter index to delete :"); m = sc.nextInt(); book[n].set_Name(s); book[n].set_Address(s); book[n].set_Mobile_Number(s); book[n].set_Email_Address(s); size--; } else if(c==3&& size !=0) { int i; System.out.println(" Entries in book:"); for(i=0;i

System.out.print("Enter Name of the person in the address book :"); s =sc.next(); book[m].set_Name(s); System.out.print("Enter Address of the person:"); s =sc.next(); book[m].set_Address(s);

System.out.print("Enter Mobile number of the person:"); s =sc.next(); book[m].set_Mobile_Number(s); System.out.print("Enter Email address of the person:"); s =sc.next(); book[m].set_Email_Address(s); } else if(c==5) { System.out.println(" Thank you......."); break; } else { System.out.println(" Enter Correct Choice "); } } } }

Thank you so much to someone who will answer the question :)

2. Factorial Create a program that computes for the factorial of a number. Factorial is the product of an integer and all the integers below it; e.g., factorial four 4! is equal to 24 (4*3*2"1-24). The factorial of 0 and 1 is 1. Negative values are invalid input. The program should display an error message and should loop back to data entry when an invalid input is encountered. Sample Output: run Enter nunber: 4 The tactorial of 4 is 24 tun Enter number: 5 The factorial of 5 is 120<>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions

Question

Evaluate three pros and three cons of e-prescribing

Answered: 1 week ago

Question

2. Do you find change a. invigorating? b. stressful? _______

Answered: 1 week ago