Skip to content

Commit 3c00096

Browse files
Cartracking
Add Cartracking project
1 parent 06d8862 commit 3c00096

File tree

13 files changed

+1367
-0
lines changed

13 files changed

+1367
-0
lines changed

Car Tracking/P3 Instructions.pdf

61.4 KB
Binary file not shown.

Car Tracking/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Car Tracking Application in Terminal
2+
3+
This application is made to be a GUI Terminal application that tracks cars. It is implemented in java. For instructions on usage, check the `src/` folder and the `/doc/` folder. For some more context of this project, check the `P3 Instructions.pdf` file that explains the purpose and requirements of the program.
4+
5+
**Contact Information**
6+
7+
![interests](https://avatars1.githubusercontent.com/u/38919947?s=400&u=49ab1365a14fac78a91e425efd583f7a2bcb3e25&v=4)
8+
9+
Yogindra Raghav (YogiOnBioinformatics)
10+
11+
yraghav97@gmail.com

Car Tracking/bin/Car.class

1.68 KB
Binary file not shown.

Car Tracking/bin/CarTracker.class

7.94 KB
Binary file not shown.

Car Tracking/bin/IndexMinPQ.class

3.61 KB
Binary file not shown.

Car Tracking/doc/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Car Tracking App in Terminal
2+
3+
**Main Classes**
4+
5+
Car.java
6+
This class contains self-explanatory set and get methods, mainly, that will be used by the CarTracker application.
7+
8+
CarTracker.java
9+
The main class that has a user interface and does the tracking.
10+
11+
IndexMinPQ.java
12+
Minimal Priority Queue that is used for sorting cars.
13+
14+
StdOut.java
15+
Standard Java class that allows output from java program to terminal screen.
16+
17+
18+
**Explanation of Creation**
19+
20+
I first began by designing a Car data structure class called "Car.java" which has basic setters and getters. The notable part of this class is that
21+
I use a flag called comparingPrice. This flag is set when cars are initialized and before they are put into IndexMinPQ's in the CarTracker.java. The reason is
22+
because I use two separate cars for each Car that is entered into the program. One of the cars has the flag comparingPrice set to true and the other one to false.
23+
This way the compareTo() method in Car.java knows which parameter to compare to return the relevant answer.
24+
25+
In CarTracker.java I used a mileagePQ and a pricePQ which I gave a max size of 100000 just in case the input file was very big. These PQ's will keep the
26+
minimum priority of mileage and price, respectively. I used an integer variable, index, which kept track of the index that I would give a new car that I added.
27+
To allow for quick accesses of cars I kept a HashMap that mapped VIN Strings to their integer indexes so that I could retrieve the car from the PQ with that index,
28+
quickly. Then I kept two HashMap's related to Make and Model combinations of cars. They mapped the String of the Make and Model together, without spaces, to an
29+
IndexMinPQ, either comparing price or mileage, which is just for a specific model and make.
30+
31+
Here I will prove that retrieving the car with minimum mileage/price is logarithmic or better. I will also prove that all updates and removals are
32+
logarithmic or better. Before we can do any of the above operations, we must first enter cars into our data structure. This was done with one simple call
33+
to insert(int index) in IndexMinPQ.java. According to the documentation of IndexMinPQ.java, this operation is logarithmic. Now that we have the cars in the data
34+
structure, we can retrieve the car with either minimum mileage or price by calling the minKey() method on the correct IndexMinPQ<Car>. Once again according to
35+
the documentation in IndexMinPQ.java, the minKey() operation is logarithmic. So this means retrievals for either attribute are logarithmic. For retrieval of
36+
an attribute on a specific make and model, we first ask the user for the make and model. Then we take the make and model (key) and retrieve the
37+
IndexMinPQ<Car> (value). This is an O(1) operation. Once we have this IndexMinPQ<Car> that is specific to our make and model, we can call minKey(), which is
38+
constant. Two constant operations [O(1) + O(1)] is still constant, O(1). To update a car, the user is asked what the VIN number is. Assuming a valid VIN is passed
39+
in, we can find the index in our indirection table that corresponds to that object. On average, this is an O(1) constant operation with a HashMap. Once we have
40+
the index, we delete the old version of the car which is O(log(n)), according to IndexMinPQ.java, and then re-add the new version which is the insert() method.
41+
This is also O(log(n)). That means updating a car costs O(1)+O(log(n)) + O(log(n)) which simplifies to O(log(n)). Removing a car is done very similarly with
42+
an O(1) HashMap look-up given the VIN. Then we call the delete(int index) function in IndexMinPQ.java which according to the documentation is O(log(n)). That
43+
means removing a car has an average complexity of O(1) + O(log(n)) which simplifies to O(log(n)). Therefore, all the operations involved in this project function
44+
in logarithmic time or better.
45+
46+
To make sure that the major operations of CarTracker.java were logarithmic time or better, more memory was used. The memory requirements of this program
47+
are relatively high. To take into account the major contributors to the memory overhead, we will ignore minor variables such as int index and BufferedReader reader,
48+
which consume a minimal amount of memory as compared to the other data structures. The mileagePQ and pricePQ which are IndexMinPQ's of type Car used a memory
49+
overhead of "one million". This is to say that they used up quite a lot of memory but it is hard to say in bytes how much that is. If n equals the size of the input
50+
data, then in most cases this term is greater than n (1000000>n). There are two of these so we have at MINIMUM Omega(2n) in memory right there. After this, we have
51+
a HashMap known as vinMap which contains the VIN String and int Index that is associated with it. This is O(n). After this, we have two more HashMap's that kept
52+
the make and model as the key and an IndexMinPQ<Car> as their value that either used mileage or price to compare. This means that in total this is another O(2n).
53+
Overall, this would mean that at a MINIMUM, as a tight lower bound, the memory used by this program is Omega(5n). This is quite a lot of memory and it is hard
54+
to give a tight upper bound or even average. However, the work of this paragraph shows that this has to be a minimum. Just to make it clear, I would like to state that
55+
I have been considering memory used by this program in terms of how much physical space it would take to run. If I was to just look at the memory usage as a function
56+
of input size, then we can say that this program uses Theta(5n) memory.
57+
58+
59+
**Contact Information**
60+
61+
![interests](https://avatars1.githubusercontent.com/u/38919947?s=400&u=49ab1365a14fac78a91e425efd583f7a2bcb3e25&v=4)
62+
63+
Yogindra Raghav (YogiOnBioinformatics)
64+
65+
yraghav97@gmail.com

Car Tracking/info_sheet.txt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
========================================
2+
CS/COE 1501 Assignment Information Sheet
3+
----------------------------------------
4+
5+
You must submit an information sheet with every assignment. Also be sure
6+
to submit all materials following the procedures described on the
7+
submission procedures page.
8+
9+
Name: Yogindra Raghav
10+
11+
Lecture section: D
12+
13+
Recitation day and time: Friday 12:00PM
14+
15+
Assignment #: 3
16+
17+
Program due date: March 23rd, 2018
18+
19+
Handed in date: March 21st, 2018
20+
21+
Source code file name(s):
22+
CarTracker.java
23+
24+
25+
26+
27+
28+
29+
Other file name(s) (if relevant):
30+
Car.java
31+
cars.txt
32+
documentation.txt
33+
IndexMinPQ.java
34+
35+
36+
Does your program run without error?: Yes, no issues
37+
38+
If not, what is/are the error(s) and which parts of your program run
39+
correctly?: No issues
40+
41+
42+
43+
44+
45+
46+
Additional comments to the grader:
47+
48+
No comments
49+
50+
51+
52+
53+

Car Tracking/src/Car.java

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import java.lang.String;
2+
3+
4+
public class Car implements Comparable<Car> { //Needs to be comparable so that PQ knows how to keep priority
5+
6+
private String VIN;
7+
private String make;
8+
private String model;
9+
private int price;
10+
private int mileage;
11+
private String color;
12+
private boolean comparingPrice; //this flag is used so that we know how to compare two items
13+
14+
15+
public Car(){
16+
17+
}
18+
19+
public boolean set_VIN(String vin){
20+
VIN = vin;
21+
return true;
22+
}
23+
24+
public String get_VIN(){
25+
26+
return VIN;
27+
}
28+
29+
public boolean set_make(String Make){
30+
make = Make;
31+
return true;
32+
}
33+
34+
public String get_make(){
35+
return make;
36+
}
37+
38+
public boolean set_model(String Model){
39+
model = Model;
40+
return true;
41+
}
42+
43+
public String get_model(){
44+
return model;
45+
}
46+
47+
public boolean set_price(int Price){
48+
price = Price;
49+
return true;
50+
}
51+
52+
public int get_price(){
53+
return price;
54+
}
55+
56+
public boolean set_mileage(int Mileage){
57+
mileage = Mileage;
58+
return true;
59+
}
60+
61+
public int get_mileage(){
62+
return mileage;
63+
}
64+
65+
public boolean set_color(String Color){
66+
color = Color;
67+
return true;
68+
}
69+
70+
public String get_color(){
71+
return color;
72+
}
73+
74+
public void set_comparingPrice(boolean b) {
75+
comparingPrice = b;
76+
}
77+
78+
public boolean get_comparingPrice(){
79+
return comparingPrice;
80+
}
81+
82+
public int compareTo(Car other){ //this method checks the flag of comparingPrice before it returns any value.
83+
if(comparingPrice){
84+
if(this.price>other.price){
85+
return 1;
86+
}
87+
else if(this.price==other.price){
88+
return 0;
89+
}
90+
else if(this.price < other.price){
91+
return -1;
92+
}
93+
else {
94+
return 0;
95+
}
96+
}
97+
else {
98+
if(this.mileage>other.mileage){
99+
return 1;
100+
}
101+
else if(this.mileage==other.mileage){
102+
return 0;
103+
}
104+
else if(this.mileage < other.mileage){
105+
return -1;
106+
}
107+
else {
108+
return 0;
109+
}
110+
}
111+
}
112+
113+
114+
115+
116+
}

0 commit comments

Comments
 (0)