Question

Q: Create a version of the UnitConverter application to convert from inches to foot. Read the...

Q: Create a version of the UnitConverter application to convert from inches to foot. Read the inches value from the user.

A:

import java.util.*;
class UnitConverter{
   public static void main(String[] args){
int inches;
int foot;

Scanner scan=new Scanner(System.in);
System.out.println("Enter inches:");
inches=scan.nextInt();
System.out.println(inches/12+" feet and "+inches%12+" inches.");
}
}

Q: Write a program that converts grams to pounds. (One pound equals 453.592 grams.) Read the grams value from the user as a floating point value.

A:

import java.util.*;
class GramsToPounds{
   public static void main(String[] args){
double pounds;
double grams;
Scanner scan=new Scanner(System.in);
System.out.println("Enter grams:");
grams=scan.nextFloat();
pounds=grams/453.592;
System.out.println(pounds+" pounds");
}
}


Q: Write a program that reads values representing the weight in kilograms, grams, and milligrams and then prints the equivalent weight in milligrams. (For example, 1 kilogram, 50 grams, and 42 milligrams is equivalent to 10,50,042 milligrams.)

A:

import java.util.*;
class ProblemMilligrams{
public static void main(String[] args){
int kilograms;
int grams;
int milligrams;
int millik;
int millig;
Scanner scan=new Scanner(System.in);
System.out.println("Enter kilograms:");
kilograms=scan.nextInt();
System.out.println("Enter grams:");
grams=scan.nextInt();
System.out.println("Enter milligrams:");
milligrams=scan.nextInt();
millik=kilograms*1000000;
millig=grams*1000;
System.out.println((millik+millig+milligrams)+" milligrams");
}
}

Q: Create a version of the previous project that reverses the com- putation. That is, read a value representing the weight in mil- ligrams, then print the equivalent weight as a combination of kilograms, grams, and milligrams. (For example, 90,70,056 milligrams is equivalent to 9 kilograms, 70 grams, and 56 milligrams.)

A:

import java.util.*;
class ProblemMilligramsBackwards{
public static void main(String[] args){
int kilograms;
int grams;
int milligrams;

Scanner scan=new Scanner(System.in);

System.out.println("Enter milligrams:");
milligrams=scan.nextInt();
kilograms=milligrams/1000000;
milligrams=milligrams%100000;
grams=milligrams/1000;
milligrams=milligrams%1000;
System.out.println(kilograms+" kilograms, "+grams+" grams, "+milligrams+" milligrams.");
}
}

These are the questions and answers but I can't understand how to put it into one java file, I need help with putting all these codes into one file.

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

import java.util.*;

class UnitConverter {

public static void main(String[] args) {

int inches;

int foot;

Scanner scan = new Scanner(System.in);

System.out.println("Enter inches:");

inches = scan.nextInt();

System.out.println(inches / 12 + " feet and " + inches % 12 + " inches.");

double pounds;

double grams;

scan = new Scanner(System.in);

System.out.println("Enter grams:");

grams = scan.nextFloat();

pounds = grams / 453.592;

System.out.println(pounds + " pounds");

int kilograms;

int milligrams;

int millik;

int millig;

scan = new Scanner(System.in);

System.out.println("Enter kilograms:");

kilograms = scan.nextInt();

System.out.println("Enter grams:");

grams = scan.nextInt();

System.out.println("Enter milligrams:");

milligrams = scan.nextInt();

millik = kilograms * 1000000;

millig = (int) (grams * 1000);

System.out.println((millik + millig + milligrams) + " milligrams");

scan = new Scanner(System.in);

System.out.println("Enter milligrams:");

milligrams = scan.nextInt();

kilograms = milligrams / 1000000;

milligrams = milligrams % 100000;

grams = milligrams / 1000;

milligrams = milligrams % 1000;

System.out.println(kilograms + " kilograms, " + grams + " grams, " + milligrams + " milligrams.");

}

}


--------------------------------------------------------------------------------------------------------------------
SEE OUTPUT


THANKS, PLEASE COMMENT if there is any concern.

Add a comment
Know the answer?
Add Answer to:
Q: Create a version of the UnitConverter application to convert from inches to foot. Read the...
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
  • import java.util.Scanner; public class SCAN { public static void main(String[ ] args) { int x, y,...

    import java.util.Scanner; public class SCAN { public static void main(String[ ] args) { int x, y, z; double average; Scanner scan = new Scanner(System.in); System.out.println("Enter an integer value"); x = scan.nextInt( ); System.out.println("Enter another integer value"); y = scan.nextInt( ); System.out.println("Enter a third integer value"); z = scan.nextInt( ); average = (x + y + z) / 3; System.out.println("The result of my calculation is " + average); } } What is output if x = 0, y = 1 and...

  • 5. Write a static method "f(n)" in the space provide, that returns O if n is...

    5. Write a static method "f(n)" in the space provide, that returns O if n is even, and if n is odd, returns 1 or -1 according as n is greater than or less than 0. importjava.util.Scanner; public class Q_05 Your "f(n)" method: public static void main(String args[]) mana int n; Scanner input = new Scanner(System.in); System.out.print("Please enetrn: "); n=input.nextInt(); System.out.println(f(n)); "Method f(n)" 7. Write a static method "max" in the space provide, that returns the maximum value from 3...

  • Complete the following Java program by writing the missing methods. public class 02 { public static...

    Complete the following Java program by writing the missing methods. public class 02 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter a number: int n = scan.nextInt(); if (isOdd (n)) { //Print n to 1 System.out.println("Print all numbers from "+n+" to 1"); printNumToOne (n); } else { System.out.println(n + " is //End of main()

  • I am working on this switch statement code and I am getting errors. Please help. import...

    I am working on this switch statement code and I am getting errors. Please help. import java.util.Scanner; public class Switchstatement { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here } class Convertor { public static void main(String[] args) {    int choice;    Double Yen, UsDollars, Kilometer, Miles, Kilograms, Pounds, Inches; Double Centimeters, result;       Scanner scanner = new Scanner(System.in);    System.out.print("Enter 1\t UsDollars to Yen:...

  • JAVA: Rewrite the following code to where the inputs are from a file. The file name...

    JAVA: Rewrite the following code to where the inputs are from a file. The file name will be from the input from the user scanner. CODE: import java.util.*; public class Q1 { public static int sumOD (int k) { int sumOD = 0; int in = k; while (in != 0) { int digitON = in % 10; sumOD += digitON; in /= 10; } return sumOD; }    public static void main(String[] args) { int n, i, k; System.out.println("Enter...

  • This assignment requires comments for each line explaining why it is necessary for the coding to...

    This assignment requires comments for each line explaining why it is necessary for the coding to run properly. I understand most of it but not all. import java.util.Scanner; // comment here: public class Age { // comment here:       public static void main (String[] args){ // comment here: final int MINOR = 21;// Scanner scan = new Scanner (System.in); // comment here: System.out.print ("Enter your age: "); // comment here: int age = scan.nextInt();//comment here: System.out.println ("You entered: " +...

  • Below I have my 3 files. I am trying to make a dog array that aggerates...

    Below I have my 3 files. I am trying to make a dog array that aggerates with the human array. I want the users to be able to name the dogs and display the dog array but it isn't working. //Main File import java.util.*; import java.util.Scanner; public class Main {    public static void main(String[] args)    {    System.out.print("There are 5 humans.\n");    array();       }    public static String[] array()    {       //Let the user...

  • Please put both of this loops into one program. Set it up so that there is...

    Please put both of this loops into one program. Set it up so that there is one main function and both loops are within it. Thank You. import java.util.Scanner; public class WhileDavidMungomaLab12 { public static void main(String[] args) { int aScore = -1; while (aScore < 0 || aScore > 100) { Scanner sc = new Scanner(System.in); System.out.println("Please enter a valid number that is within the specified range(0 and 100): "); aScore = sc.nextInt(); } } } AND import java.util.Scanner;...

  • (How do I remove the STATIC ArrayList from the public class Accounts, and move it to...

    (How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in);    public static void main(String[] args) { Scanner scanner = new Scanner(System.in);    int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...

  • Hi I need help with a java program that I need to create a Airline Reservation...

    Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it...

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