generated from hummel/Bank-System
Erstellen von C3PO.
parent
f90497c9ad
commit
f5a8cb9424
|
@ -1 +1,2 @@
|
|||
/.DS_Store
|
||||
/bin/
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>RoboterFabrik</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -1,49 +1,85 @@
|
|||
package tpe.exceptions.roboter;
|
||||
|
||||
//import java.util.*;
|
||||
|
||||
import tpe.exceptions.RobotException;
|
||||
import tpe.exceptions.RobotIllegalStateException;
|
||||
import tpe.exceptions.RobotMagicValueException;
|
||||
|
||||
public class C3PO implements Robot{
|
||||
public class C3PO extends Robots{
|
||||
|
||||
RobotType robotType;
|
||||
// private RobotException lastException;
|
||||
// private String name;
|
||||
// private boolean powerSwitch;
|
||||
private int id;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
|
||||
public C3PO(String name, int id) {
|
||||
super(name);
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
robotType = RobotType.C3PO;
|
||||
|
||||
@Override
|
||||
public String speak(int[] zahlen) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] think(int[] zahlen) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public String speak(int[] zahlen) throws RobotException {
|
||||
|
||||
for (int i = 0; i < zahlen.length; i++) {
|
||||
sb.append(zahlen[i]);
|
||||
if (i < zahlen.length - 1) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
|
||||
String output = sb.toString();
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] think(int[] zahlen) throws RobotIllegalStateException, RobotMagicValueException {
|
||||
if(!isPowerOn())
|
||||
{
|
||||
throw new RobotIllegalStateException("Der Roboter ist ausgeschaltet!", this.getName());
|
||||
}
|
||||
else if(checkRobotMagicValueException(zahlen)==true)
|
||||
{
|
||||
throw new RobotMagicValueException("Zahl 42 kann nicht verarbeitet werden!",this.getName());
|
||||
}
|
||||
else {
|
||||
int z;
|
||||
|
||||
for (int i = 1; i < zahlen.length; i++) {
|
||||
z = zahlen[i];
|
||||
int k = i;
|
||||
/**
|
||||
* hier wird die Zahl solange nach links getauscht bis die Zahl links nicht mehr kleiner
|
||||
* ist als die Zahl rechts, oder die Zahl ganz links ist.
|
||||
*/
|
||||
while (k > 0 && zahlen[k - 1] < z) {
|
||||
zahlen[k] = zahlen[k - 1];
|
||||
k--;
|
||||
}
|
||||
zahlen[k] = z;
|
||||
}
|
||||
}
|
||||
|
||||
return zahlen;
|
||||
}
|
||||
|
||||
|
||||
public RobotType getRobotType() {
|
||||
return this.robotType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void triggerPowerSwitch() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPowerOn() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RobotException getLastException() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue