• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need to Print out put to Dialog box

 
mike statham
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I not or dont know how to convert to a dialog box out put print!



I need to print this information to a dialog box

Total number of excuses: 264
The Excuse Water spilled on it had the max numer of excuses
The Excuse A tornado got it had the min numer of excuses

Excuse name # of excuses
My dog ate it 15
It burned 12
I lost it 18
I ate it 23
It fell down the sewer 16
It shredded 44
I forgot it 19
I can't remember 17
Water spilled on it 0
A tornado got it 1
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
at the moment you're using a bunch of System.out.println's to print:

Total number of excuses: 264
The Excuse Water spilled on it had the max numer of excuses
The Excuse A tornado got it had the min numer of excuses

Excuse name # of excuses
My dog ate it 15
It burned 12
I lost it 18
I ate it 23
It fell down the sewer 16
It shredded 44
I forgot it 19
I can't remember 17
Water spilled on it 0
A tornado got it 1


continue with the current program, but try to print all of the above in a single println,
which would mean using a StringBuffer, or StringBuilder to create a single String of the above
so it would be
String message = [will end up as all of the above];
System.out.println(message);

now when it prints out exactly as above, you change
System.out.println(message);
to
javax.swing.JOptionPane.showMessageDialog(null,message);
 
mike statham
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn wrote:at the moment you're using a bunch of System.out.println's to print:

Total number of excuses: 264
The Excuse Water spilled on it had the max numer of excuses
The Excuse A tornado got it had the min numer of excuses

Excuse name # of excuses
My dog ate it 15
It burned 12
I lost it 18
I ate it 23
It fell down the sewer 16
It shredded 44
I forgot it 19
I can't remember 17
Water spilled on it 0
A tornado got it 1


continue with the current program, but try to print all of the above in a single println,
which would mean using a StringBuffer, or StringBuilder to create a single String of the above
so it would be
String message = [will end up as all of the above];
System.out.println(message);

now when it prints out exactly as above, you change
System.out.println(message);
to
javax.swing.JOptionPane.showMessageDialog(null,message);



Ok, I've re wrote my code, but instead of printint in a dialog box like:

Total number of excuses: 264
The Excuse Water spilled on it had the max numer of excuses
The Excuse A tornado got it had the min numer of excuses

Excuse name # of excuses
My dog ate it 15
It burned 12
I lost it 18
I ate it 23
It fell down the sewer 16
It shredded 44
I forgot it 19
I can't remember 17
Water spilled on it 0
A tornado got it 1



it displays in a straight line!



 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don’t know about the output, but I can see lots more, I am afraid.
Why are you not creating an object? You are supposed to be learning object-oriented programming. There ought to be an Excuse object, which can have a text and howOftenUsed fields, which you can put into an array. You can give it a toString() method and use that to print it. You can even create a Comparator<Excuse> class, so you can sort your array (or a copy of it). You can get rid of those many uses of the keyword static.
Your input looks iffy. You are using Scanner#inext and parseInt, as if you didn’t know about the Scanner#nextInt method, and two lines later you are calling nextInt, which will simply remove the next valid input number. I have told somebody else to create a utility class for keyboard input, and that he could write a method in this class which validates ints within a certain range. That might be useful for you. Please search for it.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And why are you resetting nums[i] to 100? That is obviously why the excuse never used comes out as used most frequently. Don’t use parallel arrays like that; they are error-prone.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic