mia_tech
02-12-2009, 07:02 AM
guys I need help with this project of entering name on the arrayList, but I'm not able to get them print to screen... here's the main Class, and the Patients Class
import java.util.Scanner;
import java.util.ArrayList;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String [] args){
int num = 2;
ArrayList<Patients> HospPatients = new ArrayList<Patients>();
Scanner myscan = new Scanner(System.in);
for( int i = 0; i <= num; i++){
System.out.println("please enter you name: ");
String name = myscan.nextLine();
Patients patientOne = new Patients(name);
HospPatients.add(patientOne);
}
for ( int i = 0; i <= num; i++ ){
System.out.println(HospPatients.get(i));
}
}
}
Patients Class
package hospital;
/**
*
* @author jorge.vazquez001
*/
public class Patients {
//attributes
private String name = " ";
private int age = 0;
private String symptoms = " ";
private double balance = 0;
//constructor
public Patients(String tempName){
name = tempName;
}
//getters
public String getName(){
return name;
}
public int getAge(){
return age;
}
public String getSymptoms(){
return symptoms;
}
//balance
public double getBalance(){
return balance;
}
//setters
public void PatientsAge( int tempAge){
age = tempAge;
}
public void setBalance ( double tempbalance ){
balance = tempbalance;
}
public void setSymptoms( String tempsymptoms){
symptoms = tempsymptoms;
}
}
import java.util.Scanner;
import java.util.ArrayList;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String [] args){
int num = 2;
ArrayList<Patients> HospPatients = new ArrayList<Patients>();
Scanner myscan = new Scanner(System.in);
for( int i = 0; i <= num; i++){
System.out.println("please enter you name: ");
String name = myscan.nextLine();
Patients patientOne = new Patients(name);
HospPatients.add(patientOne);
}
for ( int i = 0; i <= num; i++ ){
System.out.println(HospPatients.get(i));
}
}
}
Patients Class
package hospital;
/**
*
* @author jorge.vazquez001
*/
public class Patients {
//attributes
private String name = " ";
private int age = 0;
private String symptoms = " ";
private double balance = 0;
//constructor
public Patients(String tempName){
name = tempName;
}
//getters
public String getName(){
return name;
}
public int getAge(){
return age;
}
public String getSymptoms(){
return symptoms;
}
//balance
public double getBalance(){
return balance;
}
//setters
public void PatientsAge( int tempAge){
age = tempAge;
}
public void setBalance ( double tempbalance ){
balance = tempbalance;
}
public void setSymptoms( String tempsymptoms){
symptoms = tempsymptoms;
}
}