Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Cannot find symbol - Calling method passing array Pets

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    My Mood
    Amazed
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Cannot find symbol - Calling method passing array Pets

    Having issues with calling the sort method in order to be able to sort the array. It is unable to find the symbol sortName(petArray), any ideas?

    import java.text.*;
    import java.util.Scanner;
     
    public class SortPet
      {
      public static void main(String[] args){
     
      Scanner in = new Scanner(System.in);
     
     
     
      Pet p1 = new Pet("Daisy",7,12.6);
      Pet p2 = new Pet("Heidi",4,10.5);
      Pet p3 = new Pet("Indy",5,5.7);
      Pet p4 = new Pet("Kitty",2,3.5);
      Pet p5 = new Pet("Lucy",5,5.2);
      Pet p6 = new Pet("Maggie",3,2.6);
      Pet p7 = new Pet("Mimi",6,7.8);
      Pet p8 = new Pet("Sassy",1,2.5);
      Pet[] petArray = {p1, p2,p3, p4,p5,p6,p7,p8};
     
      sortName(petArray);
     
    //for(int i =0; i<=7;i++){
    //	petArray[i].displayPet();}
     
    System.out.println("What do  you want to sort?");
    System.out.println("1 for Name");
    System.out.println("2 for Age");
    System.out.println("3 for Weight");
    System.out.println("4 for Quitting");
    System.out.println();
    int number = in.nextInt();
     
    while(number != 4){
    switch(number){
    	case 1:
    	System.out.println("Sorting by name in ascending order:");
    	System.out.println("\tName"+"\t\tAge"+"\t\tWeight");
    		for(int i =0; i<=7;i++){
    		petArray[i].displayPet();}
    	break;
    	case 2:
    	System.out.println("Sorting by Age in ascending order:");
    	System.out.println("\tName"+"\t\tAge"+"\t\tWeight");
    		for(int i =0; i<=7;i++){
    		petArray[i].displayPet();}
    	break;
    	case 3:
    	System.out.println("Sorting by weight in ascending order:");
    	System.out.println("\tName"+"\t\tAge"+"\t\tWeight");
    		for(int i =0; i<=7;i++){
    		petArray[i].displayPet();}
    	break;
    	case 4:
    	}
    System.out.println("What do  you want to sort?");
    System.out.println("1 for Name");
    System.out.println("2 for Age");
    System.out.println("3 for Weight");
    System.out.println("4 for Quitting");
    System.out.println();
    number = in.nextInt();
     
    }
     
    	}//end main
    }//end sortPet
     
    class Pet{
    	private String Name;
    	private int Age;
    	private double Weight;
     
    	public Pet(){}//constructor
     
    	public Pet(String newName, int newAge, double newWeight){
    		Name = newName;
    		Age = newAge;
    		Weight = newWeight;}  //end Pet
     
    	public void setPet(String newName, int newAge, double newWeight){
    		this.Name= newName;
    		this.Age = newAge;
    		this.Weight = newWeight;}
     
    	public void setName(String newName){
    		this.Name= newName;}
     
    	public void setAge(int newAge){
    		this.Age = newAge;}
     
    	public void setWeight(double newWeight){
    		this.Weight = newWeight;}
     
    	public String getName(){
    		return Name;}
     
    	public int getAge(){
    		return Age;}
     
    	public double newWeight(){
    		return Weight;}
     
    	public static void sortName(Pet[] petArr){
    		petArr[0]=petArr[1];
    	}
     
    	public void displayPet (){
    		System.out.println("Name: "+  this.Name + " Age: " + this.Age + " Weight " + this.Weight);
    	}
     
    }


  2. #2
    Member
    Join Date
    Dec 2011
    Posts
    48
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Cannot find symbol - Calling method passing array Pets

    You haven't told it which class or object to look in, so it assumes you mean the current class.

  3. The Following User Says Thank You to 2by4 For This Useful Post:

    Rilstin81 (December 11th, 2011)

Similar Threads

  1. Calling a print method from another class (printing array)
    By Kaldanis in forum Object Oriented Programming
    Replies: 7
    Last Post: November 25th, 2011, 01:32 PM
  2. Using Queue, cannot find symbol method enqueue
    By firebluetom in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 17th, 2011, 02:41 PM
  3. passing a string and int array into a static method
    By u-will-neva-no in forum Java Theory & Questions
    Replies: 2
    Last Post: May 8th, 2011, 06:35 PM
  4. Cannot find symbol?
    By stealthmonkey in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 10th, 2010, 10:02 PM
  5. cannot find symbol - method
    By kyuss in forum Object Oriented Programming
    Replies: 2
    Last Post: December 7th, 2009, 01:01 PM

Tags for this Thread