The Artima Developer Community
Sponsored Link

Java Answers Forum
Review program/give input/help

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
dessa123

Posts: 1
Nickname: dessa123
Registered: Feb, 2003

Review program/give input/help Posted: Feb 8, 2003 11:57 PM
Reply to this message Reply
Advertisement
This is a Java programming question. Here is what I have so far, please give help or input.

Requirements:
Create a program for a class for basic pet records:name, age and weight. Then add the following to the program.
--Create a new class called Dog, derived from petRecord class. With additional attributes (breed)type string and (boosterShot)type boolean, true if the pet has had it's boostershot, false if not.
---write a driver program to test all methods, and write program that reads in five pets of type Dog and print the name and breed of all dogs that are over two years old and have had their booster shots.
////////////////////////


public class PetRecord
{
private String name;
private int age;//in years
private double weight;//in pounds

public void writeOutput()
{
System.out.println("Name: " + name);
System.out.println("Age: " + age + " years");
System.out.println("Weight: " + weight + " pounds");
}

public PetRecord(String initialName, int initialAge,
double initialWeight)
{
name = initialName;
if ((initialAge < 0) || (initialWeight < 0))
{
System.out.println("Error: Negative age or weight.");
System.exit(0);
}
else
{
age = initialAge;
weight = initialWeight;
}
}

public void set(String newName, int newAge, double newWeight)
{
name = newName;
if ((newAge < 0) || (newWeight < 0))
{
System.out.println("Error: Negative age or weight.");
System.exit(0);
}
else
{
age = newAge;
weight = newWeight;
}
}

public PetRecord(String initialName)
{
name = initialName;
age = 0;
weight = 0;
}

public void set(String newName)
{
name = newName; //age and weight are unchanged.
}

public PetRecord(int initialAge)
{
name = "No name yet.";
weight = 0;
if (initialAge < 0)
{
System.out.println("Error: Negative age.");
System.exit(0);
}
else
age = initialAge;
}

public void set(int newAge)
{
if (newAge < 0)
{
System.out.println("Error: Negative age.");
System.exit(0);
}
else
age = newAge;
//name and weight are unchanged.
}

public PetRecord(double initialWeight)
{
name = "No name yet";
age = 0;
if (initialWeight < 0)
{
System.out.println("Error: Negative weight.");
System.exit(0);
}
else
weight = initialWeight;
}

public void set(double newWeight)
{
if (newWeight < 0)
{
System.out.println("Error: Negative weight.");
System.exit(0);
}
else
weight = newWeight; //name and age are unchanged.
}

public PetRecord()
{
name = "No name yet.";
age = 0;
weight = 0;
}

public String getName()
{
return name;
}

public int getAge()
{
return age;
}

public double getWeight();

return Weight;


{
PetRecord usersPet = new PetRecord("Stitch");
System.out.println("My records on your pet are inaccurate.");
System.out.println("Here is what they currently say:");
usersPet.writeOutput();

System.out.println("Please enter correct pet name:");
String correctName = SavitchIn.readLine();
System.out.println("Please enter corect pet age:");
int correctAge = SavitchIn.readLineInt();
System.out.println("Please enter correct pet weight:");
double correctWeight = SavitchIn.readLineDouble();
usersPet.set(correctName, correctAge, correctWeight);
System.out.println("My updated records now say:");
usersPet.writeOutput();

System.out.println("Correct pet name is Stitch:");
System.out.println("Correct pet age is 8:");

System.out.println("Correct pet weight is 40lbs:");

System.out.println("My updated records now say:");


}
}


public class Dog extends PetRecord
{

private int dogBreed;

public Dog()
{
super();
dogBreed = terrier;
}

public Dog(String breed, int boosterShot)
{
super(Initialbreed);
booster = initialboosterShot;
}

public void reset(String newName, int newbreed)
{

setName(newName);
boosterShot = newboosterShot;
}

public int getBreed()
{

return breed;
}

public void setboosterShot(int newboosterShot)
{
boosterShot = newboosterShot;
}

public void writeOutput()
{
System.out.println("breedName: " + getbreedName());
System.out.println("boosterShot: " + boosterShot);

}
public boolean equals(breed)

{
return (this.sameName(otherbreed)

&& (this.boosterShot== otherboosterShot.newBreed));
}

}

Topic: To implement a scrollbar in Swing Previous Topic   Next Topic Topic: help, i need to know how ACM last year coded this problem!!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use