Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hanitzsch #36

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/lab-java-interfaces-and-abstract-classes.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions CarInventorySystem/CarInventorySystem.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
31 changes: 31 additions & 0 deletions CarInventorySystem/src/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//Create an abstract class named Car and define the following properties and behaviors:
//vinNumber: a String representing the VIN number of the car
//make: a String representing the make of the car
//model: a String representing the model of the car
//mileage: an int representing the mileage of the car
//getInfo(): a method that returns a String containing all of the car's properties in a readable format

import org.w3c.dom.ls.LSOutput;

public abstract class Car {

public String vinNumber;
public String make;
public String model;
public int mileage;




public String getInfo() {
return "Manufacturer: " + make +
", Model: " + model +
", KM: " + mileage +
", VIN Number: " + vinNumber;
}


//Create three classes that extend Car: Sedan, UtilityVehicle and Truck.
}


15 changes: 15 additions & 0 deletions CarInventorySystem/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//Suppose you are building a car inventory system. All cars have a vinNumber, make, model and mileage.
// But no car is just a car. Each car is either a Sedan, a UtilityVehicle or a Truck.

public class Main {
public static void main(String[] args) {
Sedan sedan = new Sedan ("121212", "Dacia", "Sandero Stepway", 47000 );
Truck truck = new Truck("313131", "Dodge", "RAM", 15000, 3500);
UtilityVehicle utilityvehicle = new UtilityVehicle("030303", "Skoda","Kodiaq",15000,true);


System.out.println(truck.toString());
System.out.println(sedan.toString());
System.out.println(utilityvehicle.toString());
}
}
16 changes: 16 additions & 0 deletions CarInventorySystem/src/Sedan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class Sedan extends Car {
public Sedan(String vinNumber, String make, String model, int mileage) {
this.vinNumber = vinNumber;
this.make = make;
this.model = model;
this.mileage = mileage;
}
@Override
public String toString() {
return "Type: Truck, VIN: " + vinNumber +
", Make: " + make +
", Model: " + model +
", Mileage: " + mileage;
}
}

25 changes: 25 additions & 0 deletions CarInventorySystem/src/Truck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//Truck objects should have an additional towingCapacity property,
// a double that represents the towing capacity of the truck.

public class Truck extends Car{
private double towingCapacity;
public Truck(String vinNumber, String make, String model, int mileage, double towingCapacity) {
this.vinNumber = vinNumber;
this.make = make;
this.model = model;
this.mileage = mileage;
this.towingCapacity = towingCapacity;
}


@Override
public String toString() {
return "Type: Truck, VIN: " + vinNumber +
", Make: " + make +
", Model: " + model +
", Mileage: " + mileage +
", Towing Capacity: " + towingCapacity + " Kg";
}
}


25 changes: 25 additions & 0 deletions CarInventorySystem/src/UtilityVehicle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//UtilityVehicle objects should have an additional fourWheelDrive property,
// a boolean that represents whether the vehicle has four-wheel drive.
public class UtilityVehicle extends Car {

private boolean fourWheelDrive;


public UtilityVehicle(String vinNumber, String make, String model, int mileage, boolean fourWheelDrive) {
this.vinNumber = vinNumber;
this.make = make;
this.model = model;
this.mileage = mileage;
this.fourWheelDrive = fourWheelDrive;
}


@Override
public String toString() {
return "Type: Truck, VIN: " + vinNumber +
", Make: " + make +
", Model: " + model +
", Mileage: " + mileage +
", Four Wheel Drive: " + fourWheelDrive;
}
}
11 changes: 11 additions & 0 deletions DoubleBigDecimal/DoubleBigDecimal.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
31 changes: 31 additions & 0 deletions DoubleBigDecimal/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import java.math.BigDecimal;
import java.math.RoundingMode;

public class Main {
public static void main(String[] args) {
//Using the BigDecimal documentation, create a method that accepts a BigDecimal and returns a double of the
// BigDecimal number rounded to the nearest hundredth. For example, 4.2545 should return 4.25.
BigDecimal a = new BigDecimal("4.2545");
BigDecimal displayVal = a.setScale(2, RoundingMode.HALF_EVEN);
System.out.println("Value: " + a);
System.out.println("Rounded Value: " + displayVal);

//Using the BigDecimal documentation, create a method that accepts a BigDecimal,
// reverses the sign (if the parameter is positive, the result should be negative and vice versa),
// rounds the number to the nearest tenth and returns the result.
// For example, 1.2345 should return -1.2 and -45.67 should return 45.7.

BigDecimal b = new BigDecimal("1.2345");
BigDecimal displayVal2 = b.setScale(1, RoundingMode.HALF_UP);
System.out.println("Value: " + b);
System.out.println("Rounded Value: " + displayVal2);
System.out.println("Negate Value: " + displayVal2.negate());

BigDecimal c = new BigDecimal("-45.67");
BigDecimal displayVal3 = c.setScale(1, RoundingMode.HALF_UP);
System.out.println("Value: " + c);
System.out.println("Rounded Value: " + displayVal3);
System.out.println("Negate Value: " + displayVal3.negate());

}
}
9 changes: 9 additions & 0 deletions IntArraList.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.system.module.version="223-2" org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$/IntArraList" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
11 changes: 11 additions & 0 deletions IntArrayList/IntArrayList.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
72 changes: 72 additions & 0 deletions IntArrayList/src/IntList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//Have no idea what I did here, followed the classes and the solutions from IntelliJ hints.

//Create an IntList interface with the following methods:
//add(int number): a method that adds a new number to the list
//get(int id): a method that retrieves an element by its ID


interface IntList {
void add(int number);
int get(int id);
}

//Create two implementations of IntList: IntArrayList and IntVector.

class IntArrayList implements IntList {
private int[] array;
private int size;

public IntArrayList() {
array = new int[10];
size = 0;
}

//Until here was so nice...

@Override
public void add(int number) {
if (size == array.length) {
int[] newArray = new int[array.length + array.length / 2];
System.arraycopy(array, 0, newArray, 0, array.length);
array = newArray;
}
array[size++] = number;
}

@Override
public int get(int id) {
if (id < 0 || id >= size) {
throw new IndexOutOfBoundsException("Index out of bounds");
}
return array[id];
}
}

class IntVector implements IntList {
private int[] array;
private int size;

public IntVector() {
array = new int[20];
size = 0;
}

@Override
public void add(int number) {
if (size == array.length) {
int[] newArray = new int[array.length * 2];
System.arraycopy(array, 0, newArray, 0, array.length);
array = newArray;
}
array[size++] = number;
}

@Override
public int get(int id) {
if (id < 0 || id >= size) {
throw new IndexOutOfBoundsException("Index out of bounds");
}
return array[id];
}
}
// What the hell happened?
Loading