Info Blatt 5 - SS 2021, Java Dateien als PDF PDF

Title Info Blatt 5 - SS 2021, Java Dateien als PDF
Author Marie Schmied
Course Informatik im Maschinenbau
Institution Karlsruher Institut für Technologie
Pages 3
File Size 56 KB
File Type PDF
Total Downloads 59
Total Views 129

Summary

SS 2021, Java Dateien als PDF...


Description

Blatt 5 Aufgabe 1 das Ring-Spiel import Prog1Tools.IOTools; public class Die { public int value; public Die() { toss(); } public int getTossedValue() { return value; } public void toss() { value = (int) Math.random() *6+1; } }

Aufgabe 3 Massenberechnung public class AngularConstructionElement extends ConstructionElement { private double sideLength; public double getSideLength() { return this.sideLength; } public void setSideLength(double sideLength) { this.sideLength = sideLength; } } import Prog1Tools . IOTools ; public class Cuboid extends AngularConstructionElement { double heigth; double width; public void setAttributes(double density,double length,double width,double heigth) { super.setDensity ( density ); //ausf฀hren der Methode "setDensity" aus der Ober-Ober-Klasse "ConstructionElement" super.setSideLength ( length ); this.width = width ; this.heigth = heigth ; calculateVolume (); calculateMass (); } public void getValuesFromConsoleInput() { double density , length , width , heigth ; System .out . println (" ConstructionElement : Cuboid "); density = IOTools . readDouble (" Density in kg/m3: "); length = IOTools . readDouble (" Length in mm: " )/1000; width = IOTools . readDouble (" Width in mm: " )/1000; heigth = IOTools . readDouble (" Hight in mm: " )/1000; this . setAttributes ( density ,length ,width , heigth ); } public void calculateVolume()

{ super.setVolume( getSideLength ()* width * heigth ); } } import Prog1Tools . IOTools ; public class Pyramid extends AngularConstructionElement { double heigth; public void setAttributes(double density,double sideLength,double heigth) { super.setDensity(density); //Methode der Oberklasse wird ausfegrufen -> AngularConstructionElement, da diese Klasse super.setSideLength ( sideLength ); //aber wiederrum von der ConstructionElement erbt wird letzendlich "setDensity" aus der this.heigth = heigth ; //Klasse "ConstructionElement" aufgerufen calculateVolume (); calculateMass (); } public void getValuesFromConsoleInput() //Wetre aus der Console einlesen + Umrechnung { System .out . println (" ConstructionElement : Pyramid "); double density = IOTools . readDouble (" Density in kg/m3: "); double sideLength = IOTools . readDouble (" Side length in mm: " )/1000; double heigth = IOTools . readDouble (" Hight in mm: " )/1000; setAttributes ( density , sideLength , heigth ); } public void calculateVolume() //K฀rperspezifische Volumenberechnung { setVolume ((1/3)* Math .pow( getSideLength () ,2)* heigth ); } }...


Similar Free PDFs