Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    also need help with this program

    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
    Code:
    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:
    Code:
    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();
    }
    }

  • #2
    Gox
    Gox is offline
    Regular Coder Gox's Avatar
    Join Date
    May 2006
    Location
    Ontario, Canada
    Posts
    392
    Thanks
    2
    Thanked 20 Times in 20 Posts
    What do you mean by "not compiling perfect"? If it's not compiling please provide the compilation error.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •