PR2/Exercises/Testat1/Tutor_Aufgaben/Clone/Raumanzug.java

85 lines
1.8 KiB
Java
Raw Normal View History

2024-04-20 14:18:44 +02:00
package Testat1.Tutor_Aufgaben.Clone;
import java.io.Serializable;
/**
* Ein Raumanzug.
*/
public class Raumanzug implements Cloneable, Serializable{
/**
* Sauerstoffvorrat, der noch im Raumanzug ist.
*/
private double sauerstoffVorrat;
/**
* Ertzeugt einen neuen Raumanzug.
*/
public Raumanzug() {
sauerstoffVorrat = Math.random();
}
/**
* Sauerstoffvorrat im Anzug.
*
* @return Vorrat in % (0.0-1.0)
*/
public double getSauerstoffVorrat() {
return sauerstoffVorrat;
}
/**
* Tankt den Anzug auf.
*/
public void auftanken() {
sauerstoffVorrat = 1.0;
}
public void setSauerstoffVorrat(double sauerstoffVorrat) {
this.sauerstoffVorrat = sauerstoffVorrat;
}
/**
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(sauerstoffVorrat);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Raumanzug other = (Raumanzug) obj;
return Double.doubleToLongBits(sauerstoffVorrat)
== Double.doubleToLongBits(other.sauerstoffVorrat);
}
public Raumanzug clone() throws CloneNotSupportedException {
Raumanzug r = (Raumanzug) super.clone();
return r;
}
@Override
public String toString() {
return "Raumanzug [sauerstoffVorrat=" + sauerstoffVorrat + "]";
}
}