Eclipse Java Programming. All given .java code is listed below aslong as a .txt
ID: 3801298 • Letter: E
Question
Eclipse Java Programming. All given .java code is listed below aslong as a .txt file given to do problem.
ArrayStack.java:
public class ArrayStack<T> implements StackADT<T> {
private int capacity;
private int top;
private T[ ] stack;
@SuppressWarnings("unchecked")
public ArrayStack ( ) // POST: empty stack of capacity 10
{ capacity = 10;
top = 0;
stack = (T [ ]) new Object [capacity];
}
@SuppressWarnings("unchecked") // PRE: cap > 0
public ArrayStack (int cap) // POST: empty stack of capacity cap
{ capacity = cap;
top = 0;
stack = (T [ ]) (new Object [capacity]);
}
public void push (T element) // POST: element pushed onto stack
{ if (top == capacity)
resize();
stack[top] = element;
top++;
}
@SuppressWarnings("unchecked")
private void resize() // POST: array is doubled
{
T [ ] temp = (T[ ]) new Object [capacity*2];
for (int k = 0; k < capacity; k++)
temp[k] = stack[k];
capacity = capacity * 2;
stack = temp;
}
public T peek ( ) throws EmptyCollectionException // POST: return top
{ if (isEmpty())
throw new EmptyCollectionException ( );
return stack[top-1];
}
public T pop ( ) throws EmptyCollectionException // POST: return and remove top
{ if (isEmpty())
throw new EmptyCollectionException ( );
top--;
T result = stack[top];
stack[top] = null;
return result;
}
public boolean isEmpty ( ) // POST: return true if empty
{ return top == 0; }
public int size( ) // POST: return size of stack
{ return top; }
}
EmptyCollectionException.java
@SuppressWarnings ("serial")
public class EmptyCollectionException extends RuntimeException {
public EmptyCollectionException ( )
{
super ("The collection is empty.");
}
}
Lot.txt
ParkTime.java//Time.java
import java.util.Scanner;
public class Time {
private int hour; // hour (0 - 23)
private int minute; // minute (0 - 59)
public Time ( ) // POST: empty Time object
{
}
public Time (int h, int m) // PRE: 0 <= h <= 23, 0 <= m <= 59
{ // POST: Time object set with user hour and minute
}
public Time (String s) // PRE: hh:mm format, "00" <= "hh" <= "23", "00" <= "mm" <= "59"
{ // POST: Time object set from string
}
public int getHour() { // POST: return hour
}
public void setHour(int h) { // PRE: 0 <= h <= 23
// POST: set hour
}
public int getMinute() { // POST: return minute
}
public void setMinute(int m) { // PRE: 0 <= m <= 59
// POST: set minute
}
public String toString ( ) // POST: return string in hh:mm format
{
}
public int subtract (Time other) // POST: return number of minutes between two times
{ // compute number of minutes from midnight to time
}
}
Part II: (80 pts) This program will compute income from a small parking lot. It uses a stack to hold data in LIFO order. Use classes ArrayStack and EmptyCollectionException developed in lecture, available on First Class. Acompany rents a 5-car alley for parking. The alley is so narrow that the only egress is at the top, forcing vehicles to be removed one at a time in order to retrieve an internal one Vehicles are temporarily parked on the street until they can be returned to the alley. Cars do not need to returned to the alley in any particular order. alley is a stack street metered parking One day's data set is available in file lot.txt on First Class. Arrival/Departure Code String ("A" or "D") License String (ex. "BOSS") Time Time (ex. 10:30 or 21:45) Read in the lines of the data files and recreate the movement of cars in and out of the parking lot. Vehicles are charged $4.50 per hour for the duration of their stay. If a person arrives and claims to have a car but the car is not found, catch the EmptyCollectionException and note this in your output. Cars are then just returned to the parking lot. Partial hours are rounded up. Cars parked temporarily on the street pay a $0.25 meter feeExplanation / Answer
public class ArrayStack implements StackArray {
private int capacity;
private int top;
private T[ ] stack;
@SuppressWarnings("unchecked")
public ArrayStack ( )
{ capacity = 10;
top = 0;
stack = (T [ ]) new Object [capacity];
}
@SuppressWarnings("unchecked")
public ArrayStack (int cap)
{ capacity = cap;
top = 0;
stack = (T [ ]) (new Object [capacity]);
}
public void push (T element)
{ if (top == capacity)
resize();
stack[top] = element;
top++;
}
@SuppressWarnings("unchecked")
private void resize()
{
T [ ] temp = (T[ ]) new Object [capacity*2];
for (int k = 0; k < capacity; k++)
temp[k] = stack[k];
capacity = capacity * 2;
stack = temp;
}
public T peek ( ) throws EmptyCollectionException
{ if (isEmpty())
throw new EmptyCollectionException ( );
return stack[top-1];
}
public T pop ( ) throws EmptyCollectionException
{ if (isEmpty())
throw new EmptyCollectionException ( );
top--;
T result = stack[top];
stack[top] = null;
return result;
}
public boolean isEmpty ( )
{ return top == 0; }
public int size( )
{ return top; }
}
import java.util.Scanner;
public class Time {
private int hour;
private int minute;
public Time ( )
{
}
public Time (int h, int m)
{
}
public Time (String s)
{
}
public int getHour() {
}
public void setHour(int h) {
}
public int getMinute() {
}
public void setMinute(int m) {
}
public String toString ( )
{
}
public int subtract (Time other)
{
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.