Advertisement
Ewerlost

Lab1_Java

Sep 23rd, 2023 (edited)
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1. package com.company;
  2. import java.text.NumberFormat;
  3. import java.util.Scanner;
  4. public class Main {
  5.     public static void main(String[] args) {
  6.         char Gen = 0;
  7.         int Age = 0, ReAge = 0;
  8.         boolean isNotCorrect = true;
  9.         Scanner scan = new Scanner( System.in );
  10.         System.out.println( "This program will find the recommended age for marriage" );
  11.         System.out.println( "Man or Woman ? ENTER M if you are a man or W if you are a woman and your age." );
  12.         do {
  13.             try {
  14.                 Gen = scan.next().charAt(0);
  15.                 Age = scan.nextInt();
  16.                 if ((Gen != 'M' && Gen != 'W') && (Age < 16 || Age > 100)) {
  17.                     System.out.println("Enter existing gender");
  18.                     System.out.println("Enter acceptable age(16-100)");
  19.                 }
  20.                 else if (Gen != 'M' && Gen != 'W') {
  21.                     System.out.println("Enter existing gender");
  22.                 }
  23.                 else {
  24.                     isNotCorrect = false;
  25.                     if (Age < 16 || Age > 100) {
  26.                         System.out.println("Enter acceptable age(16-100)");
  27.                         isNotCorrect = true;
  28.                     }
  29.                     else {
  30.                         isNotCorrect = false;
  31.                     }
  32.                   }
  33.                 } catch(Exception err ){
  34.                     System.out.print("Data entered incorrectly, please re-enter");
  35.                     scan.nextLine();
  36.                 }
  37.  
  38.         }while ( isNotCorrect );
  39.         if ( Gen == 'M' )
  40.             ReAge = Age / 2 + 7;
  41.         else
  42.             ReAge = Age * 2 - 14;
  43.         System.out.print( "Recommended age of a candidate for marriage : " + ReAge);
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement