...

View Full Version : also need help with this program



cs4l
12-15-2011, 09:11 AM
this one i really thought i did perfect, idk if its because im tired or what but its not compiling perfect haha..if somebody can point out what i did wrong or whatever that would be greatly appreciated



import java.util.*;
public class Animal{
char name; //DECLARE VARIABLES
int byear;
char species;
double bal;
char oname;

public Animal(char n,int by,char s,double b,char o){ //CONSTRUCTOR
name=n;
byear=by;
species=s;
bal=b;
oname=o;
}

public char getPetName(){ //PRINTS PET NAME
return name;
}

public int getBirthYear(){ //PRINTS BIRTH YEAR
return byear;
}

public char getSpecies(){ //PRINTS SPECIES
return species;
}

public double getBalance(){ //PRINTS BALANCE
return bal;
}

public char getOwnersName(){ //PRINTS OWNERS NAME
return oname;
}

public char setName(char name){
}
//java.io.File file = new java.io.File("cps2231Lab5.data");

//Scanner scan = new Scanner(file);
//int x = scan.nextInt();
//Animal [] pets = new Animal[x];

public void inputAnimals(){ //INPUTS DATA INTO ARRAY
// for(int i=0; i<pets.length; i++){
// Animal pet = new Animal(scan.next(),scan.nextInt(),scan.next(),scan.nextDouble(),scan.next());
// pet.Animal(scan.next(),scan.nextInt(),scan.next(),scan.nextDouble(),scan.next());

// pets[i] = pet;
//} //END FOR STATEMENT
} //END METHOD



//public Animal getOutPut(){ //PRINTS THE ARRAY AS IS
// for(int i=0;i<pets.length;i++){
//System.out.print(pets[i].getPetName());
// pets[i].getBirthYear();
// pets[i].getSpecies();

// pets[i].getBalance();
// pets[i].getOwnersName();
// } //ENDS FOR STATEMENT
//} //END METHOD

public static arraySort(){
double temp;
double high = 0.0;
// Animal temparray;
for (int i=0;i<this.length;i++){
temp = this[i].getBalance();
// temparray=this[i];
if(temp>this[i+1].getBalance()){
this[i]=this[i+1].getBalance();
this[i+1]=temp;
}
//if(temparray.getBalance() == high)
//System.out.print(temparray.getOutPut());
} //ENDS FOR STATEMENT
} //ENDS METHOD


public static printAnimals(){
for (int i =0; i<this.length; i++){
this[i].getPetName();
this[i].getBirthYear();
this[i].getSpecies();
this[i].getBalance();
this[i].getOwnersName();
}
}
} //ENDS CLASS


the testing class:



import java.util.*;

public class AnimalTest{
public static void main(String [] args){

java.io.File file = new java.io.File(cps2231Lab5.data);
Scanner scan = new Scanner(file);
int x = nextInt();
Animal[] pets = new Animal[x];


for(int i=0; i<pets.length; i++){
Animal pet = new Animal;
pet.Animal(scan.next(),scan.nextInt(),scan.next(),scan.nextDouble(),scan.next());

pets[i] = pet;
}

pets.arraySort();
pets.printAnimals();
}
}

Gox
12-15-2011, 06:31 PM
What do you mean by "not compiling perfect"? If it's not compiling please provide the compilation error.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum