Sponsored Link •
This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.
Hello Sir / Maim ,
i. Write a program to input Employee data into an array ( maximum 100employees, but your program should also work for any number of employees less than 100 ). Your program uses two exception class, one called SSNLengthException if the social security number (SSN) is not exactly nine characters and the other called SSNCharacterException if any character is not character is not a digit ( the SSN is to be entered with just the numbers and no dashes or spaces). When an exception is thrown, the user is told what she/he entered, why it is inappropriate, and asked to reenter the data. Your program will then output the record for all employees with an annotation telling if the Employee's salary is above or below average. You will also need to define the classes Employee, SSNLengthException and SSNCharacterException.
ii. Write a program to copy a file that will allow you to enter the paths for both the file to be copied and the new file from the keyboard.
iii. Write a program that generates exception of type NullPointerEception, NegativeArraySizeException and IndexOutOfBoundsException. Record the catching of each exception by displaying the message stored in the exception object, and the stack trace record.
iv. Imagine a tollboth at a bridge. Cars passing by the booth are expected to pay a 50-cent toll. Mostly they do, but sometimes a car goes by without paying. The tollbooth keeps track of the number of cars that have gone by and of the total amount of money collected. Model this tollboth with a class called tollboth. The two data items are a type-unsigned int to hold the total number of cars, and type double to hold the total amount of money collected. A constructor initializes both of these to 0. A member function called payingCar() increments the car total and add 0.50 to the cash total. Another function, called nopaycar(), increments the car but adds nothing to the cash total. Finally, a member function called display() displays the two totals.
v. Imagine a publishing company that markets both book and audiocassette versions of its works. Create a class publication that stores the title (A string) and price ( type float ) of a publication. From this class derive two classes: Book, which adds a page count ( type int ); and Tape, which adds a playing time in minutes ( type float ). Each of these three classes should have a getdata() function to get its data from the user at the keyboard, and a putdata() function to display its data. Write a main() class to test the book and tape classes by creating instances of them, asking the user to fill in data with getdata(), and then displaying the data with putdata().
vi. Writ a Java program, which shows that the order of exception handlers is important. The first matching handler is the one that executes. Compile and run your program two different ways to show that two different handlers execute with two different effects.
vii. Create three classes: Storage, Counter and Printer. The storage class should store an integer. The Counter class should create a thread that starts counting from 0 to N, and stores each value in the Storage class. The Printer class should create a thread that keeps reading the value in the Storage class and display it. Create a Java program that creats an instance of the Storage class, and sets up a Counter and a Printer object to operate on it.
viii. Create a class Employee that encapsulates data about employees. Then derive new subclass Manager and Programmer from the Employee class; each new class should include additional fields relevant to the specify type of employee represented by the class; each new class should include additional fields relevant to the specific type of employee represented by the class. Assign data into all attributes of classes then display the result.
ix. Define a class my_int that has as its single attribute an integer variable and that contains member functions for determining the following informant for an object of type my_int.
xi. Create a class called SortedDirList with a constructor that takes file path information and builds a sorted directory list from the files at that path. Create two overloaded list() methods that will either produce the whole list or a subset of the list based on an argument. Add size() method that takes a file name and produces the size of that file.
xii. Create a class petroman, in whish a data member a then derive another class called BCS from class petroman, in which a data member b then derive another class from DIT from class BCS, in which a data member c, assign the values to all the data members through constructor. Include a method called show() in all classes, which displays the values of data members. Write the main() class to test all classes, first define the objects of all classes then access the method show(). Note using Polymorphism concepts.
xiii. Create a class with a main() that throws an object of class Exception inside a try block. Give the constructor for Exception a String argument. Catch the exception inside a catch clause and print the String argument. Add a finally clause and print a message to prove you were there.
xiv. Create a class with two methods, f() and g(). In g(), throw an exception of a new type that you define in f(), call g(), catch its exception and, in the catch clause, throw a different exception ( of a second type that you define). Test your code in main().
xv. Create three new types of exceptions. Write a class with a method that throws all three. In main(), call the method but only use a single catch clause all three types of exceptions.
xvi. Inherit a class from Thread and override the run() method. Inside run(), print a message, and then call sleep(). Repeat this three times, then return from run(). Put a start-up message in the constructor and override finalize() to print a shutdown message. Make a separate thread class that calls System.gc() and System.runFinalization() inside run(), printing a message as it does so. Make several thread objects of both types and run them to see what happens.
xvii. Write a basic, empty class called TestClass. Add to TestClass a string data field called data l.This data field should be private to the class. Add to TestClass a constructor that accepts a starting value for data l as its single argument, and public methods for setting and retrieving the value of data l. Call these methods SetData() and GetData(). Compile the finished class. Write a subclass TestSubClass that is derived from TestClass and the adds an integer data field called data2 ( declared as private ) and a public method called CreateDataString() that creats a string object from data l and data 2. That is, data 1 is equal to Java is cool! And data 2 is equal to 15, the CreateDataString() method should return Java cool! 15 as a single object string object. Also create public methods called SetData2() and GetData2() for setting and retrieving the value of data2, as well as a constructor that accepts arguments for the starting values of data 1 and data 2. Write a main() program that it creats an object of the TestSubClass class.
xviii. Write a program that sets up a String variable containing a paragraph of text of your choice. Extract the words from the text and sort them into alphabetical order. Displays the sorted list of words . You could use a simple sorting method called the bubble sort. To sort an array into ascending order the process is as follows: Starting with the first element in the array compare successive elements ( 0 and 1,1 and 2,2 and 3 and so on ). If the first element of any pair is greater that the second, interchange the two elements. Repeat the process for the whole arrays until no interchange is necessary. The array element will now be in ascending order.
xix. Define a class for rectangle objects defined by two points, the top-left and bottom-right corners of the rectangle. Include a constructor to copy a rectangle, passed as an argument and a method to display the defining points of the rectangle. Test the class by creating four rectangles and combining these cumulatively, to end up with a rectangle enclosing them all. Output the defining points of all the rectangles you create.