Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package feladat42;
- import java.util.Scanner;
- /**
- *
- * @author Rendszergazdai
- */
- public class Feladat42 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int evszam = 0, honap = 0, nap = 0;
- while(true){
- System.out.println("Évszám:");
- evszam = scan.nextInt();
- try{
- evBeker(evszam);
- break;
- }
- catch(evszamException e){
- System.out.println(e);
- }
- }
- while(true){
- System.out.println("Hónap:");
- honap = scan.nextInt();
- try{
- honapBeker(honap);
- break;
- }
- catch(honapException e){
- System.out.println(e);
- }
- }
- while(true){
- System.out.println("Nap:");
- nap = scan.nextInt();
- try{
- napBeker(honap, nap);
- break;
- }
- catch(napException e){
- System.out.println(e);
- }
- }
- }
- public static int evBeker(int evszam) throws evszamException{
- if(evszam >= 1900 && evszam <= 2017){
- System.out.println("helyes évszám");
- return evszam;
- }else{
- throw new evszamException("Helytelen évszám");
- }
- }
- public static int honapBeker(int honap) throws honapException{
- if(honap >= 1 && honap <= 12){
- System.out.println("helyes honap");
- return honap;
- }else{
- throw new honapException("Helytelen hónap");
- }
- }
- public static int napBeker(int honap, int nap) throws napException{
- int[] honapHossz = {31,28,31,30,31,30,31,31,30,31,30,31};
- if(honapHossz[honap-1] >= nap && 1 <= nap){
- System.out.println("Helyes nap");
- return nap;
- }else{
- throw new napException("Helytelen nap.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement