Java beginners Assignment Help

Hashio

Distinguished
Jan 7, 2010
3
0
18,510
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 ) );





}
}
 

Hashio

Distinguished
Jan 7, 2010
3
0
18,510
I modify the program still but can't get it to calculate properly


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( input );
JOptionPane.showMessageDialog( null, "Baseketball player has taken " +
+ shotstaken + " shots");

String input2 = JOptionPane.showInputDialog( null,
"Please enter shots made by a basketball player" );
int shotsmade = Integer.parseInt( input2 );

double shootingPercentage = (( shotstaken / shotsmade) * 100 );
NumberFormat percentFormat = NumberFormat.getPercentInstance( );

JOptionPane.showMessageDialog( null, "The shooting percentage is " + percentFormat.format( shootingPercentage ) );



}
}