Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Creating a Unit Converter Using Java Eclipse


Due date 9/23/16 by 11:59PM Homework 2 In this homework you are going to develop a simple metric/imperial system converter to convert: centimeters to inches inches to centimeters yards to meters meters to yards ounces to grams grams to ounces pounds to kilograms kilograms to pounds Create a class named UnitConverter In the main method, ask the user to input a distance or a weight amount. Assume that the input string will contain a number (with or without decimals) followed by a space followed by a unit of measurement that can be one of the following: in, cm, oz, gm, kg, lb, yr, m. Here are 5 examples of inputs: "19.342124 cm" "10 oz" "8.3 gm" "111.5 in" “10.7 m” Process the input to store the number and the unit separately, in two variables. Remember to name the variables following naming conventions covered in class. TIP: you know that the value and the unit of measurement are separated by a space (one space character). Depending on the unit value, the number should be transformed to the other measurement system. For example, if the unit is "cm", then the number will be converted to inches, or if the unit is "oz", the number will be converted to grams (gr). You can find conversion factors at or at or TIP: when comparing the unit of measurement to "cm", "in", "oz" and "gr", remember that these are string and comparing string should be done using the equals() method. You can also use equalsIgnoreCase() method, which will make your program less fragile. Display the result of the conversion. Your output should contain both the original value and units, as well as the converted value and units. For example, if input is "19.342124 cm" , the system should output : 19.342124 cm = 7.61501 in Also consider the following as VERY important: Use constants when appropriate (hint: conversion factors should be constants!) When defining variables, constants, methods, respect naming conventions Add MEANINGFUL comments to your code. Make sure your comments are succinct and appropriate. Attachments
Tags Clarifications


Unit converter solution.


In the zip file you'll find the eclipse project containing the solution for the given homework and also a screenshot of the program output. Attachments
Screen Shot 2016-09-24 at 01.42.09.png (15 K) Download Preview (5 K) Download

private static final double POUND_TO_KG = 0.453592; private static final double INCH_TO_CM = 2.54; private static final double YARD_TO_METER = 0.9144; private static final double GRAM_TO_OUNCE = 0.035274; private static final double KG_TO_POUND = 2.20462; private static final double CM_TO_INCH = 0.393701; private static final double METER_TO_YARD = 1.09361; private

Purchase Answer