Java beginners Assignment Help

Hashio

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



}
}
 
Thread starter Similar threads Forum Replies Date
B Apps General Discussion 23
B Apps General Discussion 2
I Apps General Discussion 2
K Apps General Discussion 3
G Apps General Discussion 14
syssoft Apps General Discussion 1
C Apps General Discussion 9
C Apps General Discussion 6
A Apps General Discussion 8
M Apps General Discussion 4
C Apps General Discussion 1
tomsguideUS Apps General Discussion 3
D Apps General Discussion 4
H Apps General Discussion 3
H Apps General Discussion 8
seperoph Apps General Discussion 3
Moroz Academy Apps General Discussion 0
Moroz Academy Apps General Discussion 0
Moroz Academy Apps General Discussion 0
Moroz Academy Apps General Discussion 0

ASK THE COMMUNITY