Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. /*
  2. * Name: Your Name
  3. * Topic 2: Fundamentals
  4. * Course: CSI233 (Fall 2019)
  5. * Date: September 19, 2019
  6. * Description: Represent a dog competing in a dog show.
  7. * Displays dog's weight after name.
  8. */
  9.  
  10. import java.util.Scanner;
  11.  
  12. public class DogInfo
  13. {
  14. // Conversion factor for pounds to ounces.
  15. static final int OUNCES_IN_POUND = 16;
  16.  
  17. // Whole number of weeks in a year.
  18. static final int WEEKS_IN_YEAR = 52;
  19.  
  20. // Name of dog.
  21. static String name;
  22.  
  23. // Weight of dog in whole pounds and ounces.
  24. static int wtPounds;
  25. static int wtOunces;
  26.  
  27. // Whole number age of dog.
  28. static int age;
  29.  
  30. static String address;
  31.  
  32. public static void main(String[] args)
  33. {
  34. // name = "Se\u00F1orita Yappy McSnarls";
  35.  
  36.  
  37. Scanner console = new Scanner(System.in);
  38.  
  39. System.out.print("Enter dog's name: ");
  40. name = console.nextLine();
  41.  
  42. System.out.print("Enter the Street address and Zip code: ");
  43. address = console.nextLine();
  44.  
  45.  
  46.  
  47. System.out.print("Enter Weight Pounds: ");
  48. wtPounds = console.nextInt();
  49.  
  50. System.out.print("Enter Weight Ounces: ");
  51. wtOunces = console.nextInt();
  52.  
  53. System.out.print("Enter the age: ");
  54. age = console.nextInt();
  55.  
  56.  
  57.  
  58. // Transform titles.
  59. name = name.replace("Se\u00F1orita", "Ms.");
  60. name = name.replace("Se\u00F1ora", "Mrs.");
  61. name = name.replace("Se\u00F1or", "Mr.");
  62.  
  63. double weight;
  64. weight = weightInPounds();
  65.  
  66. int truncatedWeight =(int)Math.floor(weight);
  67.  
  68. // Estimate weight of dog when it was a puppy.
  69. int pupAgeWeeks = 12;
  70. double pupWeight;
  71.  
  72. // Compute estimate puppy weight.
  73. pupWeight = (weight / WEEKS_IN_YEAR) * pupAgeWeeks;
  74.  
  75. // Extract pounds and rounded ounces from puppy weight.
  76. int pupWtPounds = (int)pupWeight;
  77. double pupWtOunces = (pupWeight - pupWtPounds) * OUNCES_IN_POUND;
  78. int pupWtWholeOunces = (int)Math.round(pupWtOunces);
  79.  
  80. // Output each label/data individually.
  81. System.out.print("Name: " + name + "\n");
  82. System.out.print("Address: " + address + "\n");
  83. System.out.print("weight: " + weight + " lbs \n");
  84. System.out.print("age = " + age + " years \n");
  85.  
  86.  
  87. System.out.println(
  88. "Truncated weight: " +
  89. truncatedWeight +
  90. " lbs");
  91.  
  92. // Display estimated weight of dog
  93. // when it was a puppy of a certain
  94. // number of weeks old.
  95. System.out.print("Puppy weight at ");
  96. System.out.print(pupAgeWeeks);
  97. System.out.print(" weeks = ");
  98. System.out.print(pupWeight);
  99. System.out.println(" lbs");
  100.  
  101. System.out.println(
  102. "Puppy weight = " + pupWtPounds +
  103. " lbs and " + pupWtWholeOunces + " oz");
  104.  
  105. }
  106.  
  107. // Convert dog's weight, which is in whole pounds and
  108. // ounces, into fractional pounds.
  109. public static double weightInPounds()
  110. {
  111. // Convert ounces to pounds.
  112. // ENSURE 1 OPERAND OF DIVISION IS FL-PT.
  113. //double fracPounds = wtOunces / OUNCES_IN_POUND;
  114. //return wtPounds + fracPounds;
  115. //return wtPounds + (double)wtOunces / OUNCES_IN_POUND;
  116. double pounds;
  117. pounds = wtOunces;
  118. pounds /= OUNCES_IN_POUND;
  119. pounds += wtPounds;
  120. return pounds;
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement