Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class PetStatistics
- {
- public static void main(String[] args)
- {
- Scanner keyboard = new Scanner(System.in);
- String petName = "";
- int petAge = 0;
- double petWeight = 0;
- Pet pet1 = null, pet2 = null, pet3 = null;
- double largest = 0, smallest = 0;
- int youngest = 0, oldest = 0;
- double aveWeight = 0, aveAge = 0;
- System.out.print("Enter name of Pet 1:");
- petName=keyboard.nextLine();
- System.out.print("Enter age of Pet 1:");
- petAge=keyboard.nextInt();
- System.out.print("Enter weight of Pet 1:");
- petWeight=keyboard.nextDouble();
- pet1=new Pet(petName,petAge,petWeight);
- keyboard.nextLine();
- System.out.print("Enter name of Pet#2:");
- petName=keyboard.nextLine();
- System.out.print("Enter age of Pet#2:");
- petAge=keyboard.nextInt();
- System.out.print("Enter weight of Pet#2:");
- petWeight=keyboard.nextDouble();
- pet2=new Pet(petName,petAge,petWeight);
- keyboard.nextLine();
- System.out.print("Enter name of Pet#3:");
- petName=keyboard.nextLine();
- System.out.print("Enter age of Pet#3:");
- petAge=keyboard.nextInt();
- System.out.print("Enter weight of Pet#3:");
- petWeight=keyboard.nextDouble();
- pet3=new Pet(petName,petAge,petWeight);
- System.out.println("====================================");
- System.out.println();
- largest=pet1.getWeight();
- if(largest<pet2.getWeight())
- {
- largest=pet2.getWeight();
- }
- if(largest<pet3.getWeight())
- {
- largest=pet3.getWeight();
- }
- System.out.println("The largest pet(s) (" + largest + " pounds):");
- if(largest==pet1.getWeight())
- {
- System.out.println(pet1.getName());
- }
- if(largest==pet2.getWeight())
- {
- System.out.println(pet2.getName());
- }
- if(largest==pet3.getWeight())
- {
- System.out.println(pet3.getName());
- }
- System.out.println();
- smallest=pet1.getWeight();
- if(smallest>pet2.getWeight())
- {
- smallest=pet2.getWeight();
- }
- if(smallest>pet3.getWeight())
- {
- smallest=pet3.getWeight();
- }
- System.out.println("The smallest pets (" + smallest + " pounds):");
- if(smallest==pet1.getWeight())
- {
- System.out.println(pet1.getName());
- }
- if(smallest==pet2.getWeight())
- {
- System.out.println(pet2.getName());
- }
- if(smallest==pet3.getWeight())
- {
- System.out.println(pet3.getName());
- }
- System.out.println();
- oldest=pet1.getAge();
- if(oldest<pet2.getAge())
- {
- oldest=pet2.getAge();
- }
- if(oldest<pet3.getAge())
- {
- oldest=pet3.getAge();
- }
- System.out.println("The oldest pet(s) (" + oldest + " years):");
- if(oldest==pet1.getAge())
- {
- System.out.println(pet1.getName());
- }
- if(oldest==pet2.getAge())
- {
- System.out.println(pet2.getName());
- }
- if(oldest==pet3.getAge())
- {
- System.out.println(pet3.getName());
- }
- System.out.println();
- youngest=pet1.getAge();
- if(youngest>pet2.getAge())
- {
- youngest=pet2.getAge();
- }
- if(youngest>pet3.getAge())
- {
- youngest=pet3.getAge();
- }
- System.out.println("The youngest pet(s) (" + youngest + " years):");
- if(youngest==pet1.getAge())
- {
- System.out.println(pet1.getName());
- }
- if(youngest==pet2.getAge())
- {
- System.out.println(pet2.getName());
- }
- if(youngest==pet3.getAge())
- {
- System.out.println(pet3.getName());
- }
- System.out.println();
- aveWeight=(pet1.getWeight()+pet2.getWeight()+pet3.getWeight())/3.0;
- System.out.print("Average weight (pounds) = " + aveWeight);
- System.out.println();
- aveAge=(pet1.getAge()+pet2.getAge()+pet3.getAge())/3.0;
- System.out.print("Average age (years) = " + aveAge);
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement