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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.metadata/
/.recommenders/
6 changes: 6 additions & 0 deletions Calculator/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions Calculator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
17 changes: 17 additions & 0 deletions Calculator/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Calculator</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions Calculator/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
47 changes: 47 additions & 0 deletions Calculator/src/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import java.util.Scanner;

public class Calculator {

public static void main(String[] args) {

System.out.println("Please type a number to the console.");
Scanner reader = new Scanner(System.in);
int firstNum = reader.nextInt(); //Reads first number from user
System.out.println("Please type another number to the console.");
int secondNum = reader.nextInt(); //Reads second number
reader.close();
int sum = addition(firstNum, secondNum);
System.out.println("Addition: " + sum);
int subtract = subtraction(firstNum, secondNum);
System.out.println("Subtraction: " + subtract);
int multiply = multiplication(firstNum, secondNum);
System.out.println("Multiplication: " + multiply);
int divide = division(firstNum, secondNum);
System.out.println("Division: " + divide);
}

//Addition
public static int addition (int firstNum, int secondNum) {
int sum = firstNum + secondNum;
return sum;
}

//Subtraction
public static int subtraction (int firstNum, int secondNum) {
int subtract = firstNum - secondNum;
return subtract;
}

//Multiplication
public static int multiplication (int firstNum, int secondNum) {
int multiply = firstNum * secondNum;
return multiply;
}

//Division
public static int division (int firstNum, int secondNum) {
int divide = firstNum / secondNum;
return divide;
}

}
6 changes: 6 additions & 0 deletions CarLot/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions CarLot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
17 changes: 17 additions & 0 deletions CarLot/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>CarLot</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions CarLot/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
44 changes: 44 additions & 0 deletions CarLot/src/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

public class Car extends Vehicle{

//Attributes
private String carType;
private int numDoors;

//Constructor
public Car() {

}

//Getters and Setters
public String getCarType() {
return carType;
}

public void setCarType(String myCarType) {
this.carType = myCarType;
}

public int getNumDoors() {
return numDoors;
}

public void setNumDoors(int myNumDoors) {
this.numDoors = myNumDoors;
}

//Methods

@Override
//Calls the super method and adds the bed size
public void printVehicleDescription() {

super.printVehicleDescription();
System.out.println("Car Type: " + carType);
System.out.println("Number of Doors in the Car: " + numDoors);

}



}
61 changes: 61 additions & 0 deletions CarLot/src/CarLot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

public class CarLot {

//Attributes
public static int carCount = 0;
private String lotName;
private Vehicle[] listOfVehicles;

//Constructor
public CarLot(int amountOfVehicles) {
listOfVehicles = new Vehicle[amountOfVehicles];
}

//Getters and Setters
public String getLotName() {
return lotName;
}

public void setLotName(String myLotName) {
this.lotName = myLotName;
}

public Vehicle[] getListOfVehicles () {
return listOfVehicles;
}

public void setListOfVehicles (Vehicle[] myListOfVehicles) {
this.listOfVehicles = myListOfVehicles;
}

//Methods

//This method adds car to the lot
public void addCarToLot(Vehicle vehicle, int spot) {
try {
//Checks to see if the spot is available
if (!(listOfVehicles[spot] == null)) {
System.out.println("Cannot place car in parking spot " + spot + " because it is taken."); }
else listOfVehicles[spot] = vehicle;
//Calls the super method and adds the bed size
} catch(Exception e) {
System.out.println("Cannot place car in spot " + spot + " because it does not exist.");
}
}

//This method prints the inventory of the Lot
public void printLotInventory() {
carCount = 0;
System.out.println(lotName + ": ");
for (int i = 0; i < listOfVehicles.length; i++) {
if (!(listOfVehicles[i] == null)) {
carCount++;
listOfVehicles[i].printVehicleDescription();
System.out.println();
}
}

System.out.println(lotName + " has " + carCount + " cars.");
System.out.println();
}
}
92 changes: 92 additions & 0 deletions CarLot/src/CarLotProgram.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@

public class CarLotProgram {

public static void main(String[] args) {
// TODO Auto-generated method stub

//Creates Lots
CarLot firstLot = new CarLot(5);
firstLot.setLotName("Lot One");

CarLot secondLot = new CarLot(5);
secondLot.setLotName("Lot Two");

//Creates Vehicles
Car firstCar = new Car();
firstCar.setCarType("Sedan");
firstCar.setLicenseNum("TVJ-8823");
firstCar.setMake("Honda");
firstCar.setModel("Accord");
firstCar.setNumDoors(4);
firstCar.setPrice("$20,000");

Car secondCar = new Car();
secondCar.setCarType("Sedan");
secondCar.setLicenseNum("GIQ-7196");
secondCar.setMake("Toyota");
secondCar.setModel("Camry");
secondCar.setNumDoors(4);
secondCar.setPrice("$22,000");

Car thirdCar = new Car();
thirdCar.setCarType("Hatchback");
thirdCar.setLicenseNum("ABC-1234");
thirdCar.setMake("KIA");
thirdCar.setModel("Soul");
thirdCar.setNumDoors(4);
thirdCar.setPrice("$28,000");

Car fourthCar = new Car();
fourthCar.setCarType("Coupe");
fourthCar.setLicenseNum("EFG-5678");
fourthCar.setMake("Chevrolet");
fourthCar.setModel("Corvette");
fourthCar.setNumDoors(2);
fourthCar.setPrice("$55,000");

Truck firstTruck = new Truck();
firstTruck.setLicenseNum("HIJ-9101");
firstTruck.setMake("Ford");
firstTruck.setModel("F-150");
firstTruck.setPrice("$59,000");
firstTruck.setBedSize(66);

Truck secondTruck = new Truck();
secondTruck.setLicenseNum("KLM-1213");
secondTruck.setMake("Ford");
secondTruck.setModel("F-250");
secondTruck.setPrice("$80,000");
secondTruck.setBedSize(80);

Truck thirdTruck = new Truck();
thirdTruck.setLicenseNum("OPQ-1415");
thirdTruck.setMake("Dodge");
thirdTruck.setModel("Ram");
thirdTruck.setPrice("$72,000");
thirdTruck.setBedSize(75);

Truck fourthTruck = new Truck();
fourthTruck.setLicenseNum("RST-1617");
fourthTruck.setMake("Dodge");
fourthTruck.setModel("Ram");
fourthTruck.setPrice("$65,000");
fourthTruck.setBedSize(70);

//Adds Cars/Trucks into First Lot
firstLot.addCarToLot(firstCar, 2);
firstLot.addCarToLot(thirdCar, 4);
firstLot.addCarToLot(secondTruck, 0);
firstLot.addCarToLot(fourthTruck, 3);

//Adds Cars/Trucks into Second Lot
secondLot.addCarToLot(secondCar, 0);
secondLot.addCarToLot(fourthCar, 1);
secondLot.addCarToLot(firstTruck, 2);
secondLot.addCarToLot(thirdTruck, 3);

//Prints Lot One and Lot two
firstLot.printLotInventory();
secondLot.printLotInventory();
}

}
35 changes: 35 additions & 0 deletions CarLot/src/Truck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

public class Truck extends Vehicle{

//Attributes
private int bedSize;

//Constructor
public Truck() {

}

//Getter and Setter
public int getBedSize() {
return bedSize;
}

public void setBedSize(int myBedSize) {
this.bedSize = myBedSize;
}

//Methods

@Override
//Calls the super method and adds the bed size
public void printVehicleDescription() {

super.printVehicleDescription();
System.out.println("Truck Bed Size: " + bedSize);

}




}
Loading