Initial Commit
This commit is contained in:
commit
f813982be2
161
src/model/Bungalow.java
Normal file
161
src/model/Bungalow.java
Normal file
@ -0,0 +1,161 @@
|
||||
package model;
|
||||
import java.io.Serializable;
|
||||
import java.util.Comparator;
|
||||
|
||||
public abstract class Bungalow implements Comparable <Bungalow>, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int nummer;
|
||||
private boolean frei;
|
||||
private double grundpreis;
|
||||
|
||||
public Bungalow(double grundpreis, int nummer) throws ResortException
|
||||
{
|
||||
setGrundpreis(grundpreis);
|
||||
setNummer(nummer);
|
||||
setFrei(true);
|
||||
}
|
||||
public Bungalow()
|
||||
{
|
||||
|
||||
}
|
||||
// ------------------------------ getter ------------
|
||||
public boolean isFrei()
|
||||
{
|
||||
return frei;
|
||||
}
|
||||
public double getGrundpreis()
|
||||
{
|
||||
return grundpreis;
|
||||
}
|
||||
public int getNummer()
|
||||
{
|
||||
return nummer;
|
||||
}
|
||||
// ------------------------------ setter ------------
|
||||
public void setFrei(boolean frei)
|
||||
{
|
||||
this.frei = frei;
|
||||
}
|
||||
public void setGrundpreis(double grundpreis) throws ResortException
|
||||
{
|
||||
if (grundpreis >= 25. && grundpreis <= 500.)
|
||||
this.grundpreis = grundpreis;
|
||||
else
|
||||
throw new ResortException("Falscher Parameterwert fuer Grundpreis (" +
|
||||
grundpreis + ") bei setGrundpreis !!");
|
||||
}
|
||||
public void setNummer(int nummer) throws ResortException
|
||||
{
|
||||
if ( (nummer/100) >= 1 && (nummer/100) <= 7 &&
|
||||
nummer - (nummer/100)*100 >= 1 && nummer - (nummer/100)*100 <= 25 )
|
||||
this.nummer = nummer;
|
||||
else
|
||||
throw new ResortException("Falscher Parameterwert fuer Nummer (" +
|
||||
nummer + ") bei setNummer !!");
|
||||
}
|
||||
// ------------------------------ others ------------
|
||||
|
||||
public abstract double berechneTagesertrag();
|
||||
|
||||
public void erhoeheGrundpreis(int proz) throws ResortException
|
||||
{
|
||||
if (proz > 0)
|
||||
{
|
||||
grundpreis *= 1.0 + proz/100.0;
|
||||
}
|
||||
else
|
||||
throw new ResortException("Falscher Parameterwert fuer proz (" +
|
||||
proz + ") bei erhoeheGrundpreis !!");
|
||||
}
|
||||
|
||||
// ------------------------------- Comparatoren ----------------------
|
||||
// public static class NummernComparator implements Comparator<Bungalow>
|
||||
// {
|
||||
// public int compare(Bungalow b1, Bungalow b2)
|
||||
// {
|
||||
// return b1.getNummer()-b2.getNummer();
|
||||
// }
|
||||
// }
|
||||
public static class PreisComparator implements Comparator<Bungalow>
|
||||
{
|
||||
public int compare(Bungalow b1, Bungalow b2)
|
||||
{
|
||||
return Double.compare(b1.getGrundpreis(), b2.getGrundpreis());
|
||||
}
|
||||
}
|
||||
public static class ErtragsComparator implements Comparator<Bungalow>
|
||||
{
|
||||
public int compare(Bungalow b1, Bungalow b2)
|
||||
{
|
||||
return Double.compare(b1.berechneTagesertrag(), b2.berechneTagesertrag());
|
||||
}
|
||||
}
|
||||
|
||||
public int compareTo(Bungalow b) {
|
||||
if (b != null)
|
||||
return nummer - b.nummer;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
// public int compareTo(Bungalow b) {
|
||||
// if (b != null)
|
||||
// {
|
||||
// double diff = grundpreis - b.getGrundpreis();
|
||||
// if (diff > 0)
|
||||
// return 1;
|
||||
// else
|
||||
// if (diff < 0)
|
||||
// return -1;
|
||||
// else
|
||||
// return 0;
|
||||
// }
|
||||
// else
|
||||
// return 1;
|
||||
//
|
||||
|
||||
// ------------------------- equals / hasCode ----------------
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (frei ? 1231 : 1237);
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(grundpreis);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
result = prime * result + nummer;
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Bungalow other = (Bungalow) obj;
|
||||
if (frei != other.frei)
|
||||
return false;
|
||||
if (Double.doubleToLongBits(grundpreis) != Double.doubleToLongBits(other.grundpreis))
|
||||
return false;
|
||||
if (nummer != other.nummer)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
// ------------------------------ toString -------------------
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(" # ").append(nummer).append(" / Grundpreis pro Person: EUR ").
|
||||
append(grundpreis).append(" -> ");
|
||||
if (frei)
|
||||
sb.append("frei");
|
||||
else
|
||||
sb.append("belegt");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
196
src/model/BungalowResort.java
Normal file
196
src/model/BungalowResort.java
Normal file
@ -0,0 +1,196 @@
|
||||
package model;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class BungalowResort {
|
||||
private String name;
|
||||
private LinkedList<Bungalow> bungalows;
|
||||
|
||||
public BungalowResort(String name) throws ResortException {
|
||||
setName(name);
|
||||
bungalows = new LinkedList<Bungalow>();
|
||||
}
|
||||
|
||||
// ----------------------------------- getter ------------------------
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
// ----------------------------------- setter ------------------------
|
||||
public void setName(String name) throws ResortException {
|
||||
if (name != null)
|
||||
this.name = name;
|
||||
else
|
||||
throw new ResortException("Null-Referenz fuer BungalowResort.setName!");
|
||||
}
|
||||
|
||||
// ----------------------------------- others ------------------------
|
||||
public void addBungalow(Bungalow bungalow) throws ResortException {
|
||||
if (bungalow != null)
|
||||
if (bungalows.size() < 100)
|
||||
if (!bungalows.contains(bungalow))
|
||||
bungalows.add(bungalow);
|
||||
else
|
||||
throw new ResortException("Dieser Bungalow steht bereits in der Anlage!!");
|
||||
else
|
||||
throw new ResortException("Es stehen bereits 100 Bungalows in der Anlage!!");
|
||||
else
|
||||
throw new ResortException("Null-Referenz fuer BungalowResort.addBungalow!");
|
||||
}
|
||||
|
||||
public double berechneTagesertrag() {
|
||||
double ertrag = 0.;
|
||||
for (Bungalow b : bungalows)
|
||||
ertrag += b.berechneTagesertrag();
|
||||
return ertrag;
|
||||
}
|
||||
|
||||
public int berechneAnzBettenBelegt() {
|
||||
int anz = 0;
|
||||
for (Bungalow b : bungalows) {
|
||||
if (b instanceof WohnBungalow)
|
||||
if (!b.isFrei())
|
||||
anz += ((WohnBungalow) b).getBetten();
|
||||
}
|
||||
return anz;
|
||||
}
|
||||
|
||||
public void removeBungalow(int pos) throws ResortException {
|
||||
if (pos >= 0 && pos < bungalows.size()) {
|
||||
bungalows.remove(pos);
|
||||
} else
|
||||
throw new ResortException("Falsche pos (" + pos + ") bei remove(pos)!!");
|
||||
}
|
||||
|
||||
public int removeBungalows(double preis) {
|
||||
int anz = 0;
|
||||
Iterator<Bungalow> it = bungalows.iterator();
|
||||
while (it.hasNext()) {
|
||||
if (it.next().getGrundpreis() < preis) {
|
||||
it.remove();
|
||||
anz++;
|
||||
}
|
||||
}
|
||||
return anz;
|
||||
}
|
||||
|
||||
public void sortBungalowsNummer() {
|
||||
// Collections.sort(bungalows, new Bungalow.NummernComparator());
|
||||
Collections.sort(bungalows);
|
||||
}
|
||||
|
||||
public void sortBungalowsTagesertrag() {
|
||||
Collections.sort(bungalows, new Bungalow.ErtragsComparator());
|
||||
Collections.reverse(bungalows);
|
||||
}
|
||||
|
||||
public void sortBungalowsPreis() {
|
||||
Collections.sort(bungalows, new Bungalow.PreisComparator());
|
||||
}
|
||||
|
||||
// ------------------------------------- Dateien ------------------------------
|
||||
public void saveBungalows(String filename) throws ResortException {
|
||||
if (filename != null) {
|
||||
try (FileOutputStream fos = new FileOutputStream(filename);
|
||||
ObjectOutputStream oos = new ObjectOutputStream(fos);) {
|
||||
oos.writeObject(bungalows);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new ResortException(
|
||||
"Datei-Fehler bei BungalowResort.saveBungalows(" + filename + ") !\n" + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
throw new ResortException("Eingabe-/Ausgabe-Fehler bei BungalowResort.saveBungalows(" + filename
|
||||
+ ") !\n" + e.getMessage());
|
||||
}
|
||||
} else
|
||||
throw new ResortException("Null-Referenz fuer BungalowResort.saveBungalows");
|
||||
}
|
||||
|
||||
public void loadBungalows(String filename) throws ResortException {
|
||||
if (filename != null) {
|
||||
List<?> tmpBungalows;
|
||||
try (FileInputStream fis = new FileInputStream(filename);
|
||||
ObjectInputStream ois = new ObjectInputStream(fis);) {
|
||||
// bungalows.addAll( (LinkedList<Bungalow>) ois.readObject() ); // mit Warning
|
||||
|
||||
tmpBungalows = (List<?>) ois.readObject();
|
||||
for (Object o : tmpBungalows) {
|
||||
if (o instanceof Bungalow) {
|
||||
addBungalow((Bungalow) o);
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new ResortException(
|
||||
"Datei-Fehler bei BungalowResort.loadBungalows(" + filename + ") !\n" + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
throw new ResortException("Eingabe-/Ausgabe-Fehler bei BungalowResort.loadBungalows(" + filename
|
||||
+ ") !\n" + e.getMessage());
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new ResortException(
|
||||
"Klassen-Fehler bei BungalowResort.loadBungalows(" + filename + ") !\n" + e.getMessage());
|
||||
}
|
||||
} else
|
||||
throw new ResortException("Null-Referenz fuer BungalowResort.loadBungalows");
|
||||
}
|
||||
|
||||
public void exportWohnBungalows(String filename) throws ResortException {
|
||||
if (filename != null) {
|
||||
try (BufferedWriter bw = new BufferedWriter(new FileWriter(filename));) {
|
||||
bw.write(toStringCsv());
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new ResortException(
|
||||
"Datei-Fehler bei BungalowResort.exportWohnBungalows(" + filename + ") !\n" + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
throw new ResortException("Eingabe-/Ausgabe-Fehler bei BungalowResort.exportWohnBungalows(" + filename
|
||||
+ ") !\n" + e.getMessage());
|
||||
}
|
||||
} else
|
||||
throw new ResortException("Null-Referenz fuer BungalowResort.exportWohnBungalows");
|
||||
|
||||
}
|
||||
|
||||
public void importWohnBungalows(String filename) throws ResortException {
|
||||
if (filename != null) {
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(filename));) {
|
||||
String zeile = br.readLine();
|
||||
String[] zeilenTeile;
|
||||
while (zeile != null) {
|
||||
zeilenTeile = zeile.trim().split(";");
|
||||
addBungalow(new WohnBungalow(zeilenTeile));
|
||||
zeile = br.readLine();
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new ResortException(
|
||||
"Datei-Fehler bei BungalowResort.importWohnBungalows(" + filename + ") !\n" + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
throw new ResortException("Eingabe-/Ausgabe-Fehler bei BungalowResort.importWohnBungalows(" + filename
|
||||
+ ") !\n" + e.getMessage());
|
||||
}
|
||||
} else
|
||||
throw new ResortException("Null-Referenz fuer BungalowResort.importWohnBungalows");
|
||||
}
|
||||
|
||||
// ------------------------------- toString --------------------------
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(1000);
|
||||
sb.append("Bungalow-Resort ").append(name).append(" -> derzeit ").append(bungalows.size())
|
||||
.append(" Bungalows\n");
|
||||
Iterator<Bungalow> it = bungalows.iterator();
|
||||
while (it.hasNext()) {
|
||||
sb.append(it.next()).append('\n');
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String toStringCsv() {
|
||||
StringBuilder sb = new StringBuilder(1000);
|
||||
Iterator<Bungalow> it = bungalows.iterator();
|
||||
while (it.hasNext()) {
|
||||
Bungalow b = it.next();
|
||||
if (b instanceof WohnBungalow) {
|
||||
sb.append(((WohnBungalow) b).toStringCsv()).append('\n');
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
94
src/model/EventBungalow.java
Normal file
94
src/model/EventBungalow.java
Normal file
@ -0,0 +1,94 @@
|
||||
package model;
|
||||
|
||||
public class EventBungalow extends Bungalow
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int personen;
|
||||
private char ausstattung;
|
||||
|
||||
public EventBungalow(double grundpreis, int nummer, char ausstattung, int personen) throws ResortException
|
||||
|
||||
{
|
||||
super(grundpreis, nummer);
|
||||
setAusstattung(ausstattung);
|
||||
setPersonen(personen);
|
||||
}
|
||||
//----------------------------------------- getters ------------------------
|
||||
public char getAusstattung()
|
||||
{
|
||||
return ausstattung;
|
||||
}
|
||||
public int getPersonen()
|
||||
{
|
||||
return personen;
|
||||
}
|
||||
//----------------------------------------- setters ------------------------
|
||||
public void setAusstattung(char ausstattung) throws ResortException
|
||||
{
|
||||
if (ausstattung == 'L' || ausstattung == 'S' || ausstattung == 'M' )
|
||||
this.ausstattung = ausstattung;
|
||||
else
|
||||
throw new ResortException("Falscher Parameterwert für Ausstattung (" +
|
||||
ausstattung + ") bei setAusstattung !!");
|
||||
}
|
||||
public void setPersonen(int personen) throws ResortException
|
||||
{
|
||||
if (personen >= 10 && personen <= 100)
|
||||
this.personen = personen;
|
||||
else
|
||||
throw new ResortException("Falscher Parameterwert für Personen (" +
|
||||
personen + ") bei setPersonen !!");
|
||||
}
|
||||
//----------------------------------------- others ------------------------
|
||||
|
||||
public double berechneTagesertrag()
|
||||
{
|
||||
double ertrag = 0.;
|
||||
if ( ! isFrei() )
|
||||
{
|
||||
ertrag = 500. + getGrundpreis()*personen;
|
||||
if (ausstattung == 'S')
|
||||
ertrag += personen*5.;
|
||||
else
|
||||
if (ausstattung == 'M')
|
||||
ertrag += 1000.;
|
||||
return ertrag;
|
||||
}
|
||||
|
||||
return 0d;
|
||||
}
|
||||
|
||||
// ------------------------- equals / hasCode ----------------
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ausstattung;
|
||||
result = prime * result + personen;
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
EventBungalow other = (EventBungalow) obj;
|
||||
if (ausstattung != other.ausstattung)
|
||||
return false;
|
||||
if (personen != other.personen)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
//---------------------------toString ------------------------
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuffer("EventBungalow ").append(super.toString()).
|
||||
append(" / Tagesertrag: EUR ").append(berechneTagesertrag()).toString();
|
||||
}
|
||||
|
||||
}
|
11
src/model/ResortException.java
Normal file
11
src/model/ResortException.java
Normal file
@ -0,0 +1,11 @@
|
||||
package model;
|
||||
|
||||
public class ResortException extends Exception
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ResortException(String text)
|
||||
{
|
||||
super(text);
|
||||
}
|
||||
}
|
178
src/model/WohnBungalow.java
Normal file
178
src/model/WohnBungalow.java
Normal file
@ -0,0 +1,178 @@
|
||||
package model;
|
||||
|
||||
public class WohnBungalow extends Bungalow
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int betten;
|
||||
private boolean meerblick;
|
||||
private int kategorie;
|
||||
|
||||
public WohnBungalow(double grundpreis, int nummer, int betten, int kategorie,
|
||||
boolean meerblick) throws ResortException
|
||||
{
|
||||
super(grundpreis, nummer);
|
||||
setBetten(betten);
|
||||
setMeerblick(meerblick);
|
||||
setKategorie(kategorie);
|
||||
}
|
||||
public WohnBungalow(String zeile) throws ResortException
|
||||
{
|
||||
setAll(zeile);
|
||||
}
|
||||
public WohnBungalow(String[] zeilenTeile) throws ResortException
|
||||
{
|
||||
setAll(zeilenTeile);
|
||||
}
|
||||
//--------------------------------- getters --------------------------------
|
||||
public int getBetten()
|
||||
{
|
||||
return betten;
|
||||
}
|
||||
public int getKategorie()
|
||||
{
|
||||
return kategorie;
|
||||
}
|
||||
public boolean getMeerblick()
|
||||
{
|
||||
return meerblick;
|
||||
}
|
||||
//--------------------------------- setters --------------------------------
|
||||
public void setBetten(int betten) throws ResortException
|
||||
{
|
||||
if (betten >= 2 && betten <= 7)
|
||||
this.betten = betten;
|
||||
else
|
||||
throw new ResortException("Falscher Parameterwert für Betten (" +
|
||||
betten + ") bei setBetten !!");
|
||||
}
|
||||
public void setKategorie(int kategorie) throws ResortException
|
||||
{
|
||||
if (kategorie >= 1 && kategorie <= 5)
|
||||
this.kategorie = kategorie;
|
||||
else
|
||||
throw new ResortException("Falscher Parameterwert für Kategorie (" +
|
||||
kategorie + ") bei setKategorie !!");
|
||||
}
|
||||
public void setMeerblick(boolean meerblick)
|
||||
{
|
||||
this.meerblick = meerblick;
|
||||
}
|
||||
private void setAll(String zeile) throws ResortException
|
||||
{
|
||||
try
|
||||
{
|
||||
setNummer( Integer.parseInt(zeile.substring(0, 3).trim() ) );
|
||||
setBetten( Integer.parseInt(zeile.substring(4, 5) ) );
|
||||
setMeerblick( zeile.charAt(6) == 't'?true:false);
|
||||
setKategorie( Integer.parseInt(zeile.substring(8, 9)));
|
||||
setGrundpreis( Double.parseDouble(zeile.substring(10,13).trim() ) );
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
throw new ResortException("Parse-Fehler beim Einlesen einer Bungalow-Zeile ("+zeile+") !!");
|
||||
}
|
||||
catch (IndexOutOfBoundsException iobe)
|
||||
{
|
||||
throw new ResortException("Index-Fehler beim Einlesen einer Bungalow-Zeile ("+zeile+") !!");
|
||||
}
|
||||
}
|
||||
private void setAll(String[] zeilenTeile) throws ResortException
|
||||
{
|
||||
if (zeilenTeile != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
// WohnBungalow;125; 6;false;1; 200.0
|
||||
// [1] [2] [3] [4] [5]
|
||||
setNummer( Integer.parseInt(zeilenTeile[1].trim() ) );
|
||||
setBetten( Integer.parseInt(zeilenTeile[2].trim() ) );
|
||||
setMeerblick( zeilenTeile[3].trim().equals("true")?true:false);
|
||||
setKategorie( Integer.parseInt(zeilenTeile[4].trim() ) );
|
||||
setGrundpreis( Double.parseDouble(zeilenTeile[5].trim() ) );
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
throw new ResortException("Parse-Fehler beim Einlesen einer Bungalow-Zeile !!");
|
||||
}
|
||||
catch (IndexOutOfBoundsException iobe)
|
||||
{
|
||||
throw new ResortException("Index-Fehler beim Einlesen einer Bungalow-Zeile !!");
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new ResortException("Fehler bei setAll(): null-Referenz fuer zeilenTeile erhalten");
|
||||
}
|
||||
//--------------------------------- others --------------------------------
|
||||
|
||||
public double berechneTagesertrag()
|
||||
{
|
||||
double ertrag = 0.;
|
||||
if ( ! isFrei() )
|
||||
{
|
||||
ertrag = getGrundpreis()*betten;
|
||||
if (betten == 2)
|
||||
ertrag += 50d;
|
||||
else
|
||||
if (betten == 7)
|
||||
ertrag -= getGrundpreis()/2;
|
||||
if (getMeerblick())
|
||||
ertrag *= 1.25;
|
||||
switch (kategorie)
|
||||
{
|
||||
case 1: ertrag *= .75; break;
|
||||
case 3: ertrag *= 1.15; break;
|
||||
case 4: ertrag *= 1.25; break;
|
||||
case 5: ertrag *= 1.5; break;
|
||||
}
|
||||
}
|
||||
return ertrag;
|
||||
}
|
||||
|
||||
// ------------------------- equals / hasCode ----------------
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + betten;
|
||||
result = prime * result + kategorie;
|
||||
result = prime * result + (meerblick ? 1231 : 1237);
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
WohnBungalow other = (WohnBungalow) obj;
|
||||
if (betten != other.betten)
|
||||
return false;
|
||||
if (kategorie != other.kategorie)
|
||||
return false;
|
||||
if (meerblick != other.meerblick)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------ toString -----------------------------
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return new StringBuffer("WohnBungalow ").append(super.toString()).
|
||||
append(" / Tagesertrag: EUR ").append(berechneTagesertrag()).toString();
|
||||
}
|
||||
|
||||
|
||||
public String toStringCsv()
|
||||
{
|
||||
String sep = ";";
|
||||
StringBuilder sb = new StringBuilder(100);
|
||||
sb.append("WohnBungalow").append(sep).append(getNummer()).append(sep).append(betten).append(sep).
|
||||
append(getMeerblick()).append(sep).append(kategorie).append(sep).append(getGrundpreis());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
2
src/module-info.java
Normal file
2
src/module-info.java
Normal file
@ -0,0 +1,2 @@
|
||||
module BungalowResort {
|
||||
}
|
44
src/test/TestEventBungalow.java
Normal file
44
src/test/TestEventBungalow.java
Normal file
@ -0,0 +1,44 @@
|
||||
package test;
|
||||
import model.EventBungalow;
|
||||
import model.ResortException;
|
||||
|
||||
public class TestEventBungalow
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
// ------------------------------ falsch -------------------------------
|
||||
try
|
||||
{
|
||||
// EventBungalow eb1 = new EventBungalow (50., 701,'X',50); // Fehler ausstattung X
|
||||
// EventBungalow eb2 = new EventBungalow (50., 701,'L',5); // Fehler personen 5
|
||||
// EventBungalow eb3 = new EventBungalow (50., 701,'M',500); // Fehler personen 500
|
||||
|
||||
// ------------------------------ korrekt -------------------------------
|
||||
EventBungalow eb4 = new EventBungalow (200., 701,'L',10); // 2500.-
|
||||
eb4.setFrei(false);
|
||||
System.out.println(eb4);
|
||||
System.out.println(eb4.berechneTagesertrag());
|
||||
|
||||
EventBungalow eb5 = new EventBungalow (100., 702,'S',100);// 11000.-
|
||||
eb5.setFrei(false);
|
||||
System.out.println("\n"+eb5);
|
||||
System.out.println(eb5.berechneTagesertrag());
|
||||
|
||||
EventBungalow eb6 = new EventBungalow (100., 703,'M',50);// 6500.-
|
||||
eb6.setFrei(false);
|
||||
System.out.println("\n"+eb6);
|
||||
System.out.println(eb6.berechneTagesertrag());
|
||||
|
||||
EventBungalow eb7 = new EventBungalow (100., 703,'M',50);// 0.-
|
||||
eb6.setFrei(true);
|
||||
System.out.println("\n"+eb7);
|
||||
System.out.println(eb7.berechneTagesertrag());
|
||||
}
|
||||
catch (ResortException e)
|
||||
{
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
32
src/test/TestImport.java
Normal file
32
src/test/TestImport.java
Normal file
@ -0,0 +1,32 @@
|
||||
package test;
|
||||
import model.BungalowResort;
|
||||
import model.EventBungalow;
|
||||
import model.ResortException;
|
||||
|
||||
public class TestImport
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
BungalowResort br = new BungalowResort("New Resort");
|
||||
EventBungalow eb0 = new EventBungalow (500., 222,'L',10); // 2500.-
|
||||
br.addBungalow(eb0);
|
||||
System.out.println(br); // 1 EventBungalow
|
||||
// br.importWohnBungalows(null);
|
||||
// br.importWohnBungalows("x:\\scratch\\wohnBungalows.csv");
|
||||
br.importWohnBungalows("c:\\scratch\\wohnBungalows.csv");
|
||||
System.out.println(".... import ok....\n");
|
||||
System.out.println(br); // 1 EventBungalow, 2 WohnBungalows
|
||||
|
||||
br.importWohnBungalows("c:\\scratch\\wohnBungalows.csv"); // Fehler Bungalow steht in der Anlage
|
||||
System.out.println(".... import ok....\n");
|
||||
System.out.println(br);
|
||||
}
|
||||
catch (ResortException e)
|
||||
{
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
34
src/test/TestLoad.java
Normal file
34
src/test/TestLoad.java
Normal file
@ -0,0 +1,34 @@
|
||||
package test;
|
||||
import model.BungalowResort;
|
||||
import model.EventBungalow;
|
||||
import model.ResortException;
|
||||
|
||||
public class TestLoad
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
BungalowResort br = new BungalowResort("New Resort");
|
||||
EventBungalow eb0 = new EventBungalow (500., 222,'L',10); // 2500.-
|
||||
br.addBungalow(eb0);
|
||||
System.out.println(br); // 1 Bungalow
|
||||
System.out.println();
|
||||
|
||||
// br.loadBungalows(null);
|
||||
// br.loadBungalows("x:\\scratch\\bungalows.ser");
|
||||
br.loadBungalows("c:\\scratch\\bungalows.ser");
|
||||
System.out.println(".... load ok....\n");
|
||||
System.out.println(br); // 2 Bungalows
|
||||
|
||||
br.loadBungalows("c:\\scratch\\bungalows.ser"); // Fehler Bungalow steht in der Anlage
|
||||
System.out.println(".... load ok....\n");
|
||||
System.out.println(br);
|
||||
}
|
||||
catch (ResortException e)
|
||||
{
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
110
src/test/TestResort.java
Normal file
110
src/test/TestResort.java
Normal file
@ -0,0 +1,110 @@
|
||||
package test;
|
||||
import model.BungalowResort;
|
||||
import model.EventBungalow;
|
||||
import model.ResortException;
|
||||
import model.WohnBungalow;
|
||||
|
||||
public class TestResort
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
BungalowResort br;
|
||||
// br = new BungalowResort(null);
|
||||
br = new BungalowResort("Le Resort");
|
||||
|
||||
WohnBungalow wb10 = new WohnBungalow (100.,123,4,2,false); // 400.-
|
||||
wb10.setFrei(false);
|
||||
WohnBungalow wb11 = new WohnBungalow (50.,125,2,5,true); // 281.25
|
||||
wb11.setFrei(false);
|
||||
|
||||
EventBungalow eb4 = new EventBungalow (200., 701,'L',10); // 2500.-
|
||||
eb4.setFrei(false);
|
||||
EventBungalow eb5 = new EventBungalow (100., 702,'S',100);// 11000.-
|
||||
eb5.setFrei(false);
|
||||
EventBungalow eb6 = new EventBungalow (100., 703,'M',50);// 6500.-
|
||||
eb6.setFrei(false);
|
||||
|
||||
// br.addBungalow(null);
|
||||
// for (int i = 0; i < 101; i++)
|
||||
// br.addBungalow( new EventBungalow (100., 703,'M',50) );
|
||||
// br.addBungalow(eb4);
|
||||
br.addBungalow(eb4);
|
||||
br.addBungalow(wb11);
|
||||
br.addBungalow(eb6);
|
||||
br.addBungalow(wb10);
|
||||
br.addBungalow(eb5);
|
||||
System.out.println(br);
|
||||
|
||||
System.out.println("Sortiere Nummer: ");
|
||||
br.sortBungalowsNummer();
|
||||
System.out.println(br);
|
||||
|
||||
System.out.println("Sortiere Tagesertrag: ");
|
||||
br.sortBungalowsTagesertrag();
|
||||
System.out.println(br);
|
||||
|
||||
System.out.println("Sortiere Preis: ");
|
||||
br.sortBungalowsPreis();
|
||||
System.out.println(br);
|
||||
|
||||
System.out.println("Tagesertrag:" +br.berechneTagesertrag()); // 20681.25
|
||||
System.out.println("Betten:" +br.berechneAnzBettenBelegt()); // 6
|
||||
wb10.setFrei(true);
|
||||
System.out.println("Betten:" +br.berechneAnzBettenBelegt()); // 2
|
||||
// br.removeBungalow(-1);
|
||||
// br.removeBungalow(5);
|
||||
br.removeBungalow(1);
|
||||
System.out.print("Remove 1\n"+br);
|
||||
|
||||
System.out.print("Remove 24.: -> ");
|
||||
System.out.println(br.removeBungalows(24.)); // 0
|
||||
System.out.println(br);
|
||||
System.out.print("Remove 150.: -> ");
|
||||
System.out.println(br.removeBungalows(150.)); // 3
|
||||
System.out.println(br);
|
||||
|
||||
// Testfaelle fuer erhoeheGrundpreis
|
||||
//EventBungalow eb4 = new EventBungalow (200., 701,'L',10); // 2500.-
|
||||
System.out.println(eb4); // 200.0
|
||||
// eb4.erhoeheGrundpreis(0); // Fehler 0
|
||||
eb4.erhoeheGrundpreis(100); // 100 Prozent
|
||||
System.out.println(eb4); // 400.0
|
||||
eb4.erhoeheGrundpreis(200); // 200 Prozent
|
||||
System.out.println(eb4); // 1200.0
|
||||
eb4.erhoeheGrundpreis(10); // 10 Prozent
|
||||
System.out.println(eb4); // 1320.0
|
||||
eb4.erhoeheGrundpreis(1); // 1 Prozent
|
||||
System.out.println(eb4); // 1333.2
|
||||
|
||||
System.out.println();
|
||||
System.out.println(br); // 1 EventBungalow
|
||||
// br.saveBungalows(null);
|
||||
// br.saveBungalows("x:\\scratch\\bungalows.ser");
|
||||
br.saveBungalows("c:\\scratch\\bungalows.ser");
|
||||
System.out.println(".... save ok....\n");
|
||||
|
||||
// System.out.println();
|
||||
// System.out.println(br);
|
||||
//// br.exportWohnBungalows(null);
|
||||
//// br.exportWohnBungalows("x:\\scratch\\wohnBungalows.csv");
|
||||
// br.exportWohnBungalows("c:\\scratch\\wohnBungalows.csv"); // leer, keine Wohnbungalows
|
||||
// System.out.println(".... export ok....\n");
|
||||
|
||||
br.addBungalow(wb11);
|
||||
br.addBungalow(wb10);
|
||||
|
||||
System.out.println();
|
||||
System.out.println(br); // 1 EventBungalow, 2 WohnBungalows
|
||||
br.exportWohnBungalows("c:\\scratch\\wohnBungalows.csv"); // 2 WohnBungalows
|
||||
System.out.println(".... export ok....\n");
|
||||
|
||||
}
|
||||
catch (ResortException e)
|
||||
{
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
51
src/test/TestWohnBungalow.java
Normal file
51
src/test/TestWohnBungalow.java
Normal file
@ -0,0 +1,51 @@
|
||||
package test;
|
||||
import model.ResortException;
|
||||
import model.WohnBungalow;
|
||||
|
||||
public class TestWohnBungalow
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
// ------------------------------ falsch -------------------------------
|
||||
try
|
||||
{
|
||||
// WohnBungalow wb1 = new WohnBungalow (0., 123,2,5,true); // Fehler grundpreis 0.0
|
||||
// WohnBungalow wb2 = new WohnBungalow (1000., 123,2,5,true); // Fehler grundpreis 1000.0
|
||||
// WohnBungalow wb3 = new WohnBungalow (50., 23,2,5,true); // Fehler nummer 23
|
||||
// WohnBungalow wb4 = new WohnBungalow (50., 923,2,5,true); // Fehler nummer 923
|
||||
// WohnBungalow wb5 = new WohnBungalow (50., 132,2,5,true); // Fehler nummer 132
|
||||
// WohnBungalow wb6 = new WohnBungalow (50., 123,0,5,true); // Fehler betten 0
|
||||
// WohnBungalow wb7 = new WohnBungalow (50., 123,9,5,true); // Fehler betten 9
|
||||
// WohnBungalow wb8 = new WohnBungalow (50., 123,3,0,true); // Fehler kategorie 0
|
||||
// WohnBungalow wb9 = new WohnBungalow (50., 123,3,10,true); // Fehler kategorie 10
|
||||
|
||||
// ------------------------------ korrekt -------------------------------
|
||||
System.out.println( "\n");
|
||||
WohnBungalow wb10 = new WohnBungalow (100.,123,4,2,false); // 400.-
|
||||
System.out.println(wb10);
|
||||
wb10.setFrei(false);
|
||||
System.out.println(wb10.berechneTagesertrag());
|
||||
|
||||
WohnBungalow wb11 = new WohnBungalow (50.,124,2,5,true); // 281.25
|
||||
System.out.println(wb11);
|
||||
wb11.setFrei(false);
|
||||
System.out.println(wb11.berechneTagesertrag());
|
||||
|
||||
WohnBungalow wb12 = new WohnBungalow (200.,125,6,1,false); // 900.-
|
||||
System.out.println(wb12);
|
||||
wb12.setFrei(false);
|
||||
System.out.println(wb12.berechneTagesertrag());
|
||||
|
||||
WohnBungalow wb13 = new WohnBungalow (200.,125,6,1,false); // 0.-
|
||||
System.out.println(wb13);
|
||||
wb12.setFrei(true);
|
||||
System.out.println(wb13.berechneTagesertrag());
|
||||
|
||||
}
|
||||
catch (ResortException e)
|
||||
{
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user