The Java Beach Resort has two types of suites Ocean View and

The Java Beach Resort has two types of suites: Ocean View and Street Side. The suites can accommodate either two, 4 people, or more. The rates are higher in summer than in the winter. Write an application that can determine the cost of a suite. Suite charges are in the given table.

Type of suite is specifies as \"Ocean\" or \"Street\" and is case insensitive

The season is \"Summer\" or \"Winter\" and is case insensitive

Write a class Suite. It has a constructor that takes three parameters:

public Suite(String view, String season, int occupants) Note: you should not change the case of the instance variable when initializing

It also has a method:

public double getCost()

The cost is based on the table above. One person costs the same as two people and three people cost the same as 4 people. For more than 4 people, the charge is a flat $200 per person for every room. If view is a String other than \"Ocean\" or \"Street\", charge the rate for \"Ocean\". If the season is anything other than \"Summer\" or \"Winter\", charge the rate for \"Summer.\" Use nested if statements.

Provide Javadoc

--------------------------------------------------------------------------------------------------------------------------------------------

the tester is given :

SuiteTester.java

Ocean Street 2 people 4 people 2 people 4 people Summer $250 $370 $200 5325 Winter $175 $315 150 $210

Solution

Here is the code for above scenario in java

Suite

package demo;

public class Suite {
   private String view;
   private String season;
   private int occupants;
   public Suite(String view, String season, int occupants){
       if(!season.equalsIgnoreCase(\"Summer\") && !season.equalsIgnoreCase(\"Winter\")){
           this.season = \"Summer\";
       }
       else
       this.season = season;
      
       this.view = view;
       this.occupants = occupants;
   }
  
   public double getCost(){
           double result = 0.0;
           if(this.view.equalsIgnoreCase(\"ocean\") && this.season.equalsIgnoreCase(\"Summer\")){
               if(this.occupants > 0 && this.occupants<2){
                   result = 250;
               }
               else if(this.occupants > 2 && this.occupants<4){
                   result = 370;
               }
               else if(this.occupants >4){
                   result = 200 * this.occupants;
               }
           }
           if(this.view.equalsIgnoreCase(\"Street\") && this.season.equalsIgnoreCase(\"Summer\")){
               if(this.occupants > 0 && this.occupants<2){
                   result = 200;
               }
               else if(this.occupants > 2 && this.occupants<4){
                   result = 325;
               }
               else if(this.occupants >4){
                   result = 200 * this.occupants;
               }
           }
           if(this.view.equalsIgnoreCase(\"ocean\") && this.season.equalsIgnoreCase(\"winter\")){
               if(this.occupants > 0 && this.occupants<2){
                   result = 175;
               }
               else if(this.occupants > 2 && this.occupants<4){
                   result = 315;
               }
               else if(this.occupants >4){
                   result = 200 * this.occupants;
               }
           }
           if(this.view.equalsIgnoreCase(\"Street\") && this.season.equalsIgnoreCase(\"winter\")){
               if(this.occupants > 0 && this.occupants<2){
                   result = 150;
               }
               else if(this.occupants > 2 && this.occupants<4){
                   result = 210;
               }
               else if(this.occupants >4){
                   result = 200 * this.occupants;
               }
           }
           return result;
   }
}

The Java Beach Resort has two types of suites: Ocean View and Street Side. The suites can accommodate either two, 4 people, or more. The rates are higher in sum
The Java Beach Resort has two types of suites: Ocean View and Street Side. The suites can accommodate either two, 4 people, or more. The rates are higher in sum

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site