mirror of
https://github.com/13hannes11/archive.git
synced 2024-09-03 21:50:58 +02:00
added all past projects
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
|
||||
<fileset name="all" enabled="true" check-config-name="Programmieren_Assignment06_WS_2015" local="false">
|
||||
<file-match-pattern match-pattern="." include-pattern="true"/>
|
||||
</fileset>
|
||||
</fileset-config>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Assignment6A_EulerApproximation</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>
|
||||
@@ -0,0 +1,11 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
Binary file not shown.
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/bin" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="jdk" jdkName="JavaSE-1.8" jdkType="JavaSDK" />
|
||||
</component>
|
||||
</module>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,72 @@
|
||||
package edu.kit.informatik;
|
||||
|
||||
/**
|
||||
* The Enum Command.
|
||||
*
|
||||
* @author Hannes Kuchelmeister
|
||||
* @version 1.0
|
||||
*/
|
||||
public enum Command {
|
||||
|
||||
/** set command. */
|
||||
SET("set", 1),
|
||||
|
||||
/** quit command. */
|
||||
QUIT("quit", 0),
|
||||
|
||||
/** invalid command. */
|
||||
INVALID("", -1);
|
||||
|
||||
/** The command. */
|
||||
private final String command;
|
||||
|
||||
/** The param count. */
|
||||
private final int paramCount;
|
||||
|
||||
/**
|
||||
* Instantiates a new command.
|
||||
*
|
||||
* @param command
|
||||
* the command
|
||||
* @param paramCount
|
||||
* the param count
|
||||
*/
|
||||
private Command(final String command, final int paramCount) {
|
||||
this.paramCount = paramCount;
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the command.
|
||||
*
|
||||
* @return the command
|
||||
*/
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the param count.
|
||||
*
|
||||
* @return the param count
|
||||
*/
|
||||
public int getParamCount() {
|
||||
return paramCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* converts string to command.
|
||||
*
|
||||
* @param str
|
||||
* the str
|
||||
* @return the command
|
||||
*/
|
||||
public static Command convertToCommand(final String str) {
|
||||
for (final Command command : Command.values()) {
|
||||
if (command.getCommand().equals(str)) {
|
||||
return command;
|
||||
}
|
||||
}
|
||||
return INVALID;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package edu.kit.informatik;
|
||||
|
||||
/**
|
||||
* The Class CommandLineParser.
|
||||
*
|
||||
* @author Hannes Kuchelmeister
|
||||
* @version 1.0
|
||||
*/
|
||||
public class CommandLineParser {
|
||||
private static final String COMMAND_NOT_FOUND = "not valid command. Use: 'set <n>', 'quit'";
|
||||
private static final String WRONG_PARAMETER_COUNT = "the command expects %d parameter";
|
||||
private boolean readyToQuit;
|
||||
|
||||
/**
|
||||
* Instantiates a new command line parser.
|
||||
*/
|
||||
public CommandLineParser() {
|
||||
readyToQuit = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the command line parser
|
||||
*/
|
||||
public void run() {
|
||||
while (!readyToQuit) {
|
||||
runCommand(Terminal.readLine());
|
||||
}
|
||||
}
|
||||
|
||||
private void runCommand(final String command) {
|
||||
if (command == null) {
|
||||
error(COMMAND_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
final String[] arr = command.split("[\\s]");
|
||||
String[] parameters;
|
||||
if (arr.length > 1) {
|
||||
parameters = arr[1].split("[\\,]");
|
||||
} else {
|
||||
parameters = new String[0];
|
||||
}
|
||||
|
||||
switch (Command.convertToCommand(arr[0])) {
|
||||
case QUIT:
|
||||
if (parameters.length != Command.QUIT.getParamCount()) {
|
||||
error(String.format(WRONG_PARAMETER_COUNT, Command.QUIT.getParamCount()));
|
||||
} else {
|
||||
readyToQuit = true;
|
||||
}
|
||||
break;
|
||||
case SET:
|
||||
if (parameters.length != Command.SET.getParamCount()) {
|
||||
error(String.format(WRONG_PARAMETER_COUNT, Command.QUIT.getParamCount()));
|
||||
} else {
|
||||
set(parameters);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
error(COMMAND_NOT_FOUND);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void set(final String[] param) {
|
||||
try {
|
||||
final int n = Integer.parseInt(param[0]);
|
||||
final double rounded = Math.ceil(Eulerapproximator.calcEuler(n) * 1000.0) / 1000.0;
|
||||
Terminal.printLine(Double.toString(rounded));
|
||||
} catch (final NumberFormatException e) {
|
||||
error("set expects <n> where n is a number as parameter");
|
||||
} catch (final IllegalNumberException e) {
|
||||
error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void error(final String str) {
|
||||
Terminal.printLine("Error, " + str);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package edu.kit.informatik;
|
||||
|
||||
/**
|
||||
* The Class Eulerapproximator.
|
||||
*
|
||||
* @author Hannes Kuchelmesiter
|
||||
* @version 1.0
|
||||
*/
|
||||
public final class Eulerapproximator {
|
||||
private static final String NOT_NATURAL = "the number is not a natural number";
|
||||
|
||||
private Eulerapproximator() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates eulers number.
|
||||
*
|
||||
* @param n
|
||||
* the n
|
||||
* @return the double
|
||||
* @throws IllegalNumberException
|
||||
* the illegal number exception
|
||||
*/
|
||||
public static double calcEuler(final int n) throws IllegalNumberException {
|
||||
// Check if n is natural number
|
||||
if (n < 0) {
|
||||
throw new IllegalNumberException(NOT_NATURAL);
|
||||
}
|
||||
|
||||
final double tmp = 1.0 / faculty(n);
|
||||
if (n == 0) {
|
||||
return tmp;
|
||||
} else {
|
||||
return calcEuler(n - 1) + tmp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static double faculty(final int n) {
|
||||
assert n >= 0;
|
||||
if (n == 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return faculty(n - 1) * n;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package edu.kit.informatik;
|
||||
|
||||
/**
|
||||
* The Class IllegalNumberException.
|
||||
*
|
||||
* @author Hannes Kuchelmeister
|
||||
* @version 1.0
|
||||
*/
|
||||
public class IllegalNumberException extends Exception {
|
||||
|
||||
/**
|
||||
* Instantiates a new illegal number exception.
|
||||
*/
|
||||
public IllegalNumberException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new illegal number exception.
|
||||
*
|
||||
* @param message
|
||||
* the message
|
||||
*/
|
||||
public IllegalNumberException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package edu.kit.informatik;
|
||||
|
||||
/**
|
||||
* The Class Main.
|
||||
*
|
||||
* @author Hannes Kuchelmeister
|
||||
* @version 1.0
|
||||
*/
|
||||
public final class Main {
|
||||
|
||||
/**
|
||||
* Instantiates a new main.
|
||||
*/
|
||||
private Main() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The main method.
|
||||
*
|
||||
* @param args
|
||||
* the arguments
|
||||
*/
|
||||
public static void main(final String[] args) {
|
||||
final CommandLineParser cParser = new CommandLineParser();
|
||||
cParser.run();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package edu.kit.informatik;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* This class provides some simple methods for input/output from and to a
|
||||
* terminal.
|
||||
*
|
||||
* Never modify this class, never upload it to Praktomat. This is only for your
|
||||
* local use. If an assignment tells you to
|
||||
* use this class for input and output never use System.out or System.in in the
|
||||
* same assignment.
|
||||
*
|
||||
* @author ITI, VeriAlg Group
|
||||
* @author IPD, SDQ Group
|
||||
* @version 4
|
||||
*/
|
||||
public final class Terminal {
|
||||
|
||||
/**
|
||||
* BufferedReader for reading from standard input line-by-line.
|
||||
*/
|
||||
private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
/**
|
||||
* Private constructor to avoid object generation.
|
||||
*/
|
||||
private Terminal() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a String to the standard output.
|
||||
*
|
||||
* The String out must not be null.
|
||||
*
|
||||
* @param out
|
||||
* The string to be printed.
|
||||
*/
|
||||
public static void printLine(final String out) {
|
||||
System.out.println(out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a line from standard input.
|
||||
*
|
||||
* Returns null at the end of the standard input.
|
||||
*
|
||||
* Use Ctrl+D to indicate the end of the standard input.
|
||||
*
|
||||
* @return The next line from the standard input or null.
|
||||
*/
|
||||
public static String readLine() {
|
||||
try {
|
||||
return in.readLine();
|
||||
} catch (final IOException e) {
|
||||
/*
|
||||
* rethrow unchecked (!) exception to prevent students from being
|
||||
* forced to use Exceptions before they have
|
||||
* been introduced in the lecture.
|
||||
*/
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user