The Artima Developer Community
Sponsored Link

Design Forum
ssnlength exception

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
tanya

Posts: 1
Nickname: tpeanutlz
Registered: May, 2004

ssnlength exception Posted: May 17, 2004 7:49 AM
Reply to this message Reply
Advertisement
I need help. I really can not figure out how to write this program. any help will be much appreciated. I need to get this done so I can graduate next week. Thank you!!!!!!!!!

Here is the program:

Write a program to enter Employee data, including social security number and salary, into an arry. (the maximum number of employees is 100, but your program should also work for any number of employees less than 100). your program should use two exception classes, one called ssnlengthexception for when the cocial security number enter is not exactly nine characters and the other called ssncharacterexception for when any character in the social security number is not a digit. when an exception is thrown, the user is reminded of what she or he enter, told why itis inappropriate and asked to reenter the data. after all has been entered your program will out put the records for all employees with an annotation stating whether the employee's salary is above or below average.

Here is the code I have so far:
public class Employee extends Person

private double salary;

public Employee( double salary, String name, String socialSecurity, String address, String phone)
{
super( String name, String socialSecurity, String address, String phone ) ;
}

public void setSalary (double salary)
{
salary = newSalary
}

public getsalary ()
{
return salary;
}

public String toString ()
{
return super.toString() +
"salary : " + Double.toString ( salary )
}

public static void main (String [] args)
{
try
{
system.out.println ("enter social security number:");
socialsecurityNumber = SavitchIn.readLine();
if (socialsecurityNumber!= )
throw new SSNLengthException ("socialsecurityNumber")
}
catch (SSNLengthException e)
{
system.out.println("you need 9 numbers"
+ e.getMessage ());
}
}

public class SSNLengthException extends Exception
{
public SSNLengthException ()
{
super ("Not enough characters!");
}
public SSNLengthException (String message))
{
super (message):
}
}

public class Person
{
private String name;
private String socialSecurity;
private String address;
private String phone;

public Person ()
{
name = "no name yet.";
}

public Person (string initialName)
{
name = initialName;
}

public void setName (string newName)
{
name = newName;
}

public Sting getName ()
{
return name;
}

public void setSocialSecurity (String newSocialSecurity)
{
socialSecurity = initialSocialSecurity;
}

public String socialSecurity ()
{
return socialSecurity;
}

public void setaddress (String newAddress)
{
address = newaddress;
}

public String getaddress ()
{
return address;
}

public void setphone (String phone)
{
phone = newphone
}

public getphone ()
{
return phone;
}

public String toString ()
{
return "name : " + name + "\n" +
"socialSecurity: " + socialSecurity + "\n" +
"address : " + address + "\n" +
"phone : " + phone + "\n" ;
}

public boolean sameName (Person other Person)
{
return (this.name.equalsIgnoreCase(otherPerson.name));
}
}

Topic: Best website design company style Previous Topic   Next Topic Topic: Information system

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use