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: 2795
Discussions: 200,970, Posts: 2,379,701, Members: 246,334
Old February 22nd, 2008, 04:02 PM   Digg it!   #1 (permalink)
Member
 
Ty44ler's Avatar
 
Join Date: Mar 2005
Location: Atlanta, Georgia
Posts: 407
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 online now   Reply With Quote
Old February 24th, 2008, 02:21 PM     #2 (permalink)
Member
 
Join Date: Oct 2003
Posts: 263
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,083
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: 407
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 online now   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? (3033)
Forty-six years ago today (12)
The disrespect of Obama by Russian .. (47)
Laptop with wireless problem. (12)
Wireless Televisions. (12)
CPU fan stops spinning randomly (11)
Regular Build (11)
windows vista security holes (17)
Internet Lost (5)
windows 7 problem (7)
Is the PSU I received dead? (13)
Point and Shoot Camera Suggestions. (6)
radeon x850xt platinum & shader.. (6)
HIS HD5770 graphic card question (15)
Recent Discussions
Nvidia GTX 260 problem (3)
Games, Cables, PCI cards, and more fo.. (6)
Dept. of HS: NSA 'Helped' Develop Vis.. (17)
Delete an OS (9)
Linksys WMP54GS wireless card problem.. (5)
windows vista security holes (17)
Help getting around port 80 for camer.. (5)
Skillsoft Network+ Study Software Que.. (10)
Browsers wont load websites (3)
help me pls laptop just stopped worki.. (0)
Open With ..... Win7 (3)
Laptop with wireless problem. (12)
Internet Lost (5)
virus blocking exe. files (1)
Point and Shoot Camera Suggestions. (6)
CPU fan stops spinning randomly (11)
Modern Warfare 2: Who Bought It? (65)
Is the PSU I received dead? (13)
Print spooler problem (16)
Kingston Bluetooth Dongle Driver (1)
Multiple Restarts Required at Boot (3)
webcam (0)
upgrade for hp a6101 (0)
tv not turn on-makes clicking sound (2)
EVGA 9800 gtx help with finding a goo.. (11)


All times are GMT -4. The time now is 05:36 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