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
26 changes: 26 additions & 0 deletions BigDecimalProject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package Exercise1;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class BigDecimalProject {

public static double roundToCent(BigDecimal number) {
BigDecimal rounded = number.setScale(2, RoundingMode.HALF_UP);
return rounded.doubleValue();
}
public static BigDecimal invertAndRoundToTenth(BigDecimal number) {
BigDecimal inverted = number.negate();
return inverted.setScale(1, RoundingMode.HALF_UP);
}

public static void main(String[] args) {
BigDecimal number = new BigDecimal("4.2545");
System.out.println(roundToCent(number));

BigDecimal number1 = new BigDecimal("1.2345");
BigDecimal number2 = new BigDecimal("-45.67");
System.out.println(invertAndRoundToTenth(number1));
System.out.println(invertAndRoundToTenth(number2));
}
}
19 changes: 19 additions & 0 deletions Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package Exercise2;

public abstract class Car {
protected String vinNumber;
protected String make;
protected String model;
protected 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 + " miles";
}
}
29 changes: 29 additions & 0 deletions IntArrayList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package Exercise4;
import java.util.Arrays;

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

public IntArrayList() {
array = new int[10];
size = 0;
}
@Override
public void add(int number) {
if (size == array.length) {
int newSize = array.length + (array.length / 2);
int[] newArray = new int[newSize];
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: " + id + ", Size: " + size);
}
return array[id];
}
}
6 changes: 6 additions & 0 deletions IntList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package Exercise4;

public interface IntList {
void add(int number);
int get(int id);
}
29 changes: 29 additions & 0 deletions IntVector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package Exercise4;
import java.util.Arrays;

public 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 newSize = array.length * 2;
int[] newArray = new int[newSize];
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: " + id + ", Size: " + size);
}
return array[id];
}
}
27 changes: 27 additions & 0 deletions Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package Exercise4;

public class Main {
public static void main(String[] args) {
IntList intArrayList = new IntArrayList();
for (int i = 0; i < 15; i++) {
intArrayList.add(i);
System.out.println("IntArrayList add: " + i);
}

System.out.println("Elementos en IntArrayList:");
for (int i = 0; i < 15; i++) {
System.out.println("Elemento en posición " + i + ": " + intArrayList.get(i));
}

IntList intVector = new IntVector();
for (int i = 0; i < 25; i++) {
intVector.add(i);
System.out.println("IntVector add: " + i);
}

System.out.println("Elementos en IntVector:");
for (int i = 0; i < 25; i++) {
System.out.println("Elemento en posición " + i + ": " + intVector.get(i));
}
}
}
15 changes: 15 additions & 0 deletions Movie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package Exercise3;

public class Movie extends Video {
private double rating;

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

@Override
public String getInfo() {
return super.getInfo() + ", Rating: " + rating;
}
}
Loading