I have tried another exercise, but again I will need help, here's the code

hi,
I have another problem. here's the question pluss the code.
public interface Patient{
public void doVisit(float hour);
public boolean hospitalize();
1. I will need to write a class name OrdinaryPatient which extends Patient.
the class will include value int that his name age and another value that will be boolean
of disease.
I have to do two constructors. one that don't get values and give them default and the other one
that does get values.
another method name docVisit which get a visit to the doctor time visit and will print a message.
the method hospitalize will hospitalize the patient (and if he will have disease he will get true).
and for age I have to write methods of get and set.
2. I will need to write a class of Hipochondriac that extends from OrdinaryPatient.
I have to do two constructors. one that don't get values and make default and the other one that do get values.
I will need to ade int by the name of numberOfHospitalize.
I will need to move the method hospitalize that it will be possible to hospitalize the hypochondriac
on with the value numberOfHospitalize that his small from 5 and if he will hospitalize he will return
the value true.
3. write class PatientClass which will be the method main.
do 10 objects from OrdinaryPatient, 5 that don't get values and 5 will get randomaly age and
chronic disease with true.
do 10 objects from Hipochonidraic, 9 that don't get values and one get all of them.
save all objects in value from Patinet.
print for each of them their age.
print for the OrdinaryPatient alone the method of Hospitalize.
ok, here's what I did.
1. OrdinaryPatient
pbulic class OrdinaryPatient implements Patient{
private int age;
private boolean disease;
public OrdinaryPatient(){
this.disease=false;
this.age=0;
public OrdinaryPatient(int age,boolean ddisase){
this.disease=disease;
this.age=age;
public int getAge(){
return age;
public void setDisease(boolean disease){
this.disease=disease;
public void setAge(int age){
this.age=age;
public void docVisit(){
System.out.println("Patient's visit is one hour");
public boolean hospitalize(){
return false;
2. public class Hipochondriac extends OrdinaryPatient{
private = numberOfHospitalize;
public Hipochondriac();
super();
numberOfHospitalize=0;
public Hipochondriac(int age, boolean diseased, int numberOfHospitalize){
super(age.diseased);
setnumberOfHospitalize(numberofHospitalize);
from here I don't know how to continue.
3. public class PatientClass{
public static void main(String args[]){
patient patinets= new patient[20];
for (int i=0; i<5; i++){
patients= new OrdinaryPatient();
from i'm stuck!!!
if you can help me to improve it I will appriciate it...
Einat

here my result.
1. public interface Patient{
     public void docVisit(float hour_;
     public boolean hospitalize();
public class OrdinaryPatient extends Patient
     private int age;
     private boolean disease;
//constructors
     public OrdinaryPatient(){
          age=20;
          disease=true;
     public OrdinaryPatient(int age, boolean disease) {
          setAge(age);
          this.disease=disease;
//methods
     public int getAge() {
          return age;
     public void setAge(boolean disease) {
          if(age>0 && age<120)
               this.age=age;
     //overriding methods.
     public void docVisit(float hour) {
          System.out.println("your visit turn is at "+hour");
     public boolean hospitalize(){
          System.out.println("go to hospital");
          if(disease)
               return true;
          else
               return false;
2. public class Hipochondriac extends OrdinaryPatient{
     private int numberOfHospitalize;
//constructors
     public Hipochondriac(){
     public Hipochondriac(int age, boolean disease, int numberOfHospipitalize){
          setAge(age);
          this.disease=disease;
          this.numberOfHospitalize=numberOfHospitalize
     //methods
     public int getNumberOfHospitalize(){
          return numberOfHospitalize;
     public void setNumberOfHospitalize(int numberOfHostpitalize){
          if(numberOfHospitalize>0)
               this.numberOfHospitalize=numberOfHospitalize;
     public boolean hospitalize(){
          if(numberOfHospitalize<5)
               System.out.println("go to hospital");
               numberOfHospitalize++;
               return true;
          else
               return false;
3. public class PatientClass
     //constructors
     private PatientClass(String[] args){
          //private methods helps to build the object.
          intialArr(args);
          printAge();
          gotHospital();
//methods.
private void intialArr(String[] args){
     int i;//array index
     for(i=0;i<arr.lents/2;i+=2)
          arr=new OrdinaryPatient();
          arr[i+1]=new OridnaryPatient((int)(Math.random()*121),true);
     for(;i<=arr.length-2;i++)
          arr[i]=new Hipochondriac();
     arr[i]=new Hipochondriac(Interget.parseINt(args[0]),
     private void printAge(){
          for(int i=0;i<arr.length;i++)
               System.out.println(((OrdinaryPatient)arr[i]).getAge());
     private void gotoHospital(){
          for(int i=0;i<arr.length;i++)
//checking for ordinarypatient objects only
               if(!(arr[i] instanceof Hipochondriac))
                    //dont need casting
                    arr[i].hospitalize()[
     //main method
     public static void main(String[] args)
          //setting the commandLine array from the main to PatientClass object
          PatientClass pc=new PatientClass(args);
let me know if it's seems logic to you.
thank you, Einat     

Similar Messages

Maybe you are looking for

  • US iPhone in the UK?

    Hey everyone. First of all sorry if this is in the wrong discussions section. I want to buy the new iPhone and what with the rumours of it coming out in September it will coincide with my holiday. Not only will I be in the US, but I will be in San Fr

  • Problem with BAPI_PO_CHANGE when called within ME_PURCHDOC_POSTED BADI Implementation

    Hi All, We have a situation where PR to PO conversion needs to happen through a custom program which submits ME59N in batches. During this conversion, it's a business requirement to update the PO's GS Partner function based on the manufacturer in the

  • Text in 0fiscper3

    Hi all, Hope you can help me with this question: I have some layouts with 0FISCPER3, but I'm not beeing able to show text related to characteristic. So, in layouts I only get 1, 2,... instead of Jan, Feb, ... Can you help me in solving this problem:

  • Ghost Files on Thumb Drives??

    So whenever I delete a file off my thumb drive while using my mac, for some reason, it shows up as having been deleted, but I don't regain memory space. When I bring my thumb drive to a PC, it shows all these files as still being on the thumb drive.

  • Loss of image quality after rotate canvas

    PS7 on Win XP Windows Explorer and some software bundled with digital cameras [Canon and Panasonic] warn when rotating a picture that there may be loss of image quality. Presumably it must re-compress the jpg image file? In order to avoid that proble