Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Name: Your Name
- * Topic 2: Fundamentals
- * Course: CSI233 (Fall 2019)
- * Date: September 19, 2019
- * Description: Represent a dog competing in a dog show.
- * Displays dog's weight after name.
- */
- import java.util.Scanner;
- public class DogInfo
- {
- // Conversion factor for pounds to ounces.
- static final int OUNCES_IN_POUND = 16;
- // Whole number of weeks in a year.
- static final int WEEKS_IN_YEAR = 52;
- // Name of dog.
- static String name;
- // Weight of dog in whole pounds and ounces.
- static int wtPounds;
- static int wtOunces;
- // Whole number age of dog.
- static int age;
- static String address;
- public static void main(String[] args)
- {
- // name = "Se\u00F1orita Yappy McSnarls";
- Scanner console = new Scanner(System.in);
- System.out.print("Enter dog's name: ");
- name = console.nextLine();
- System.out.print("Enter the Street address and Zip code: ");
- address = console.nextLine();
- System.out.print("Enter Weight Pounds: ");
- wtPounds = console.nextInt();
- System.out.print("Enter Weight Ounces: ");
- wtOunces = console.nextInt();
- System.out.print("Enter the age: ");
- age = console.nextInt();
- // Transform titles.
- name = name.replace("Se\u00F1orita", "Ms.");
- name = name.replace("Se\u00F1ora", "Mrs.");
- name = name.replace("Se\u00F1or", "Mr.");
- double weight;
- weight = weightInPounds();
- int truncatedWeight =(int)Math.floor(weight);
- // Estimate weight of dog when it was a puppy.
- int pupAgeWeeks = 12;
- double pupWeight;
- // Compute estimate puppy weight.
- pupWeight = (weight / WEEKS_IN_YEAR) * pupAgeWeeks;
- // Extract pounds and rounded ounces from puppy weight.
- int pupWtPounds = (int)pupWeight;
- double pupWtOunces = (pupWeight - pupWtPounds) * OUNCES_IN_POUND;
- int pupWtWholeOunces = (int)Math.round(pupWtOunces);
- // Output each label/data individually.
- System.out.print("Name: " + name + "\n");
- System.out.print("Address: " + address + "\n");
- System.out.print("weight: " + weight + " lbs \n");
- System.out.print("age = " + age + " years \n");
- System.out.println(
- "Truncated weight: " +
- truncatedWeight +
- " lbs");
- // Display estimated weight of dog
- // when it was a puppy of a certain
- // number of weeks old.
- System.out.print("Puppy weight at ");
- System.out.print(pupAgeWeeks);
- System.out.print(" weeks = ");
- System.out.print(pupWeight);
- System.out.println(" lbs");
- System.out.println(
- "Puppy weight = " + pupWtPounds +
- " lbs and " + pupWtWholeOunces + " oz");
- }
- // Convert dog's weight, which is in whole pounds and
- // ounces, into fractional pounds.
- public static double weightInPounds()
- {
- // Convert ounces to pounds.
- // ENSURE 1 OPERAND OF DIVISION IS FL-PT.
- //double fracPounds = wtOunces / OUNCES_IN_POUND;
- //return wtPounds + fracPounds;
- //return wtPounds + (double)wtOunces / OUNCES_IN_POUND;
- double pounds;
- pounds = wtOunces;
- pounds /= OUNCES_IN_POUND;
- pounds += wtPounds;
- return pounds;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement