Question

Java COSC 237 Problem: You are to develop a program that allows a user to convert...

Java COSC 237 Problem: You are to develop a program that allows a user to convert lengths in the metric system (i.e., meters/centimeters) to the Imperial system (i.e., feet/inches) AND convert lengths in the Imperial system to the metric system.

Specifications

• Input may be given with or without decimal places.

• Error checking for invalid input is not required.

• The results are to be displayed with two decimal places of precision. (For example, 2 meters, 25 centimeters (225 centimeters) is equal to 7 feet, 4.58 inches.)

• The program should allow the user to continue to convert values until they choose to quit

• While the creation of your own classes (objects) is not expected, static methods (functions) should be utilized

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//if you have any queries please comment

import java.util.*;
import java.lang.*;
import java.io.*;

class ConversionSystem
{
public static void main (String[] args) throws IOException
{
String choice; //define choice to get user input
Scanner scan = new Scanner(System.in);
System.out.println("Please enter inputs for Conversion, if you want to stop enter 'quit'" );
choice = scan.nextLine(); //scan the input
while(!(choice.equals("quit"))) //take input until user enters quit
{
String[] inputStrings = choice.split(" "); //split the user input ex: "2 meters" to "2","meters"
Double length = Double.parseDouble(inputStrings[0]);   //convert first argument (ex: "2") to double
String converstionSystem = inputStrings[1]; //separate Conversion system from the user input ex:"meters"

if(converstionSystem.equals("meters")) //convert from meters to feet
{
Double result = length/0.305; //formula to convert
String resultFormated = String.format("%.2f", result); //format two decimal places of precision
System.out.println(resultFormated+"feet"); //print the output
}

else if(converstionSystem.equals("centimeters")) //convert from centimeters to inches
{
Double result = length*0.394; //formula to convert
String resultFormated = String.format("%.2f", result);//format two decimal places of precision
System.out.println(resultFormated+"inches");//print the output
}

else if(converstionSystem.equals("feet")) //convert from feet to meters
{
Double result = length*0.305; //formula to convert
String resultFormated = String.format("%.2f", result);//format two decimal places of precision
System.out.println(resultFormated+"meters"); //print the output
}

else if(converstionSystem.equals("inches")) //convert from inches to centimeters
{
Double result = length*2.54;//formula to convert
String resultFormated = String.format("%.2f", result);//format two decimal places of precision
System.out.println(resultFormated+"centimeters");//print the output
}

System.out.println("Please enter inputs for converstion, if you want to stop enter 'quit'" );
choice = scan.nextLine(); //scan the user input
}

}
}

Screenshot for Code :

import java.util.*; import java.lang.*; import java.io.*; class ConversionSystem public static void main (String/] args) thro

Input Format :

Input 2 meters 225 centimeters 6.56 feet 88.65 inches quit

Add a comment
Know the answer?
Add Answer to:
Java COSC 237 Problem: You are to develop a program that allows a user to convert...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need help with following C++ program: 3) Write a program in C++ with a menu. When...

    Need help with following C++ program: 3) Write a program in C++ with a menu. When the program executes it gives the user a list of choice to choose from. The user can input 1,2 or 3 only. For all other input, the message “Invalid Options” will be displayed. ****MENU**** 1) Convert length from feet to inches. 2) Convert length from meter to centimeters. 3) To quit the program

  • You want to write a converter program which will let user convert distance and weight from SI to ...

    Use functions to complete this C + + program You want to write a converter program which will let user convert distance and weight from SI to the USCS system and vice versa The formulae are as follows: 1. Distance in miles- distance in kilometers x 1.60 2. Weight in kilograms weight in pounds x 2.20 The program would let user input the number that they want to convert and then choose the units to and from which they want...

  • Language: C# In this assignment we are going to convert weight and height. So, the user...

    Language: C# In this assignment we are going to convert weight and height. So, the user will have the ability to convert either weight or height and as many times as they want. There conversions will only be one way. By that I mean that you will only convert Pounds to Kilograms and Feet and Inches to Centimeters. NOT the other direction (i.e. to Pounds). There will be 3 options that do the conversion, one for each type of loop....

  • Write a Java program to convert power in kilowatts (kW) of an electric car motor to...

    Write a Java program to convert power in kilowatts (kW) of an electric car motor to horsepower (hp) as follows: Prompt the user to enter the power in kilowatts (kW) of the electric car motor. Convert the power to horsepower. In a comment, reference your source for the conversion factor (non-wiki source). (As a rough estimate, 1 hp equals ~0.75 kW.) Output the power in horsepower (hp). Print the result with 2 decimal places. Once this is working, add a...

  • You are to write a program IN C++ that asks the user to enter an item's...

    You are to write a program IN C++ that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: if the an item's wholesale cost is 5.00 and its markup percentage is 100%, then the item's retail price is 10.00 If an item's wholesale cost is 5.00 and its markup percentage is 50%, then the item's retail price is 7.50 Program design specs. You should have 5...

  • This is in C++. Example: You will write a program that will prompt the user to...

    This is in C++. Example: You will write a program that will prompt the user to enter a grade out of 100 and then show them what the equivalent grade points value is. The main() function will handle the input and output tasks, but the actual conversion will occur in a function called GradePoints(). GradePoints Specifications This function is strictly a processing function, meaning that there are no console input or output steps in the actual function. Consider that this...

  • **This is for the C Language. Trigonometric Calculator Specification You are required to write a program...

    **This is for the C Language. Trigonometric Calculator Specification You are required to write a program that calculates and displays values of the trigonometric functions sine, cosine, and tangent for user-supplied angular values. The basic program must comply with the following specification. 1. When the program is run, it is to display a short welcome message. TRIG: the trigonometric calculator 2. The program shall display a message prompting the user to enter input from the keyboard. Please input request (h-help,...

  • Assignment Overview This assignment will give you more experience on the use of strings and iterations....

    Assignment Overview This assignment will give you more experience on the use of strings and iterations. The goal of this project is to use Google’s currency converter API to convert currencies in Python and display the result to user by processing the returned results. Assignment Background The acronym API stands for “Application Programming Interface”. It is usually a series of functions, methods or classes that supports the interaction of the programmer (the application developer, i.e., you) with some particular program....

  • Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQ...

    Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQUIRED for this program will use two stacks, an operator stack and a value stack. Both stacks MUST be implemented using a linked list. For this program, you are to write functions for the linked list stacks with the following names: int isEmpty (stack); void push (stack, data); data top (stack); void pop (stack); // return TRUE if the stack has no...

  • Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQ...

    Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQUIRED for this program will use two stacks, an operator stack and a value stack. Both stacks MUST be implemented using a linked list. For this program, you are to write functions for the linked list stacks with the following names: int isEmpty (stack); void push (stack, data); data top (stack); void pop (stack); // return TRUE if the stack has no...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT