Advertisement
Guest User

Clock

a guest
Apr 25th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Clock {
  4. Scanner keyboard = new Scanner(System.in);
  5. private String color;
  6. private String shape;
  7. private int hours;
  8. private int minutes;
  9. private int seconds;
  10.  
  11. public Clock() {
  12. color = "No color yet";
  13. }
  14.  
  15. public int getHours() {
  16. return hours;
  17. }
  18.  
  19. public void setHours(int hours) {
  20. this.hours = hours;
  21. }
  22.  
  23. public int getMinutes() {
  24. return minutes;
  25. }
  26.  
  27. public void setMinutes(int minutes) {
  28. this.minutes = minutes;
  29. }
  30.  
  31. public int getSeconds() {
  32. return seconds;
  33. }
  34.  
  35. public void setSeconds(int seconds) {
  36. this.seconds = seconds;
  37. }
  38.  
  39. public String getColor() {
  40. return color;
  41. }
  42.  
  43. public void setColor(String color) {
  44. this.color = color;
  45. }
  46.  
  47. public void readInput() {
  48. String type;
  49. System.out.println("Clock, Alarm Clock, or Sound Clock?");
  50. type = keyboard.nextLine();
  51.  
  52.  
  53. System.out.println("Enter the color: ");
  54. color = keyboard.nextLine();
  55.  
  56. System.out.println("Enter the hour: ");
  57. hours = keyboard.nextInt();
  58. while (hours > 12 || hours < 1) {
  59. System.out.println("Enter a valid hour: ");
  60. hours = keyboard.nextInt();
  61. }
  62.  
  63. System.out.println("Enter the minutes: ");
  64. minutes = keyboard.nextInt();
  65. while (minutes > 60 || minutes < 1) {
  66. System.out.println("Enter a valid number of minutes: ");
  67. minutes = keyboard.nextInt();
  68. }
  69.  
  70. System.out.println("Enter the seconds: ");
  71. seconds = keyboard.nextInt();
  72. while (seconds > 60 || seconds < 1) {
  73. System.out.println("Enter a valid number of seconds: ");
  74. seconds = keyboard.nextInt();
  75. }
  76. }
  77.  
  78. public void writeOutput() {
  79. System.out.println(color);
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement