SHARE
TWEET

vaadB

a guest May 24th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args)
  6.     {
  7.         Scanner s = new Scanner(System.in);
  8.      int numOfRooms; // variable that will receive number of rooms from user
  9.      char duplex; // variable that will receive if its a duplex or not
  10.      System.out.println(" please enter number of rooms");  // telling the user to enter data
  11.      numOfRooms=s.nextInt(); //receiving data from user
  12.      switch (numOfRooms) { //using switch in order to find the right price to pay
  13.          case 3:
  14.              System.out.println("the amount to pay is: 120 NIS");
  15.              break;
  16.          case 4:
  17.              System.out.println("the amount to pay is 150 NIS");
  18.              break;
  19.          case 5: // the only case that matters if its a duplex
  20.              System.out.println("is your house a duplex? Y/N");
  21.              duplex= s.next().charAt(0);
  22.              if (duplex == 'y' || duplex == 'Y') { //if its a duplex
  23.                  System.out.println("the amount to pay is 200 NIS");
  24.              }
  25.              else if (duplex=='n'|| duplex=='N') { // if its not a duplex
  26.                  System.out.println("the amount to pay is 180 NIS");
  27.              }
  28.              else{ // in case user entered wrong letter;
  29.                  System.out.println("please enter Y or N?");
  30.              }
  31.              break;
  32.          default: // in case user entered wrong nuber of rooms;
  33.              System.out.println("you entered wrong number");
  34.      }//switch
  35.  
  36.  
  37.     }
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top