Monday, 11 November 2013

Lab 14 - Exception


You  will practice how to report and handle an error condition.
1. Create a custom class named DivideException that extend exception.
2. Create a class MyMath and type in the following code:

public class MyMath
{
public static void main(String[] args)

{
int quotient = divide(10, 5);
System.out.println(quotient);
quotient = divide(10, 0);
System.out.println(quotient);
quotient = divide(10, 1);
System.out.println(quotient);
}
public static int divide(int dividend, int divisor)
{

    return (int) dividend/divisor;
}
}



3.  Make changes to the divide  method to throw the custom DivideException with message of "Cannot divide lor"
4. Catch the specific error accordingly and print the error message.

Lab 14- Recursive

Using recursive style , create a class that receive from a user a string and a number   then  have recursive  methods that :

1.  reverse the string recursively.  eg prog  become gorp
2.  count  the number of character in the screen recursively  eg.  prog = 4
3.  using a number entered , create a fibonacci  recursive  that return the result of that particular position of the number you entered.  eg 0 = 0 , 2 = 1 , 3 =3

Wednesday, 23 October 2013

Hospital Exercise - Link list



Create a Doctor class that have all appropriate details of Doctor Profiles.




Create a Patient  linked-list header class that link a list of PatientNodes.

Each of the PatientNodes object should contains data such as Name , Id and other appropriate variable ( ward no , sickness ) . Add a doctor to the node as the appointed doctor for the patient.


PatientList header class should also be able to do operation of
i )  adding  ( only  to the tail ) ,
ii)  traversing and  printing the node data.
iv) remove a patient from the list
Create a Driver class that add 10 patient to the list and give the option to delete a patient based on his name or id. Print the list before and after the deletion of the patient name.