home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Array Error

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2604
Discussions: 203,417, Posts: 2,407,399, Members: 248,942
Old February 22nd, 2008, 04:02 PM   Digg it!   #1 (permalink)
Member
 
Ty44ler's Avatar
 
Join Date: Mar 2005
Location: Atlanta, Georgia
Posts: 417
Send a message via AIM to Ty44ler
Question
Array Error

Well, I've come to be stumped and come to all you java guru's of TechIMO to help me out! :thumbsup: haha Here goes:

The basic idea of my program:
Creating a program to bill two kinds of patients (Hospital and Clinic) differently and show the bill of all the patients in a JOptionpane using classes so it can be easily edited to add for more patients.

The problem:
I'm receiving errors at HospitalPatient and ClientPatient inside the array. It says "cannot instantiate the type ClinicPatient" and vice versa for the HospitalPatient.

My program Structure:
I've got a HospitalPatient class and ClientPatient class that extends from a Patient class which extends from a Person class.

I'm not sure as to why this is coming up as an error. If you need to see the other class code I'll gladly put them up, but didnt want to make the post too long if it wasn't necessary....


Code:
import javax.swing.JOptionPane;
import java.text.DecimalFormat;

public abstract class TesterClass extends Person{
   public static void main( String[] args )
   {
      String output = "";

      // create a formatting object
      DecimalFormat precision2 = new DecimalFormat( "$0.00" );

      // Patient Array
      Patient[] patientArray=new Patient[4];
        patientArray[0]= new ClinicPatient("Dr Sushel", "March 4, 2002", "first name","lastName", "address", "city", "state", "zip", "ssn" );
      	patientArray[1]= new HospitalPatient("dr weiner", "2209", 3, 180,  "first name","lastName", "address", "city", "state", "zip", "ssn" );
      	patientArray[2]= new ClinicPatient("Dr Sushel", "March 4, 2002", "first name","lastName", "address", "city", "state", "zip", "ssn" );
      	patientArray[3]= new HospitalPatient("dr weiner", "2209", 3, 180, "first name","lastName", "address", "city", "state", "zip", "ssn" );
    
      	output="";
      	for (int i=0; i<patientArray.length; i++;{
    	output+=patientArray[i].toString();
    	output += "\n\n*****\n\n";
    }

      JOptionPane.showMessageDialog( null, output,"Billing Report", JOptionPane.INFORMATION_MESSAGE );

      System.exit( 0 );
   }
}

Here's my HospitalPatient code:
Code:
public abstract class HospitalPatient extends Patient {
	   private String roomNumber;
	   private int daysOfStay;
	   private static double roomRate;

	   
	   // Constructor
	   public  HospitalPatient( String doctor, String room, int days, double rate, String firstName, String lastName, String address, String city, String state, String zip, String ssn ){
	   
		   super(doctor, firstName, lastName,  address,  city,  state,  zip,  ssn); 
		   roomNumber=room;
		   daysOfStay=days;
		   roomRate=rate;
	   }
	      
	   //No argument Constructor
	   public HospitalPatient(){
	}

	   // Set the roomNumber
	   public void setroomNumber( String room ) {
		   roomNumber = room;
		 }
	   
	   // Set the days of stay
	   public void daysOfStay( int days ) {
			 daysOfStay = ( days >= 1 ? days : 0 );
		 }
	   
	   // Set the room rate
	   public static void roomRate( double rate ) {
		   roomRate = ( rate >= 200 && rate <  500 ? rate : 200 );
		 }
	   
	   // Return the room number
	   public String getroomNumber() {
			 return roomNumber;
		 }
	  
	   // Return the days of stay
	   public int daysOfStay() {
			 return daysOfStay;
		 }

	   // Return the room rate
	   public static double roomRate() {
			 return roomRate;
		 }

	   //Determine the Bill of Hospital Patient
	   public double computeBill() {
			 return daysOfStay*(roomRate+125);
	   }
	   
		public String toString() {
		return super.toString() + daysOfStay + "-day hospital stay attended by : " + computeBill();
			 }
}
and ClinicPatient code

Code:
public abstract class ClinicPatient extends Patient {
	   private String appointmentDate;
   
	   // Constructor
	   public  ClinicPatient( String doctor, String appointment, String firstName, String lastName, String address, String city, String state, String zip, String ssn ){
	   
		   super(doctor, firstName, lastName,  address,  city,  state,  zip,  ssn); 
		   appointmentDate=appointment;
	   }
	   //No argument Constructor
	   public ClinicPatient(){
	}

