Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TestDogs{
- public static void main(String[] args) {
- Dogs breed1 = new Dogs("Pitbull", "Black", 6, 15, 750, 80.3, 500);
- Dogs breed2 = new Dogs("Poodle", "White", 4, 19, 1000, 75.7, 500);
- Dogs breed3 = new Dogs("Labrador", "Brown", 3, 17, 600, 85.4, 500);
- System.out.println("Dog Breeds");
- System.out.println("-----------------------------");
- PrintDogs(breed1);
- PrintDogs(breed2);
- PrintDogs(breed3);
- System.out.println("Breed of dog: " +breed1.getTheColor()+" "+breed1.getTheBreed());
- System.out.print("Current purchase: $");
- System.out.printf("%.2f", breed1.getTheDeal());
- breed1.changeTheDeal(300);
- System.out.print("\nNew purchase price: $");
- System.out.printf("%.2f", breed1.getTheDeal());
- System.out.println("\n-----------------------------");
- System.out.print("\nCurrent selling price: $");
- System.out.printf("%.2f", breed1.getThePrice());
- breed1.changeThePrice(400);
- System.out.print("\nNew selling price: $" );
- System.out.printf("%.2f", breed1.getThePrice());
- System.out.println("\n------------------------------");
- System.out.println("Breed of dog: " +breed2.getTheColor()+" "+breed2.getTheBreed());
- breed2.changeTheBreed("Standard Poodle");
- System.out.println("Change the Breed: " +breed2.getTheBreed());
- System.out.println("-----------------------------");
- }
- public static void PrintDogs(Dogs m){
- System.out.println("Breed of dog: " +m.getTheColor()+" "+ m.getTheBreed());
- System.out.println("Age: " +m.getTheAge());
- System.out.println("Max Speed of Dog: "+m.getTheSpeed() + "mph");
- System.out.println("Decibal Level of Bark: "+m.getTheBark() + " "+ "Db");
- System.out.print("Sale Price: $");
- System.out.printf("%.2f", m.getThePrice()); //%.2f define; output displaying 2 decimals, %.3f-3decimals. etc
- System.out.println(" ");
- System.out.print("Profit: $");
- System.out.printf("%.2f", m.getTheProfit());
- System.out.println();
- System.out.println("-----------------------------");
- }
- }
- class Dogs {
- private String breed, color;
- private int age=0, speed=0;
- private double price=0.0, bark=0.0, profit=0.0, deal=0.0;
- private String name;
- public Dogs(String theBreed, String theColor, int theAge, int theSpeed, int thePrice, double theBark, int theDeal){
- breed = theBreed;
- color = theColor;
- age = theAge;
- speed = theSpeed;
- price = thePrice;
- bark = theBark;
- deal = theDeal;
- }
- public String getTheBreed() {
- return breed;
- }
- public String getTheColor(){
- return color;
- }
- public int getTheAge(){
- return age;
- }
- public int getTheSpeed(){
- return speed;
- }
- public double getThePrice(){
- return price;
- }
- public double getTheBark(){ //Accessor method; "public"
- return bark;
- }
- double getTheDeal(){
- return deal;
- }
- double getTheProfit(){ //Mutator method; "private"
- profit = getThePrice() - getTheDeal();
- return profit;
- }
- //Changers
- void changeThePrice(double amount){
- price = amount;
- }
- void changeTheDeal(double amount){
- deal = amount;
- }
- void changeTheBreed(String name){
- breed = name;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement