/* Title/Author: cage.java -- Daniel Paepcke Description : Allows cage enclosure dimensions to be entered in meters or inches. Area, number of required 8-meter fence sections, and amount of spare fencing is given the the user. Please Note : This program does not comply exactly to the guidlines, but I hope that it is of sufficient complexity. */ class cage { public static void main(String[] args) { double length = 0; double width = 0; double unit; double leninch = 0; double widinch = 0; System.out.println("Welcome to Jack's Hardware pen calculator utility \n"); System.out.println("Jack's Hardware sells only 8-meter-long fencing sections."); System.out.println("This utility determines how many must be purchased for your project."); for ( ; ; ){ //Here we loop the entire program minus the intro above System.out.print("\n For meters..........1 \n For inches..........2 \n To quit.............3 "); unit = Input.real(); if(unit == 3) //Begin the IF statement which will select between options 1,2,3 break; else if(unit == 1){ /* ######################### BEGIN CALCULATOR WITH METERS ################# */ System.out.print("\nEnter Width in meters: "); width = Input.real(); while (width <= 0){ System.out.println("In this universe, there is no such thing as a " + width + "-meter distance"); System.out.print("Enter a real width: "); width = Input.real(); } System.out.print("Enter Length in meters: "); length = Input.real(); while (length <= 0){ System.out.println("In this universe, there is no such thing as a " + length + "-meter distance"); System.out.print("Enter a real length: "); length = Input.real(); } System.out.println("The total area of your proposed enclosure is " + (length * width) + " square meters"); System.out.println("You will need to purchase " + Math.ceil((2 * width + 2 * length) / 8) + " sections of fencing"); System.out.println("You'll be left with " + ((((2 * width + 2 * length) / 8) - (Math.floor((2 * width + 2 * length) / 8))) * 8) + " meters of spare fencing"); /* ############################ END CALCULATOR WITH METERS ################# */ } else if(unit == 2){ /* ##################### BEGIN CALCULATOR WITH FEET&INCHES ################# */ System.out.print("\nEnter Width in inches: "); widinch = Input.real(); while (widinch <= 0){ System.out.println("In this universe, there is no such thing as a " + width + "-inch distance"); System.out.print("Enter a real width: "); widinch = Input.real(); } System.out.print("Enter Length in inches: "); leninch = Input.real(); while (leninch <= 0){ System.out.println("In this universe, there is no such thing as a " + length + "-inch distance"); System.out.print("Enter a real length: "); leninch = Input.real(); } System.out.println("The total area of your proposed enclosure is " + (leninch * widinch * 25.4 / 1000) + " square meters"); System.out.println("You will need to purchase " + Math.ceil((2 * widinch * 25.4 / 1000 + 2 * leninch * 25.4 / 1000) / 8) + " sections of fencing"); System.out.println("You'll be left with " + ((((2 * widinch + 2 * leninch * 25.4 / 1000) / 8) - Math.floor((2 * widinch + 2 * leninch * 25.4 / 1000) / 8)) * 8) + " meters of spare fencing"); /* ###################### END CALCULATOR WITH FEET&INCHES ################# */ } else{ System.out.println("\n Your selection response was not recognized. Please try again."); } } } } // ~~~~~~ And now a sample output ~~~~~~ /* C:\java\dev>java cage Welcome to Jack's Hardware pen calculator utility Jack's Hardware sells only 8-meter-long fencing sections. This utility determines how many must be purchased for your project. For meters..........1 For inches..........2 To quit.............3 1 Enter Width in meters: 12 Enter Length in meters: 15 The total area of your proposed enclosure is 180.0 square meters You will need to purchase 7.0 sections of fencing You'll be left with 6.0 meters of spare fencing For meters..........1 For inches..........2 To quit.............3 2 Enter Width in inches: 480 Enter Length in inches: 192 The total area of your proposed enclosure is 2340.864 square meters You will need to purchase 5.0 sections of fencing You'll be left with 1.7536000000000058 meters of spare fencing For meters..........1 For inches..........2 To quit.............3 3 C:\java\dev> */