initial commit

This commit is contained in:
nora 2020-12-01 17:53:37 +01:00
parent 5e115d7fbe
commit defbacb8c7
21 changed files with 194 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

Binary file not shown.

View file

@ -0,0 +1,2 @@
#Tue Dec 01 17:50:15 CET 2020
gradle.version=6.6.1

Binary file not shown.

View file

3
.idea/.gitignore generated vendored Normal file
View file

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

2
.idea/TriangleCalulator.iml generated Normal file
View file

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />

6
.idea/compiler.xml generated Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="15" />
</component>
</project>

16
.idea/gradle.xml generated Normal file
View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

20
.idea/jarRepositories.xml generated Normal file
View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="MavenRepo" />
<option name="name" value="MavenRepo" />
<option name="url" value="https://repo.maven.apache.org/maven2/" />
</remote-repository>
</component>
</project>

5
.idea/misc.xml generated Normal file
View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_15" default="false" project-jdk-name="15" project-jdk-type="JavaSDK" />
</project>

6
.idea/vcs.xml generated Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

29
build.gradle.kts Normal file
View file

@ -0,0 +1,29 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.4.20"
application
}
group = "me.nilsh"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
testImplementation(kotlin("test-junit"))
}
tasks.test {
useJUnit()
}
tasks.withType<KotlinCompile>() {
kotlinOptions.jvmTarget = "1.8"
}
application {
mainClassName = "MainKt"
}

1
gradle.properties Normal file
View file

@ -0,0 +1 @@
kotlin.code.style=official

View file

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

3
settings.gradle.kts Normal file
View file

@ -0,0 +1,3 @@
rootProject.name = "TriangleCalulator"

96
src/main/kotlin/main.kt Normal file
View file

@ -0,0 +1,96 @@
import java.lang.IllegalArgumentException
import kotlin.contracts.contract
import kotlin.math.*
fun main() {
val triangle = Triangle(7.7, 4.3, 8.7)
println(triangle)
}
class Triangle() {
var a = Side(0.0, "a")
var b = Side(0.0, "b")
var c = Side(0.0, "c")
var alpha = Angle(0.0, "")
var beta = Angle(0.0, "")
var gamma = Angle(0.0, "")
init {
}
constructor(angleName: String, angle: Double, sideName: String, side: Double) : this() {
if (angleName == "alpha") {
when(sideName){
"a" -> {
c = Side(side / sin(angle), "c")
b = Side(c * cos(angle), "b")
}
"b" -> {
//c = Side
}
"c" -> {
//cos
}
}
} else if (angleName == "beta") {
when(sideName){
"a" -> {
//cos
}
"b" -> {
//sin
}
"c" -> {
//cos
}
}
} else {
throw IllegalArgumentException("$angleName is not a valid angle")
}
}
constructor(vararg sides: Double) : this() {
a = Side(sides[0], "a")
b = Side(sides[1], "b")
c = Side(sides[2], "c")
calculateAngles()
}
private fun calculateAngles() {
alpha = Angle(asin(a.length / c.length).toDegree(), "alpha")
beta = Angle(asin(b.length / c.length).toDegree(), "beta")
gamma = Angle(180 - beta.angle - alpha.angle, "gamma")
}
private fun Double.toDegree() = this * 180 / PI
override fun toString(): String {
return "Seiten: $a, $b, $c Winkel: $alpha $beta $gamma"
}
}
class Side(length: Double, name: String) {
val length = length
val name = name
operator fun times(other: Double) = this.length * other
override fun toString(): String {
return "$name = $length"
}
}
class Angle(value: Double, name: String) {
val angle = value
val name = name
override fun toString(): String {
return "$name = ${"%.2f".format(angle)}"
}
}