Hello, I am having trouble making a program exactly what my professor wants. I know I need two variables meaning two JPoptionpanes but I am not sure how to calcuatore the percetange. Here is the assignment:
Write a program that reads two integers using the JOptionPane class: one representing the number of shots taken by a basketball player, the other representing the number of shots made by the same player. Calculate the shooting percentage and output it formatted with percent notation using the JOptionPane class.
Here is what I have so far(this is just stuff that I formula together and slap on the source code it doe snot work)
import javax.swing.JOptionPane;
import java.text.NumberFormat;
public class Basketball
{
public static void main( String [] args )
{
String input = JOptionPane.showInputDialog( null,
"Please enter shots taken by a basketball player" );
int shotstaken = Integer.parseInt( shotstaken );
JOptionPane.showMessageDialog( null, "Baseketball player has taken " +
+ shotstaken + " shots");
String input = JOptionPane.showInputDialog( null,
"Please enter shots made by a basketball player" );
int shotsmade = Integer.parseInt( shotsmade );
JOptionPane.showMessageDialog( null, "Baseketball player has made " +
+ shotsmade + " shots" );
NumberFormat percentFormat = NumberFormat.getPercentInstance( );
System.out.print( "The shooting percentage is " );
System.out.println( percentFormat.format( winningPercentage ) );
double percentFormat = Double.parseDouble(
JOptionPane.showInputDialog( null,
"" ) );
JOptionPane.showMessageDialog( null, "The shooting percentage is "
+ ( shotstaken / shotsmade) * 100 ) );
}
}
Write a program that reads two integers using the JOptionPane class: one representing the number of shots taken by a basketball player, the other representing the number of shots made by the same player. Calculate the shooting percentage and output it formatted with percent notation using the JOptionPane class.
Here is what I have so far(this is just stuff that I formula together and slap on the source code it doe snot work)
import javax.swing.JOptionPane;
import java.text.NumberFormat;
public class Basketball
{
public static void main( String [] args )
{
String input = JOptionPane.showInputDialog( null,
"Please enter shots taken by a basketball player" );
int shotstaken = Integer.parseInt( shotstaken );
JOptionPane.showMessageDialog( null, "Baseketball player has taken " +
+ shotstaken + " shots");
String input = JOptionPane.showInputDialog( null,
"Please enter shots made by a basketball player" );
int shotsmade = Integer.parseInt( shotsmade );
JOptionPane.showMessageDialog( null, "Baseketball player has made " +
+ shotsmade + " shots" );
NumberFormat percentFormat = NumberFormat.getPercentInstance( );
System.out.print( "The shooting percentage is " );
System.out.println( percentFormat.format( winningPercentage ) );
double percentFormat = Double.parseDouble(
JOptionPane.showInputDialog( null,
"" ) );
JOptionPane.showMessageDialog( null, "The shooting percentage is "
+ ( shotstaken / shotsmade) * 100 ) );
}
}