Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java programming: input kilograms and output is pounds. Round answer to 2 decimc

ID: 671562 • Letter: J

Question

Java programming: input kilograms and output is pounds. Round answer to 2 decimcal places. Use dialog boxes for input and output.

I'm working through the correct stucture and getting 3 errors so far.

Any insight would be helpful.

Thanks

import.javax.swing.*; //this will allow for dialog boxes
import java.text.DecimalFormat; //this will allow for decimal numbers

//program inputs kilograms and outputs pounds

public class kilogramsconvertpounds
{
public static void main(string[] args)
{

double kilograms;
double pounds;
double pounds = kilograms * 2.2;
  
  
  
String weight;
String outputStr;
  
weight = JOptionPane.showInputDialog(null,"Enter weight in kiliograms"); //this option allows for input with dialog box
weight = float.parseFloat ("Input in Kilograms"); // this changes string to decimal
  
outputStr = weight;
outputStr = String.format("2 decimal places" + "places = %.2f%n"); // this allows for 2 decimal places
  
JOptionPane.showMessageDialog(null,"weight in pounds"); //output in a dialog box
  
System.exit (0); //exit and clear
  
}
}

Explanation / Answer

import java.io.*;
import javax.swing.*; //this will allow for dialog boxes
import java.text.DecimalFormat; //this will allow for decimal numbers
//program inputs kilograms and outputs pounds
public class kilogramsconvertpounds
{
public static void main(String[] args) throws IOException
{

double kilograms;
double pounds;

  
  
  
float weight;
String outputStr;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str;
str = JOptionPane.showInputDialog(null,"Enter weight in kiliograms"); //this option allows for input with dialog box
weight = Float.parseFloat(str); // this changes string to decimal
pounds = weight * 2.2;
outputStr = String.format("2 decimal places = %.2f%n",pounds); // this allows for 2 decimal places
  
JOptionPane.showMessageDialog(null,"weight in pounds"+outputStr); //output in a dialog box
  
System.exit (0); //exit and clear
  
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote