Skip to content
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
39 changes: 39 additions & 0 deletions LabWeek3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
.kotlin

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
10 changes: 10 additions & 0 deletions LabWeek3/.idea/.gitignore

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

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

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

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

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

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

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

17 changes: 17 additions & 0 deletions LabWeek3/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.workshop</groupId>
<artifactId>LabWeek3</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>25</maven.compiler.source>
<maven.compiler.target>25</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
26 changes: 26 additions & 0 deletions LabWeek3/src/main/java/BigDecimalExercise.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

double round(BigDecimal num){
MathContext m = new MathContext(3);
BigDecimal rounded = num.round(m);
return rounded.doubleValue();
}
double p2(BigDecimal num){
MathContext m = new MathContext(2);
BigDecimal rounded = num.round(m);
rounded = rounded.multiply(new BigDecimal("-1"));
return rounded.doubleValue();
}




void main() {
BigDecimal b1 = new BigDecimal("4.2585");
double result = round(b1);
System.out.println("Rounded: " + result);

result = p2(b1);
System.out.println("Rounded and flipped: " + result);
}


49 changes: 49 additions & 0 deletions LabWeek3/src/main/java/CarSystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
public abstract class Car{
private String vinNumber;
private String make;
private String model;
private int mileage;

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

public String getInfo(){
return "vinNumber: "+ vinNumber
+ " make: " + make + " model: "
+model+" mileage: "+mileage;
}

}

public class Sedan extends Car {
public Sedan(String vinNumber, String make, String model, int mileage) {
super(vinNumber, make, model, mileage);
}
}
public class UtilityVehicle extends Car{
private boolean fourWheelDrive;

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

public Truck(String vinNumber, String make, String model, int mileage, double towingCapacity) {
super(vinNumber, make, model, mileage);
this.towingCapacity = towingCapacity;
}
}




void main() {

}
99 changes: 99 additions & 0 deletions LabWeek3/src/main/java/IntListInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
public interface IntList{
void add(int number);
int get(int id) throws Exception;
}
public class IntArrayList implements IntList{
private int[] nums;
private int capacity = 10;
private int elements = 0;

public IntArrayList() {
this.nums = new int[capacity];
}

@Override
public void add(int number) {
if (elements == capacity) {
int new_capacity = (int) Math.floor(capacity * 1.5);
int[] new_nums = new int[new_capacity];
for(int i = 0; i < elements; ++i) {
new_nums[i] = nums[i];
}
this.nums = new_nums;
this.capacity = new_capacity;
}
this.nums[elements] = number;
this.elements++;
}

@Override
public int get(int id) throws Exception {
if (id < elements) {
return nums[id];
}
throw new Exception("not enough elements");
}
}


public class IntVector implements IntList{
private int[] nums;
private int capacity = 20;
private int elements = 0;

public IntVector() {
this.nums = new int[capacity];
}

@Override
public void add(int number) {
if (elements == capacity) {
int new_capacity = capacity * 2;
int[] new_nums = new int[new_capacity];
for(int i = 0; i < elements; ++i) {
new_nums[i] = nums[i];
}
this.nums = new_nums;
this.capacity = new_capacity;
}
this.nums[elements] = number;
this.elements++;
}

@Override
public int get(int id) throws Exception {
if (id < elements) {
return nums[id];
}
throw new Exception("not enough elements");
}

}





void main() {
IntList my_list = new IntArrayList();
for (int i = 0; i < 14; ++i) {
my_list.add(i);
}
try {
int elem = my_list.get(13);
System.out.println(elem);
} catch (Exception e) {
throw new RuntimeException(e);
}

my_list = new IntVector();
for (int i = 0; i < 14; ++i) {
my_list.add(i);
}
try {
int elem = my_list.get(13);
System.out.println(elem);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
39 changes: 39 additions & 0 deletions LabWeek3/src/main/java/VideoStreamingService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
public abstract class Video{
private String title;
private int duration;

public Video(String title, int duration) {
this.title = title;
this.duration = duration;
}

public String getInfo(){
return "title: "+ title + " duration: " + duration;
}

}

public class TvSeries extends Video{
private int episodes;

public TvSeries(String title, int duration, int episodes) {
super(title, duration);
this.episodes = episodes;
}
}
public class Movie extends Video{
private double rating;

public Movie(String title, int duration,double rating) {
super(title, duration);
this.rating = rating;
}
}





void main() {

}