Last active
December 14, 2015 05:29
-
-
Save desireesantos/5035362 to your computer and use it in GitHub Desktop.
Java Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.hotel; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
/** | |
* @author desireeSantos | |
* | |
*/ | |
public class Hotel { | |
private String name; | |
private int classification; | |
private double[] pricesHotel; | |
public Hotel(String name, int classification, Double[] priceHotels) { | |
if (isValid(name)) { | |
this.name = name; | |
} else { | |
throw new IllegalArgumentException("Write hotel name. "); | |
} | |
if (isValid(classification)) { | |
this.classification = classification; | |
} else { | |
throw new IllegalArgumentException("Write classification. "); | |
} | |
if (isValid(priceHotels)) { | |
this.classification = classification; | |
} else { | |
throw new IllegalArgumentException("Write prices reservation. "); | |
} | |
} | |
private boolean isValid(String value) { | |
if ((value != null) && !(value.isEmpty())) { | |
return true; | |
} | |
return false; | |
} | |
private boolean isValid(int value) { | |
String string = String.valueOf(value); | |
Pattern parttern = Pattern.compile("^[0-9]"); | |
Matcher match = parttern.matcher(string); | |
while (match.find()) | |
{ | |
return false; | |
} | |
return true; | |
} | |
private boolean isValid(Double[] priceHotels) { | |
if ((priceHotels != null) && !(priceHotels.length == 0)) { | |
return true; | |
} | |
return false; | |
} | |
public String name() { | |
return name; | |
} | |
public int classification() { | |
return classification; | |
} | |
public void name(String name) { | |
this.name = name; | |
} | |
public void classification(int classification) { | |
this.classification = classification; | |
} | |
public double[] getX() { | |
return pricesHotel; | |
} | |
public void setX(double[] pricesHotel) { | |
this.pricesHotel = pricesHotel; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment