Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package class170619;
- import java.util.Scanner;
- public class tester01 {
- public static void main(String[] args) {
- /*
- * ברחוב דירות עם 3 עד 5 חדרים, שחלקן הן דופלקסים. תשלומי ועד הבית נקבעו
- * כך: דירת 3 חדרים: 120 ש"ח דירת 4 חדרים: 150 ש"ח דירת 5 חדרים: אם
- * דופלקס: 200 ש"ח אחרת: 180 ש"ח יש להציג את הסכום לתשלום.
- */
- int numberOfRooms; // input: number of rooms in the apartment
- int price; // output: the rent of the apartment
- // create a scanner to get input from the user
- Scanner s = new Scanner(System.in);
- // ask the user to enter the number of rooms
- System.out.println("Enter number of rooms (3, 4 or 5) : ");
- // get and save data from the user
- numberOfRooms = s.nextInt();
- // check the number of rooms
- switch (numberOfRooms) {
- case 3:
- // three rooms in apartment --> price is 120
- price = 120;
- break;
- case 4:
- // four rooms in apartment --> price is 150
- price = 150;
- break;
- case 5:
- // five rooms in apartment
- // should get and check if apartment is duplex
- boolean isDuplex; // input: is the apartment duplex?
- // ask the user to input data
- System.out.println("Is the apartment duplex (true / false) ? ");
- // get and save data from the user
- isDuplex = s.nextBoolean();
- // if duplex then price is 200, else price is 180
- price = isDuplex ? 200 : 180;
- break;
- default:
- // number of rooms is invalid
- System.out.println("Error: Invalid number of rooms ("
- + numberOfRooms + ") !");
- // to indicate an error
- price = 0;
- }
- // if input data was valid and price has been claculated
- if (price > 0) {
- // display the price on the screen for the user
- System.out.println("the price you should pay is : " + price);
- }
- s.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement