Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exception Handing Programming Lab 4 Student Learning Outcomes. After completion of this lab, students will be able to write a Java program that uses exception

Exception Handing Programming Lab 4

Student Learning Outcomes. After completion of this lab, students will be able to write a Java program that

uses exception handling

uses a user defined exception.

Activity - Implement a program that prompts a user for their name, age, salary and email address and develops a hacker name from the data. The program stores the information (name, age and email) along with the hackers name to a file, and displays their hacker name. Use the same file for every user.

Catches the following exceptions

NumberFormatException for the salary

User defined Malformed email address (See below)

Allows the user to try again.

User Class

Stores user information in instance variables name, age, salary and email address in the appropriate data type.

Default constructors only

Accessor and mutator methods including:

boolean setSalary(String newSalary)

receives a string and converts it to a number

Handles the NumberFormatException.

Returns true if conversion is successful and false if not.

boolean setEmail(String newEmail)

receives a String

Tests for Malformed email address and throws MalformedEmailAddress Exception if it is malformed.

Returns true if address is correctly formed, false if not.

setHackerName method

Use your creativity to create an algorithm that uses the data the create a hacker nickname,

The nickname does not necessary have to be a pronounceable word, but that would be nice.

You may want to store a bank of words to use as part of your hacker name see HYPERLINK "http://forums.windrivers.com/showthread.php?38547-Good-hacker-names" http://forums.windrivers.com/showthread.php?38547-Good-hacker-names for some ideas.

Exception handling

Email Address

Check to see if an email address is valid

Valid address is HYPERLINK "mailto:xxxx@xxxx.xxx" xxxx@xxxx.xxx (where x is any character or number)

If email address is malformed it throws a the User Defined MalformedEmailAddress Exception.(see below)

The MalformedEmailAddress should be caught and the user given a chance to correct the address. (Think about this as its a little trickier than you think)

MalformedEmailAddress Exception class - Creates an error message explaining the exception.

UserTest

Test all methods in the User class including exception.

To simplify the process read all data in from a Scanner as a String.

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

More Books

Students also viewed these Databases questions