	   // Set the appointment Date
	   public void setappointmentDate( String a ) {
		   appointmentDate = a;
		 }

	   // Return the appointment Date
	   public String getappointmentDate() {
			 return appointmentDate;
		 }
	   	
	   //Determine the Bill of Clinic Patient
	   public double computeBill() {
			 return (125);
	   }
	   
	   public String toString() {
	return super.toString() + "Clinic visit with: on " + appointmentDate + computeBill();
}
}
__________________
Frank: Blue do you trust that I do not want to see you die here tonight?
Blue: Yes sir.
Frank: Blue you're my boy!

Last edited by Ty44ler : February 22nd, 2008 at 07:33 PM.
Ty44ler is offline   Reply With Quote
Old February 24th, 2008, 02:21 PM     #2 (permalink)
Member
 
Join Date: Oct 2003
Posts: 267
maybe...

hey,

not a java programmer. I only code now in .net (vb, c#)

if you declare each ClinicPatient or HospitalPatient into its own variable as clinic patient does it create the instance? I am assuming the extends is inheritance. If thats the case maybe your array of Patient is causing the error since the array is strongly typed. Not sure if java works differently with inheritance / strongly typed arrays with inheritance.

see if the following code works:

test ClinicPatient=new ClinicPatient.......

if that works you might want to declare your array with objects not patients.
amtrac24 is offline   Reply With Quote
Old February 25th, 2008, 09:23 AM     #3 (permalink)
Super F@D Folder
 
Join Date: Jun 2004
Posts: 5,086
Send a message via AIM to sr71000
That should work. Why does testerclass extend person though?

also..what version of java are you using?
sr71000 is offline   Reply With Quote
Old February 25th, 2008, 03:21 PM     #4 (permalink)
Member
 
Ty44ler's Avatar
 
Join Date: Mar 2005
Location: Atlanta, Georgia
Posts: 417
Send a message via AIM to Ty44ler
Im running JAVA SE 6....

I figured it out, it was because clinicPatient and hospitalPatient were both abstract classes and couldnt read it. I took that out and voila no error. Thanks for the help though!
Ty44ler is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
"detecting array" error, single raid drive Carbon14 Technical Support 1 October 26th, 2007 10:52 AM
Cloning to an array Blitzkreig75 Storage Related 3 September 14th, 2006 05:28 PM
detecting array zero tolerance Technical Support 1 April 24th, 2005 12:43 AM
Help for my new raid array Uncle Bob Storage Related 4 July 24th, 2003 02:26 PM


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (3724)
nVIDIA GTX 260 vs ATI 5770 (6)
and she wanted to be VP? (49)
GPU upgrade from 8600 GT (14)
New PC Heavy Gaming Rig (8)
[F@H Chat]2/6/10 New thread for ya'.. (24)
Need for Speed Shift (7)
Best route for upgrade (several opt.. (5)
Motherboards with 2 PCIE x16 slots (8)
Graphene transistors promise 100GHz.. (7)
I want to buid a pc with this case (14)
Animated GIFs don't animate? (13)
Upgrading (5)
Upgrading Video (28)
Recent Discussions
GPU upgrade from 8600 GT (14)
tecumseh snow blower (0)
nVIDIA GTX 260 vs ATI 5770 (6)
PLEASE MUCH NEEDED HELP! (4)
Information on the Foxconn RC4107MA M.. (5)
3 monitors (1)
HD5870 Question (18)
[F@H Chat]2/6/10 New thread for ya' s.. (24)
Microsoft Wireless Keyboard 3000 (13)
Laptop - HDTV Connection Using HDMI C.. (2)
How Good is This $450 MSI Laptop? (3)
Wireless G printer w/wrt160n (0)
SpeedFan Temp Monitor Help (3)
BSOD - IRQL not less or equal - HELP! (0)
Unable to find LAN (7)
Best route for upgrade (several optio.. (5)
should i upgrade whole pc or just vid.. (2)
WEBCAM / XP / XP64 / VISTA (7)
routers and switches OPERATING SYSTEM.. (0)
One dumb nube and a cisco 3550 (1)
New PC Heavy Gaming Rig (8)
120mm fan on top of case??? (12)
Is my hard drive going bad? Please h.. (2)
rsync over passwordless ssh in a cron.. (4)
Wii at buy.com for $374 - Carnival Sm.. (7)


All times are GMT -4. The time now is 04:00 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28