Question

In: Computer Science

Lodging in Europe Q1. Write a program to make suggestions on lodging in Europe. If a...

Lodging in Europe

Q1. Write a program to make suggestions on lodging in Europe.

  • If a user wants to spend $30 or less on lodging per night, suggest camping.
  • If a user wants to spend $45 or less but more than $30 per night, suggest youth hostel if the user is 30 years old or younger and adult hostel if the user is older than 30 years old.
  • If a user wants to spend $100 or less but more than $45 per night, suggest hotel.
  • If a user wants to spend $200 or less but more than $100 per night, suggest grant hotel.
  • If a user wants to spend more than $200, suggest exclusive suites. If the country is France, also suggest rooms in palaces.

Note that to compare whether a String variable country equals "France", you cannot use country == "France". The correcr way to compare is country.equals("France").

Q2.

Days of a Month

Given the year and month number, return the number of days in the month.

  • For month 1, 3, 5, 7, 8, 10, 12, return 31.
  • For month 4, 6, 9, 11, return 30.
  • For month 2, if it is leap year, return 29, otherwise return 28.

A year is a leap year if the year number is a multiple of 4 but not a multiple of 100. However, if a year number is a multiple of 400, the year is a leap year.

Solutions

Expert Solution

Since you have not mentioned the language of your preference, I am providing the code in Java.

1)

CODE

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

double spend;

System.out.println("Enter the amount you want to spend on lodging per night: ");

spend = sc.nextDouble();

if (spend <= 30) {

System.out.println("Go to camping");

} else if (spend <= 45) {

System.out.println("Enter your age: ");

int age = sc.nextInt();

if (age <= 30) {

System.out.println("Take youth hostel");

} else {

System.out.println("Take adult hostel");

}

} else if (spend <= 100) {

System.out.println("Hotel");

} else if (spend <= 200) {

System.out.println("Grand hotel");

} else {

System.out.println("Enter the country: ");

String country = sc.nextLine();

if ("France".equalsIgnoreCase(country)) {

System.out.println("Go to palaces");

} else {

System.out.println("Take exclusive suites");

}

}

}

}

2)

CODE

import java.util.Scanner;

public class Main {

public static boolean isLeapYear(int year)

{

// If a year is multiple of 400,

// then it is a leap year

if (year % 400 == 0)

return true;

  

// Else If a year is muliplt of 100,

// then it is not a leap year

if (year % 100 == 0)

return false;

  

// Else If a year is muliplt of 4,

// then it is a leap year

if (year % 4 == 0)

return true;

return false;

}

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("Enter the month: ");

int month = sc.nextInt();

System.out.println("Enter the year: ");

int year = sc.nextInt();

if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {

System.out.println("Number of days = 31");

} else if (month == 4 || month == 6 || month == 9 || month == 11) {

System.out.println("Number of days = 30");

} else {

if (isLeapYear(year)) {

System.out.println("Number of days = 29");

} else {

System.out.println("Number of days = 28");

}

}

}

}


Related Solutions

write a program to make scientific calculator in java
Problem StatementWrite a program that uses the java Math library and implement the functionality of a scientific calculator. Your program should have the following components:1. A main menu listing all the functionality of the calculator.2. Your program should use the switch structure to switch between various options of the calculator. Your Program should also have the provision to handle invalidoption selection by the user.3. Your calculator SHOULD HAVE the following functionalities. You can add any other additional features. PLEASE MAKE...
For the mspfr6989 write program #2 1(b) Write a program that will make LED1 blink 5...
For the mspfr6989 write program #2 1(b) Write a program that will make LED1 blink 5 times when S1 is pressed, and then stop. Program #2 – Using both S1 and S2 1 Write a program like 1(b) above, but the LED1 will blink until S2 is pressed. 2 Write a program that simulates a motor coming up to speed. When S1 is pressed, LED1 blinks at 50% duty cycle for 10 cycles (indicating a motor coming up to speed)....
Can you solve this C program by using Function? Q1. Write a C program to ring...
Can you solve this C program by using Function? Q1. Write a C program to ring the computer bell at any number of times you specify. Use the system clock as a delay, you need to include the time header file.
Q1: Write a Java program that will display different messages depending on your age. Your program...
Q1: Write a Java program that will display different messages depending on your age. Your program should ask the user for his/her name and their age in years and give one or more answers from the following ones below: if the age of the user is less than 16, the program should print on the screen “You are not allowed to drive at the moment”. if the age of the user is less than 18, the program should print on...
Q1: Write a Java program that will display different messages depending on your age. Your program...
Q1: Write a Java program that will display different messages depending on your age. Your program should ask the user for his/her name and their age in years and give one or more answers from the following ones below: if the age of the user is less than 16, the program should print on the screen “You are not allowed to drive at the moment”. if the age of the user is less than 18, the program should print on...
Q1: A. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO EXCHANGE 16-BIT NUMBERS B. WRITE AN ASSEMBLY LANGUAGE...
Q1: A. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO EXCHANGE 16-BIT NUMBERS B. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO SOLVE THE EQUATION Z=A+B-(C/D)+E please write the answer separately part A its own code and part B its own code this is microprocessor the ASSEMBLY LANGUAGE emu8086 should be written like this EX: mov ax,100h mov bx,200h etc
Write a C++ program that attempts to make the Radix Sort more practical: make it sort...
Write a C++ program that attempts to make the Radix Sort more practical: make it sort strings of a maximum length of 15. Have an array of strings. Then in the Radix Sort, create an array of LinkedQueue with 95 queues (95 are the printable characters starting with space). Those queues will be used to separate the data then combine them (i.e. bins). Randomly generate 10,000 strings with lengths from 1 to 15 (during the sort and with strings less...
Write a C++ program that attempts to make the Radix Sort more practical: make it sort...
Write a C++ program that attempts to make the Radix Sort more practical: make it sort strings of a maximum length of 15. Have an array of strings. Then in the Radix Sort, create an array of LinkedQueue with 95 queues (95 are the printable characters starting with space). Those queues will be used to separate the data then combine them (i.e. bins). Randomly generate 10,000 strings with lengths from 1 to 15 (during the sort and with strings less...
Write a program in C++ that will make changes in the list of strings by modifying...
Write a program in C++ that will make changes in the list of strings by modifying its last element. Your program should have two functions: 1. To change the last element in the list in place. That means, without taking the last element from the list and inserting a new element with the new value. 2. To compare, you need also to write a second function that will change the last element in the list by removing it first, and...
Write a program using multiple functions. Make use of an array to store data Make use...
Write a program using multiple functions. Make use of an array to store data Make use of searching techniques Read data from a file Write data to a file Instructions: In this lab, you will be examining a set of stock collected over a twenty four day period. Be sure to make use of an array to store these stocks. You will be required to read in the data points from a file. Write a function to read in the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT