Sunday, 20 August 2017

client.java examples of java

package ACP.Patient;

import javax.swing.JOptionPane;
import java.io.*;
//////////////////////////////////////////////////////
class Client
{
    public static void main(String[] fileName)
    {
        final int ARRAY_SIZE    = 50;
        Patient []patient    = new Patient[ARRAY_SIZE];
        int numPatients        = 0;
        String[] choices    = {"", "Add New Patient Record", "Update Patient Information", "Update Prescription & Disease History", "Delete Patient Record", "Search & View Patient Record By Patient ID", "Search & View Patient Record By Patient Name", "Search & View Patient Record By Patient Age", "Search & View Patient Record By Disease category", "Search & View Patient Record By Doctor Name", "Exit"};
        String[] Continue    = {"", "Yes", "No"};
        ObjectOutputStream oOS    = null;
        ObjectInputStream  oIS    = null;
    //////////////////////////////////////////////////////
        String choice        = null;
        String cont        = null;
        int i            = 0;                   
    /////////////////////////////////////////////////////
        if(fileName.length == 0)
        {
            JOptionPane.showMessageDialog(null, "File Name Not Sent From Command Line\nExecute Again With File Name", "Error", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        }
    ////////////////////////////////////////////////////
        try
        {
            Patient temp = null;
            oIS         = new ObjectInputStream(new FileInputStream(fileName[0]));
            for(i = 0; i < ARRAY_SIZE; i++)
            {
                temp = (Patient) oIS.readObject();
                if(temp != null)
                {
                    patient[i] = temp;
                    numPatients++;
                }
            }
            oIS.close();
        }
        catch(ClassNotFoundException cNFE)
        {
            JOptionPane.showMessageDialog(null, "Error\n" + cNFE, "Class Not Found Exception in Reading Objects", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        }
        catch(FileNotFoundException fNFE){}
        catch(EOFException eOFE){}
        catch(IOException iOE)
        {
            JOptionPane.showMessageDialog(null, "Error\n" + iOE, "I/O Exception in Reading Objects", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, "Error\n" + e, "Exception in Reading Objects", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        }

        Patient.readNextID();
    ///////////////////////////////////////////////////
        do
        {
            choice = (String) JOptionPane.showInputDialog(null, "What You Want To Do ?", "Main Menu", JOptionPane.QUESTION_MESSAGE, null, choices, choices[0]);
            while(choice.equals(choices[0]))
                choice = (String) JOptionPane.showInputDialog(null, "Field Cannot Be Empty\nWhat You Want To Do ?", "Main Menu", JOptionPane.ERROR_MESSAGE, null, choices, choices[0]);
       
            if(choice.equals(choices[1]))
            {
                if(numPatients < 0 || numPatients >= ARRAY_SIZE)
                    JOptionPane.showMessageDialog(null, "No Space for New patients :(", "Database Full", JOptionPane.WARNING_MESSAGE);
                else
                {
                    patient[numPatients] = new Patient();
                    numPatients++;
                }               
            }
            else if(choice.equals(choices[2]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    patient[0].updatePatientInfo(patient, numPatients);
            }   
            else if(choice.equals(choices[3]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    patient[0].updatePrescriptionDiseaseHistory(patient, numPatients);
            }
            else if(choice.equals(choices[4]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    numPatients = patient[0].deletePatientInfo(patient, numPatients);
            }
            else if(choice.equals(choices[5]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    patient[0].searchView_patientID(patient, numPatients);
            }
            else if(choice.equals(choices[6]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    patient[0].searchView_patientName(patient, numPatients);
            }
            else if(choice.equals(choices[7]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    patient[0].searchView_patientAge(patient, numPatients);
            }
            else if(choice.equals(choices[8]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    patient[0].searchView_diseaseCategory(patient, numPatients);
            }
            else if(choice.equals(choices[9]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    patient[0].searchView_doctorName(patient, numPatients);
            }
            else if(choice.equals(choices[10]))
            {
                JOptionPane.showMessageDialog(null, "Good Bye", "Exiting", JOptionPane.PLAIN_MESSAGE);
                               
                if(numPatients > 0)
                {
                    try                       
                    {
                        oOS = new ObjectOutputStream(new FileOutputStream(fileName[0]));
                        for(i = 0; i < ARRAY_SIZE; i++)
                            oOS.writeObject(patient[i]);
                        oOS.close();
                    }
                    catch(IOException iOE)
                    {
                        JOptionPane.showMessageDialog(null, "Error\n" + iOE, "I/O Exception in Writing Objects", JOptionPane.ERROR_MESSAGE);
                    }
                    catch(Exception e)
                    {
                        JOptionPane.showMessageDialog(null, "Error\n" + e, "Exception in Writing Objects", JOptionPane.ERROR_MESSAGE);
                    }

                    Patient.writeNextID();
                }
                System.exit(0);
            }
            cont = (String) JOptionPane.showInputDialog(null, "Want to go back to Main Menu ?", "Continue or Exit", JOptionPane.QUESTION_MESSAGE, null, Continue, Continue[0]);
            while(cont.equals(Continue[0]))
                cont = (String) JOptionPane.showInputDialog(null, "Field Cannot Be Empty\nWant to go back to Main Menu ?", "Continue or Exit", JOptionPane.ERROR_MESSAGE, null, Continue, Continue[0]);
        }
        while(cont.equals(Continue[1]));
    ///////////////////////////////////////////////////
        JOptionPane.showMessageDialog(null, "Good Bye", "Exiting", JOptionPane.PLAIN_MESSAGE);
       
        if(numPatients > 0)
        {
            try                       
            {
                oOS = new ObjectOutputStream(new FileOutputStream(fileName[0]));
                for(i = 0; i < ARRAY_SIZE; i++)
                    oOS.writeObject(patient[i]);
                oOS.close();
            }
            catch(IOException iOE)
            {
                JOptionPane.showMessageDialog(null, "Error\n" + iOE, "I/O Exception in Writing Objects", JOptionPane.ERROR_MESSAGE);
            }
            catch(Exception e)
            {
                JOptionPane.showMessageDialog(null, "Error\n" + e, "Exception in Writing Objects", JOptionPane.ERROR_MESSAGE);
            }
        }

        Patient.writeNextID();
    ///////////////////////////////////////////////////
    }
}

Friday, 11 August 2017

A point on the two-dimensional plane can be represented by two numbers: an x coordinate and a y coordinate. For example, (4,5) represents a point 4 units to the right of the vertical axis, and 5 units up from the horizontal axis. The sum of two points can be defined as a new point whose x coordinate is the sum of the x coordinates of the two points, and whose y coordinate is the sum of the y coordinates. Write a program that uses a structure called point to model a point. Define three points, and have the user input values to two of them. Then set the third point equal to the sum of the other two, and display the value of the new point. Interaction with the program might look like this: Enter coordinates for p1: 3 4 Enter coordinates for p2: 5 7 Coordinates of p1+p2 are: 8, 11

A point on the two-dimensional plane can be represented by two numbers: an x coordinate and a y coordinate. For example, (4,5) represents a point 4 units to the right of the vertical axis, and 5 units up from the horizontal axis. The sum of two points can be  defined as a new point whose x coordinate is the sum of the x coordinates of the two points, and whose y coordinate is the sum of the y coordinates.  Write a program that uses a structure called point to model a point. Define three points, and have the user input values to two of them. Then set the third point equal to the sum of the other two, and display the value of the new point. Interaction with the program  might look like this:  Enter coordinates for p1: 3 4  Enter coordinates for p2: 5 7  Coordinates of p1+p2 are: 8, 11


A point on the two-dimensional plane can be represented by two numbers: an x coordinate and a y coordinate. For example, (4,5) represents a point 4 units to the right of the vertical axis, and 5 units up from the horizontal axis. The sum of two points can be
defined as a new point whose x coordinate is the sum of the x coordinates of the two points, and whose y coordinate is the sum of the y coordinates.
Write a program that uses a structure called point to model a point. Define three points, and have the user input values to two of them. Then set the third point equal to the sum of the other two, and display the value of the new point. Interaction with the program
might look like this:
Enter coordinates for p1: 3 4
Enter coordinates for p2: 5 7
Coordinates of p1+p2 are: 8, 11
SOLUTION:
#include<iostream.h>
#include<conio.h>
////////////////////////////////////////////////////////////// Define Structure /////////////////////////////////////////////////////////////
struct point
            {
int x_coordinate,y_coordinate;
};
///////////////////////////////////////////////////// Define Structure Variables /////////////////////////////////////////////////////
point p1,p2,p3;
void main()
{
clrscr();
///////////////////////////////////////////////////////////////// Take Input ////////////////////////////////////////////////////////////////////
cout<<"Enter coordinates of first point ";
                        cin>>p1.x_coordinate>>p1.y_coordinate;
cout<<"Enter coordinates of second point ";
                        cin>>p2.x_coordinate>>p2.y_coordinate;
////////////////////////////////////////////////////////////// Calculate Point 3 ////////////////////////////////////////////////////////////
p3.x_coordinate=p1.x_coordinate+p2.x_coordinate;
p3.y_coordinate=p1.y_coordinate+p2.y_coordinate;
////////////////////////////////////////////////////////////////////// Output /////////////////////////////////////////////////////////////////////
cout<<"\nCoordinates of P1+P2 are: "<<p3.x_coordinate<<" "<<p3.y_coordinate;
getch();
}
OUTPUT:

Monday, 7 August 2017

code for salary

#include"stdio.h"
#include"conio.h"

int sal,h_rent,d_allow,g_pay;
void main()
{
    printf("Enter salary\n");
    scanf("%d",&sal);
    if(sal<1500)
    {
        h_rent=(0.1*sal);
        d_allow=(0.9*sal);
        g_pay=h_rent+d_allow;
        printf("Gross Salary :%d",g_pay);
    }
    else if(sal>=1500)
    {
        h_rent=(0.2*sal);
        d_allow=(0.95*sal);
        g_pay=h_rent+d_allow;
        printf("Gross Salary :%d",g_pay);
    }
    else
        printf("Invalid Input");
    getch();