Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args)
- {
- Scanner s = new Scanner(System.in);
- int numOfRooms; // variable that will receive number of rooms from user
- char duplex; // variable that will receive if its a duplex or not
- System.out.println(" please enter number of rooms"); // telling the user to enter data
- numOfRooms=s.nextInt(); //receiving data from user
- switch (numOfRooms) { //using switch in order to find the right price to pay
- case 3:
- System.out.println("the amount to pay is: 120 NIS");
- break;
- case 4:
- System.out.println("the amount to pay is 150 NIS");
- break;
- case 5: // the only case that matters if its a duplex
- System.out.println("is your house a duplex? Y/N");
- duplex= s.next().charAt(0);
- if (duplex == 'y' || duplex == 'Y') { //if its a duplex
- System.out.println("the amount to pay is 200 NIS");
- }
- else if (duplex=='n'|| duplex=='N') { // if its not a duplex
- System.out.println("the amount to pay is 180 NIS");
- }
- else{ // in case user entered wrong letter;
- System.out.println("please enter Y or N?");
- }
- break;
- default: // in case user entered wrong nuber of rooms;
- System.out.println("you entered wrong number");
- }//switch
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement