Advertisement
Guest User

Untitled

a guest
May 30th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1.  
  2.  
  3.  
  4. class TestDogs{
  5.  
  6. public static void main(String[] args) {
  7. Dogs breed1 = new Dogs("Pitbull", "Black", 6, 15, 750, 80.3, 500);
  8. Dogs breed2 = new Dogs("Poodle", "White", 4, 19, 1000, 75.7, 500);
  9. Dogs breed3 = new Dogs("Labrador", "Brown", 3, 17, 600, 85.4, 500);
  10.  
  11. System.out.println("Dog Breeds");
  12. System.out.println("-----------------------------");
  13. PrintDogs(breed1);
  14. PrintDogs(breed2);
  15. PrintDogs(breed3);
  16.  
  17. System.out.println("Breed of dog: " +breed1.getTheColor()+" "+breed1.getTheBreed());
  18. System.out.print("Current purchase: $");
  19. System.out.printf("%.2f", breed1.getTheDeal());
  20. breed1.changeTheDeal(300);
  21. System.out.print("\nNew purchase price: $");
  22. System.out.printf("%.2f", breed1.getTheDeal());
  23. System.out.println("\n-----------------------------");
  24. System.out.print("\nCurrent selling price: $");
  25. System.out.printf("%.2f", breed1.getThePrice());
  26.  
  27. breed1.changeThePrice(400);
  28. System.out.print("\nNew selling price: $" );
  29. System.out.printf("%.2f", breed1.getThePrice());
  30.  
  31. System.out.println("\n------------------------------");
  32. System.out.println("Breed of dog: " +breed2.getTheColor()+" "+breed2.getTheBreed());
  33. breed2.changeTheBreed("Standard Poodle");
  34. System.out.println("Change the Breed: " +breed2.getTheBreed());
  35. System.out.println("-----------------------------");
  36. }
  37.  
  38. public static void PrintDogs(Dogs m){
  39. System.out.println("Breed of dog: " +m.getTheColor()+" "+ m.getTheBreed());
  40. System.out.println("Age: " +m.getTheAge());
  41. System.out.println("Max Speed of Dog: "+m.getTheSpeed() + "mph");
  42. System.out.println("Decibal Level of Bark: "+m.getTheBark() + " "+ "Db");
  43. System.out.print("Sale Price: $");
  44. System.out.printf("%.2f", m.getThePrice()); //%.2f define; output displaying 2 decimals, %.3f-3decimals. etc
  45. System.out.println(" ");
  46. System.out.print("Profit: $");
  47. System.out.printf("%.2f", m.getTheProfit());
  48. System.out.println();
  49. System.out.println("-----------------------------");
  50. }
  51. }
  52.  
  53. class Dogs {
  54.  
  55. private String breed, color;
  56. private int age=0, speed=0;
  57. private double price=0.0, bark=0.0, profit=0.0, deal=0.0;
  58. private String name;
  59.  
  60.  
  61. public Dogs(String theBreed, String theColor, int theAge, int theSpeed, int thePrice, double theBark, int theDeal){
  62.  
  63. breed = theBreed;
  64. color = theColor;
  65. age = theAge;
  66. speed = theSpeed;
  67. price = thePrice;
  68. bark = theBark;
  69. deal = theDeal;
  70. }
  71.  
  72. public String getTheBreed() {
  73. return breed;
  74. }
  75.  
  76. public String getTheColor(){
  77. return color;
  78. }
  79.  
  80. public int getTheAge(){
  81. return age;
  82. }
  83. public int getTheSpeed(){
  84. return speed;
  85. }
  86. public double getThePrice(){
  87. return price;
  88. }
  89. public double getTheBark(){ //Accessor method; "public"
  90. return bark;
  91. }
  92. double getTheDeal(){
  93. return deal;
  94. }
  95.  
  96. double getTheProfit(){ //Mutator method; "private"
  97. profit = getThePrice() - getTheDeal();
  98. return profit;
  99. }
  100.  
  101. //Changers
  102. void changeThePrice(double amount){
  103. price = amount;
  104. }
  105. void changeTheDeal(double amount){
  106. deal = amount;
  107. }
  108. void changeTheBreed(String name){
  109. breed = name;
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement