Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. // The "SumDice1b" class.
  2. import java.awt.*;
  3. import hsa.Console;
  4. import usefulstuff.*;
  5.  
  6. public class SumDice1b
  7. {
  8. static Console c; // The output console
  9.  
  10. public static void main (String[] args)
  11. {
  12. c = new Console ();
  13. char key;
  14.  
  15. Dice d1;
  16.  
  17. d1 = new Dice (225, 200, 200, 1, Color.green);
  18.  
  19. int total;
  20. total = 0;
  21. c.println ("Instructions:");
  22. c.println ("hit anykey to roll the dice and for the sum to be added");
  23. c.println ("hit q to see the sum and quit the program");
  24. do
  25. {
  26. d1.roll ();
  27. d1.draw (c);
  28. total = total + d1.getNumber ();
  29. key = c.getChar ();
  30.  
  31. }
  32. while (key != 'q');
  33. int sum;
  34. sum = 0;
  35. c.println ("Enter sum:");
  36. sum = c.readInt ();
  37. while (sum < total || sum > total)
  38. {
  39. if (sum < total || sum > total)
  40. {
  41. c.println ("that is wrong.");
  42. sum = c.readInt ();
  43.  
  44. }
  45. else if (sum == total)
  46. {
  47. c.println ("Right.");
  48. }
  49. }
  50. // Place your program here. 'c' is the output console
  51. } // main method
  52. } // SumDice1a class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement