Java code problem

Java code problem

Please check the errors,if any,in this code...i am a java beginner

import java.util.ArrayList;

import java.util.Calendar;

import java.util.Date;

import java.util.HashMap;

import java.util.Map;

import java.util.Scanner;



public class Hospital
 {

    /**
     * @param args
     */

public static void main(String[] args)
 {

        // TODO Auto-generated method stub

Map<Integer,Patient> patients=new HashMap<Integer,Patient>();

PatientFunction pf=new PatientFunction();

Patient p1=new Patient();

Calendar c=Calendar.getInstance();

Date d=new Date();
d.setMonth(d.getMonth()-1);

c.setTime(d);

p1.setAge(25);
p1.setName("Arg");
p1.setLastAppointment(c);

patients.put(p1.getPatientId(), p1);

Scanner s=new Scanner(System.in);


int ctr=0;

do
{

System.out.println("::::::::Hospital::::::::");

System.out.println("Enter 1.Add a patient 2.Update Patient 3.Search patient 4.Display patients or View status");

ctr=s.nextInt();
s.nextLine();

switch(ctr)
{

case 1:

Patient p=pf.addPatient();

if(p==null)

System.out.println("Incorrect input");

else

patients.put(p.getPatientId(), p);

break;

case 2:

System.out.println("Enter a patient ID");

int pid=s.nextInt();
s.nextLine();

if(patients.containsKey(pid))
{

Patient p2=pf.updatePatient(patients.get(pid));

if(p2!=null)

patients.put(p2.getPatientId(), p2);

else

System.out.println("Invalid input");    

}

else

{

System.out.println("Patient with the ID does not exist");
                    }

break;

case 3:

System.out.println("Enter a patient ID");

pid=s.nextInt();
s.nextLine();

if(patients.containsKey(pid))
{

pf.displayPatientDetails(patients.get(pid));

                    }

else

{

System.out.println("Patient with the ID does not exist");
                    }

break;

case 4:

if(patients.size()==0)

System.out.println("No patients in list");

else

{   
ArrayList<Patient> al=new ArrayList<Patient>(patients.values());
                        pf.displayAll(al);              
                    }

break;

}

System.out.println("Continue? Enter y or n");

if(s.nextLine().toLowerCase().equals("y"))

ctr=999;

}
while(ctr==999);

}


}
View Answers

Ads









Related Tutorials/Questions & Answers:
Java code problem
Java code problem  Please check the errors,if any,in this code...i am a java beginner import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.Map
Problem with Java Source Code - Java Beginners
Problem with Java Source Code  Dear Sir I have Following Source Code ,But There is Problem with classes, plz Help Me. package mes.gui; import javax.swing.JOptionPane.*; import java.sql.*; import javax.swing.*; import
Advertisements
Java Compilation error. Hibernate code problem. Struts first example - Hibernate
Java Compilation error. Hibernate code problem. Struts first example  Java Compilation error. Hibernate code problem. Struts first example
Application context problem code
Application context problem code   now i am posting my code here . i..."); // code to set test action environment createAction("/create", "Test", "list"); // code to execute test action String result = proxy.execute(); // code
combo box code problem
combo box code problem  in this my problem related to : when i select state MP then i wil open the its corresponding city but in database it only stores the option value no like MP at option value 10 then it will stores the 10
code related problem
code related problem  this code is compiling but not running please help import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Mybutton11 extends JFrame { JTextField text1 = new JTextField(20
Give me the source code for this problem
Give me the source code for this problem  Ram likes skiing a lot. That's not very surprising, since skiing is really great. The problem with skiing is one have to slide downwards to gain speed. Also when reached the bottom most
JSP code problem - JSP-Servlet
JSP code problem  HI.. I have a DB2 stored procedure wich return a result set. I have made a report basing on this procedure using Crystal Reports. How to pass parameters to this procedure with java code in a JSP page
StringIndexOutOfBoundException problem, What is mean in this code | first.charAt(i)) |
StringIndexOutOfBoundException problem, What is mean in this code | first.charAt(i)) |  import java.io.*; public class Sort{ public static void main(String[]args)throws IOException{ BufferedReader br=new BufferedReader(new
StringIndexOutOfBoundException problem, What is mean in this code | first.charAt(i)) |
StringIndexOutOfBoundException problem, What is mean in this code | first.charAt(i)) |  import java.io.*; public class Sort{ public static void main(String[]args)throws IOException{ BufferedReader br=new BufferedReader(new
StringIndexOutOfBoundException problem, What is mean in this code | first.charAt(i)) |
StringIndexOutOfBoundException problem, What is mean in this code | first.charAt(i)) |  import java.io.*; public class Sort{ public static void main(String[]args)throws IOException{ BufferedReader br=new BufferedReader(new
Applet run with appletviewer but not in browser, any code problem.
Applet run with appletviewer but not in browser, any code problem.  Hi,My problem is when I am running my applet in appletviewer index.html, Its work... can be problem in code also. please check my code. 1) Card.java package
JAVA Problem
JAVA Problem  Write a program that takes two parameters 1. a word... for string length Ignore case handle boundary conditions Optimize the code   The given code accepts a word and array of five words which
java Problem
java Problem  I want to create a binary tree for displaying members in Downline. i am creating a site for MLM(Multi-Level MArketing). tree must be dynamically populated from database. is there any help for me. Thanks in advance
for a problem in coading - Java Beginners
for a problem in coading  what is the problm in following coading...(String[] args) { mywindow (); } }   Hi Friend, There is no problem with the code. Please execute it like as follows : Compile : javac
resolution problem in java
resolution problem in java  I designed project in java in my PC when run the same project in some other PC i can't fully view my java forms.Some said that it is resolution problem
Problem in uploading java application
Problem in uploading java application  I have uploaded my java application (folder created under webapps) using Filezilla FtpClient.Application... this problem
Java implementation problem
/answers/viewqa/Java-Beginners/28578-java-implementation-problem-.html...Java implementation problem  I want to implement following in java code : Main thread 1. create three threads 2. wait for completion of stage 2
java implementation problem
java implementation problem   I want to implement following in java code : Main thread Create three threads wait for completion of stage 2 of all three threads Access all three local variable (LC0, LC1, LC2) of threads bulid
Problem on JAVA Programme
Problem on JAVA Programme  public class AA { int add(int i) { int y = i; y += 20; if (y <= 100){ y +=30;add(y);} System.out.println("Final Value of y : " + y); return y; } public static void main
JAVA CLASSPATH PROBLEM
JAVA CLASSPATH PROBLEM  hi all Friends I am stuck using the java servlets and problem raise for classpath. I had a problem with servlet to call... that it didn't found any java class (which is java class calling from servlet). but i
Java Servlet Problem - JSP-Servlet
method. Please help!!  Hi friend, Please explain problem in details for complete solution and send code the where are you problem. Thanks...Java Servlet Problem  I have a servlet class that implemets
Basic problem for Java experts
Basic problem for Java experts  This assignment will test your knowledge of Arrays Array searching Array sorting Array processing Specification An athletics club require a simple statistical analysis program for analysing lap
this code will be problem it display the error again send jsp for registration form
this code will be problem it display the error again send jsp for registration... RESEND THE CODE org.apache.jasper.JasperException: java.lang.NumberFormatException... in database as text and set the mobile field or telephone field as string in your code
this code will be problem it display the error again send jsp for registration form
this code will be problem it display the error again send jsp for registration... RESEND THE CODE org.apache.jasper.JasperException: java.lang.NumberFormatException... in database as text and set the mobile field or telephone field as string in your code
java servlet connectivity problem with access
java servlet connectivity problem with access  Import java.sql...=con.createStatement(); ^ i am confused what is the problem with this part of code
java problem - Java Beginners
java problem  Write a program that could be used to help children... the main method  Hi Friend, Try the following code: import...(); System.out.print("How many problems would you like? "); double q = scan.nextDouble
Java IF statement problem
Java IF statement problem  Dear Sir/Madam i am using the following code. expected to not have any output but it still showing "welcome".. please...; This code is not even compiling. it is showing compiler errors
this is my code but i cant able to run it wt is the problem
this is my code but i cant able to run it wt is the problem  import java.io.*; class createthread { int thread=4,i; class thread1 extends createthread { public void run() { for(i=0;i
this is my code but i cant able to run it wt is the problem
this is my code but i cant able to run it wt is the problem  import java.io.*; class createthread { int thread=4,i; class thread1 extends createthread { public void run() { for(i=0;i
Java HashSet Collection problem
Java HashSet Collection problem  Here's how the HashSet works.... Here's my code. import java.util.*; public class Prac { @Override public... the concept behind this??   In your code, HashSet stores the values

Ads