-
Bug Fix of previous solution
import javax.swing.*;
public class ExceptionParser {
public static void main( String[] args ) {
int gross = 0;
String output;
int[] total = new int[11];
while( gross != -1) {
String input = JOptionPane.showInputDialog(null,
" Enter The Gross Sales Amount, -1 to quit" );
if(input==null)
System.exit(-1); //user hit cancel
else if(input.equals("-1"))
gross=-1; //user entered -1 to stop
else if (!input.equals("")) { //user entered a number
gross = Integer.parseInt( input );
//if you divide it by 100, and make it an integer,java will round it
8 //down to the nearest whole number
int temp = gross/100;
//all we have to worry about is numbers over 1000
if(temp>10)
temp=10;
//this is used to increment the position in the array
total[temp]++;
}
}
output = "";
//print out the elements under a 1000
for(int i=0;i<10;i++)
output += "$" + (i*100) + "-" + (i*100+99) + "-----" + total[i]
+ "\n";
//print out the element at a 1000
output += "$1000+-------" + total[10];
JOptionPane.showMessageDialog(null, output,"gross salaries ",
JOptionPane.INFORMATION_MESSAGE );
System.exit( 1 );
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks