Question

JAVA PROGRAMMING: Create a program which will calculate and output as formatted output the kilometers or...

JAVA PROGRAMMING:

Create a program which will calculate and output as formatted output the kilometers or miles, given as keyboard input the miles or kilometers, as inputted as a double number. That is, the user has a choice what to calculate. The original value inputted should be displayed along with the calculated miles or kilometers. Demonstrate escape sequences, a while loop or a do…while loop, and named constants as needed,  should be implemented. Finally, input, processing, and output must be implemented by methods; at least three, probably four methods.

Homework Answers

Answer #1

Please find below code and don't forget to give a Like.

Here, we used total of 4 methods as mentioned.

1.input (input())

2.processing(conversion_miles2kms())

3.processing(conversion_kms2miles())

4.output(display_output())

Scanner is used to take input from user. Check the below screenshot on how to give the inputs:

Code:

import java.util.Scanner;
public class Main
{
   public static void main(String[] args) {
   double value,convert_Value=0;
   boolean b=true;
   char inp=' ';
  
   value=input();
       while(b){
       System.out.println("Enter 'k' to convert Miles to KMs or 'm' for viceversa:");
       Scanner input1=new Scanner(System.in);
       inp=input1.next().charAt(0);
       if(inp=='k' || inp=='m'){
       b=false;
       }
      
       }
       if(inp=='k'){
       convert_Value=conversion_miles2kms(value);
       System.out.print(value+" miles converted value into kms is ");
       }
       else if(inp=='m'){
       convert_Value=conversion_kms2miles(value);
       System.out.print(value+" kms converted value into miles is ");
       }
       display_output(convert_Value);
   }
   public static double input(){
double val;
System.out.println("Enter a value to convert");
Scanner input=new Scanner(System.in);
val=input.nextDouble();
return val;
}
  
public static double conversion_miles2kms(double value){
double convert;
convert=value*1.6;
return convert;
}
public static double conversion_kms2miles(double value){
double convert;
convert=value/1.6;
return convert;
}
public static void display_output(double convert_Value){
System.out.println(convert_Value);
}
}

Output:

Know the answer?
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
Similar Questions
C++ PROGRAMMING Assignment: For this assignment, you will construct a program which is capable of taking...
C++ PROGRAMMING Assignment: For this assignment, you will construct a program which is capable of taking a user-given number, and adding up all of the numbers between 1 and the given number. So if someone inputs 12, it should add 1 + 2 + 3 + 4 + … 9 + 10 + 11 + 12, and return the answer. However, you’ll be using two different methods to do this. The first method should utilize either a for loop or...
Write a Java program named BinaryConversion that will convert base 2 numbers to base 10 numbers....
Write a Java program named BinaryConversion that will convert base 2 numbers to base 10 numbers. The data for this program will be entered from the keyboard using JOptionPane one 16-bit binary number at a time. Note that each base 2 number is actually read in as a String. The program should continue until a 16-bit base 2 number consisting of all 0’s is entered. Once the 16-bit number has been entered your program should make sure that the input...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the program title and programmer’s name. Then get the user’s name, and greet the user. • Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer in the range [1 .. 46]. • Get and validate the user input (n). • Calculate and display all of the Fibonacci numbers up to and including the nth...
Create a Java Program to calculate luggage costs. The Business Rules are: A. Two bags per...
Create a Java Program to calculate luggage costs. The Business Rules are: A. Two bags per person are free. B. The Excess Bag Charge is $75 per bag. The program needs to do the following: 1. In your main method(),    Create integers to store the number of Passengers and also the total number of bags    Prompt for the number of passengers on a ticket.    Prompt for the total number of bags for all passengers on a ticket....
Using C++, Python, or Java, write a program that: In this programming exercise you will perform...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform an empirical analysis of the QuickSort algorithm to study the actual average case behavior and compare it to the mathematically predicted behavior. That is, you will write a program that counts the number of comparisons performed by QuickSort on an array of a given size. You will run the program on a large number of arrays of a certain size and determine the average...
Code in Java SAMPLE PROGRAM OUTPUT Because there are several different things your program might do...
Code in Java SAMPLE PROGRAM OUTPUT Because there are several different things your program might do depending upon what the user enters, please refer to the examples below to use to test your program. Run your final program one time for each scenario to make sure that you get the expected output. Be sure to format the output of your program so that it follows what is included in the examples. Remember, in all examples bold items are entered by...
JAVA: MUST BE DONE IN JAVA Assignment: Write algorithms and programs to play “non-betting” Craps. Craps...
JAVA: MUST BE DONE IN JAVA Assignment: Write algorithms and programs to play “non-betting” Craps. Craps is a game played with a pair of dice. In the game, the shooter (the player with the dice) rolls a pair of dice and the number of spots showing on the two upward faces are added up. If the opening roll (called the “coming out” roll) is a 7 (“natural”) or 11 (“yo-leven”), the shooter immediately wins the game. If the coming out...
Program Description A local company has requested a program to calculate the cost of different hot...
Program Description A local company has requested a program to calculate the cost of different hot tubs that it sells. Use the following instructions to code the program: File 1 - HotTubLastname.java Write a class that will hold fields for the following: The model of the hot tub The hot tub’s feature package (can be Basic or Premium) The hot tub’s length (in inches) The hot tub’s width (in inches) The hot tub’s depth (in inches) The class should also...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
***Programming language is Java. After looking at this scenario please look over the requirements at the...
***Programming language is Java. After looking at this scenario please look over the requirements at the bottom (in bold) THIS IS ALL THAT WAS PROVIDED. PLEASE SPECIFY ANY QUESTIONS IF THIS IS NOT CLEAR (don't just say more info, be specific)*** GMU in partnership with a local sports camp is offering a swimming camp for ages 10-18. GMU plans to make it a regular event, possibly once a quarter. You have been tasked to create an object-oriented solution to register,...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT