Question

In: Computer Science

3) Create a Java program that uses NO methods, but use scanner: Write a program where...

3) Create a Java program that uses NO methods, but use scanner:

Write a program where you will enter the flying distance from one continent to another, you will take the plane in one country, then you will enter miles per gallon and price of gallon and in the end it will calculate how much gas was spend for that distance in miles.

Steps: 1) Prompt user to enter the name of country that you are

2) Declare variable to enter and relate to scanner.

3) Prompt user to enter the name of country where you are willing to go.

4) Declare variable to enter and relate to scanner.

5) Create scanner, also declare variable double for distance, miles Per Gallon and price Per Gallon.

6) Prompt the user to enter data of your choice for each one of them

7) Create variable ticket which calculate distance divided by multiplication of miles Per Gallon and price Per Gallon

8) Create condition that if ticket cost is less then 1000 you are flying close, if greater then 1000 and less then 5000 they are flying far, if greater then 10000 very far and son on

9) In the end display the miles from one country to another and cost of flying and how far you are flying based on conditions.

Solutions

Expert Solution

import java.util.Scanner;
public class Main
{
   public static void main(String[] args)
   {
   Scanner sc = new Scanner(System.in);
   System.out.print("Enter the name of the country that are travelling from: ");
   String from = sc.next();
   System.out.print("Enter the name of country where you are willing to go: ");
   String to = sc.next();  
   double distance,mpg,ppg;
   System.out.print("Enter distance: ");
   distance=sc.nextDouble();
   System.out.print("Enter miles Per Gallon: ");
   mpg=sc.nextDouble();  
   System.out.print("Enter price Per Gallon: ");
   ppg=sc.nextDouble();     
   double ticket = distance/(mpg*ppg);
   String str="";
   if(ticket<1000)
   {
   str="you are flying close";
   }
   else if(ticket>1000&&ticket<5000)
   {
   str="you are flying far";
   }
   else
   {
   str="you are very far";
   }
   System.out.println("Miles from "+from+" to "+to+" = "+distance);
   System.out.println("Cost of flying = "+ticket);
   System.out.println(str);
   }
}


Related Solutions

Write a program in Java with a Scanner. Given an array and a number k where...
Write a program in Java with a Scanner. Given an array and a number k where k is smaller than the size of the array, write a program to find the k'th smallest element in the given array. It is given that all array elements are distinct. Example: Input: arr[] = {7,10,4,3,20,15} k = 3 Output: 7
8) Create the following program using Java. Circle calculation using methods Create scanner declare double variable...
8) Create the following program using Java. Circle calculation using methods Create scanner declare double variable radius = -999 declare character choice create do while loop inside of do loop write: System.out.println(); System.out.println("*** CIRCLE CALCULATIONS ***"); System.out.println(); System.out.println("1. Enter the radius of the circle"); System.out.println("2. Display the area of the circle"); System.out.println("3. Display the circumference of the circle"); System.out.println("4. Quit"); System.out.println(); System.out.println("Enter a number from 1 - 4"); System.out.println(); Declare choice character and relate to scanner declare switch (choice) case...
This for Java Programming Write a java statement to import the java utilities. Create a Scanner...
This for Java Programming Write a java statement to import the java utilities. Create a Scanner object to read input. int Age;     Write a java statement to read the Age input value 4 . Redo 1 to 3 using JOptionPane
5) Create the following in a Java program Create a scanner Prompt the user to enter...
5) Create the following in a Java program Create a scanner Prompt the user to enter the name where the box of mail is shipping from and create the variable and relate to scanner Prompt the user to enter the name of destination where the box of mail will be shipped and create the variable and relate to scanner Prompt the user to enter the weight of the package and create variable to relate to scanner Calculate cost of shipping...
Write a program in java which is in main and uses no classes, methods, loops or...
Write a program in java which is in main and uses no classes, methods, loops or if statements Ask the user to enter their first name Ask the user to enter their last name Print their initials followed by periods (ie. Clark Kent = C. K.) Print the number of letters in their last name
Write a program in java that uses methods to input data for calculation, calculate, and display...
Write a program in java that uses methods to input data for calculation, calculate, and display the results of the calculations. That is, there are at least three methods. The problem is to write a program that calculates the area of a rectangle. This action should be repeatable.
CIT 149 JAVA 1 program question? Write a program that will use static methods as described...
CIT 149 JAVA 1 program question? Write a program that will use static methods as described in the specifications below. Utilizing the if and else statements, write a program which will calculate a commission based on a two-tiered commission plan of 3% and 7% paid on amounts of $15,000 or less, or over $15,000 in monthly sales by a sales force paid on a commission basis. Use the output specifications below. ? Specifications There will be two classes (separate files)...
User the Scanner class for your input Write a java program to calculate the area of...
User the Scanner class for your input Write a java program to calculate the area of a rectangle. Rectangle Area is calculated by multiplying the length by the width   display the output as follow: Length =   Width = Area = Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
Assignment Purpose Write a well commented java program that demonstrates the use and re-use of methods...
Assignment Purpose Write a well commented java program that demonstrates the use and re-use of methods with input validation. Instructions It is quite interesting that most of us are likely to be able to read and comprehend words, even if the alphabets of these words are scrambled (two of them) given the fact that the first and last alphabets remain the same. For example, “I dn'ot gvie a dman for a man taht can olny sepll a wrod one way.”...
write the program in java. Demonstrate that you understand how to use create a class and...
write the program in java. Demonstrate that you understand how to use create a class and test it using JUnit Let’s create a new Project HoursWorked Under your src folder, create package edu.cincinnatistate.pay Now, create a new class HoursWorked in package edu.cincinnatistate.pay This class needs to do the following: Have a constructor that receives intHours which will be stored in totalHrs Have a method addHours to add hours to totalHrs Have a method subHours to subtract hours from totalHrs Have...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT