Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package feladat42;
  7. import java.util.Scanner;
  8. /**
  9. *
  10. * @author Rendszergazdai
  11. */
  12. public class Feladat42 {
  13.  
  14. /**
  15. * @param args the command line arguments
  16. */
  17. public static void main(String[] args) {
  18. Scanner scan = new Scanner(System.in);
  19. int evszam = 0, honap = 0, nap = 0;
  20. while(true){
  21. System.out.println("Évszám:");
  22. evszam = scan.nextInt();
  23. try{
  24. evBeker(evszam);
  25. break;
  26. }
  27. catch(evszamException e){
  28. System.out.println(e);
  29. }
  30.  
  31. }
  32. while(true){
  33. System.out.println("Hónap:");
  34. honap = scan.nextInt();
  35. try{
  36. honapBeker(honap);
  37. break;
  38. }
  39. catch(honapException e){
  40. System.out.println(e);
  41. }
  42.  
  43. }
  44. while(true){
  45. System.out.println("Nap:");
  46. nap = scan.nextInt();
  47. try{
  48. napBeker(honap, nap);
  49. break;
  50. }
  51. catch(napException e){
  52. System.out.println(e);
  53. }
  54. }
  55. }
  56.  
  57. public static int evBeker(int evszam) throws evszamException{
  58. if(evszam >= 1900 && evszam <= 2017){
  59. System.out.println("helyes évszám");
  60. return evszam;
  61. }else{
  62. throw new evszamException("Helytelen évszám");
  63. }
  64. }
  65.  
  66. public static int honapBeker(int honap) throws honapException{
  67. if(honap >= 1 && honap <= 12){
  68. System.out.println("helyes honap");
  69. return honap;
  70. }else{
  71. throw new honapException("Helytelen hónap");
  72. }
  73. }
  74.  
  75. public static int napBeker(int honap, int nap) throws napException{
  76. int[] honapHossz = {31,28,31,30,31,30,31,31,30,31,30,31};
  77. if(honapHossz[honap-1] >= nap && 1 <= nap){
  78. System.out.println("Helyes nap");
  79. return nap;
  80. }else{
  81. throw new napException("Helytelen nap.");
  82. }
  83.  
  84. }
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement