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 https://www.britannica.com/science/British-Imperial-System or at https://en.wikipedia.org/wiki/United_States_customary_units or https://en.wikipedia.org/wiki/Imperial_units
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
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