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

I\'m in an intro level Java programming class, and failing miserably at solving

ID: 3803437 • Letter: I

Question

I'm in an intro level Java programming class, and failing miserably at solving this problem. I need this application done in terms of what someone could do in the first few weeks of learning Java(ie no imports or shortcuts that absolute beginners wouldn't know how to use.) I apologize if this lengthens the process.

Java Program: Create an application that determines gravitational potential energy in joules for 3 objects based upon their inputted height (in meters and the ground is considered to be a zero height position.) and relevant mass (in kg).The output window displays all 3 in order from largest gravitational potential energy to smallest with each formula and calculation result. All input/output must accommodate 2 digits post decimal point. All Input/output done in JOptionPane

Gravitational Potential Energy Formula (in joules): Potential Energy = m *g * h

m is the mass of the object in kilograms

h is the height of the object in meters

g is the gravitational constant equal to 9.8 m/sec 2

Explanation / Answer

code.java:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication2;

import java.lang.*;
import java.util.Scanner;
import javax.swing.JOptionPane;
import java.util.Arrays;

public class code {

public static double round(double value, int places)
{
long factor = (long) Math.pow(10, places);
value = value * factor;
long tmp = Math.round(value);
return (double) tmp / factor;
}
  
public static void main(String[] args)
{
double[] weights = new double[3];
double[] heights = new double[3];
double[] GP = new double[3];
for(int i = 0 ; i<3 ; i++)
{
String s1;
s1 = JOptionPane.showInputDialog("Weight of person " + (i+1) );
weights[i] = Double.parseDouble(s1);
String s2;
s2 = JOptionPane.showInputDialog("height of person " + (i+1) );
heights[i] = Double.parseDouble(s2);
GP[i] = 9.8*weights[i]*heights[i];
GP[i] = round(GP[i], 2);
}
Arrays.sort(GP);
for(int i = 2 ; i>=0 ; i--)
{
JOptionPane.showMessageDialog(null, "The Potential Energy of person " + (i+1) + " is "+ String.valueOf(GP[i]) + " joules");
}
}
  
}

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