Need help.
Task \#1 The if Statement, Comparing Strings, and Flags 1. Copy the file PizzaOrder.java (see Code Listing 3.1) from the Student Files or as directed by your instructor. 2. Compile and run Pizzaorder.java. You will be able to make selections, but at this point, you will always get a Hand-tossed pizza at a base cost of $12.99 no matter what you select, but you will be able to choose toppings, and they should Copyright @ 2019 Pearson Education, Inc., Hoboken NJ add into the price correctly. You will also notice that the output does not look like money. So we need to edit Pizzaorder. java to complete the program so that it works correctly. 3. Construct a simple if statement. The condition will compare the String input by the user as his or her first name with the first names of the owners, Mike and Diane. Be sure that the comparison is not case sensitive. 4. If the user has either first name, set the discount flag to true. This will not affect the price at this point yet.
.
General Principles of Intellectual Property: Concepts of Intellectual Proper...
NEED THE JAVA CODE FOR TEST METHODS OF THE FOLLOWING CODE- PLEASE HELP.docx
1. NEED THE JAVA CODE FOR TEST METHODS OF THE FOLLOWING CODE,
PLEASE HELP.
public class ArrayBasedStack<T> implements StackADT<T> {
private T[] stackArray;
private int size;
private int capacity;
@SuppressWarnings("unchecked")
public ArrayBasedStack(int initialCapacity) {
size = 0;
this.capacity = initialCapacity;
stackArray = (T[])new Object[capacity];
}
public ArrayBasedStack() {
this(100);
}
/**
* Checks if the stack is empty.
*
* @return Returns true if the stack is empty.
*/
@Override
public boolean isEmpty() {
return size == 0;
2. }
/**
* Checks the item at the top of the
* stack without removing it.
*
* @return Item at the top of the stack.
*/
@Override
public T peek() throws EmptyStackException {
if (isEmpty()) {
throw new EmptyStackException();
}
return stackArray[size - 1];
}
/**
* Removes the item at the top of
* the stack.
*
* @return The item that was removed.
*/
@Override
public T pop() throws EmptyStackException {
if (isEmpty()) {
3. throw new EmptyStackException();
}
T result = stackArray[size - 1];
stackArray[size - 1] = null;
size--;
return result;
}
/**
* Pushes an item onto the stack.
*
* @param item
* Item to be pushed
* onto the stack.
*/
@Override
public void push(T item) {
if (size == capacity) {
expandCapacity();
}
stackArray[size] = item;
size ++;
}
/**
4. * Checks if an item is in the stack.
*
* @param item
* Item to be looked for.
* @return Returns true if the item is
* somewhere in the stack.
*/
@Override
public boolean contains(T item) {
for (int i = size - 1; i >= 0; i--) {
if (stackArray[i].equals(item)) {
return true;
}
}
return false;
}
/**
* Number of items in the stack.
*
* @return The number of items in
* the stack.
*/
@Override
5. public int size() {
return size;
}
/**
* Clears the stack (removes all of
* the items from the stack).
*/
@Override
public void clear() {
for (int i = 0; i < size; i++) {
stackArray[i] = null;
}
size = 0;
}
/**
* Returns an array with a copy of each element in the stack with the top of
* the stack being the last element
*
* @return the array representation of the stack
*/
@Override
public Object[] toArray() {
@SuppressWarnings("unchecked")
6. T[] copy = (T[])new Object[this.size()];
for (int i = 0; i < this.size(); i++) {
copy[i] = this.stackArray[i];
}
return copy;
}
/**
* Expands the capacity of the stack by doubling its current capacity.
*/
private void expandCapacity() {
@SuppressWarnings("unchecked")
T[] newArray = (T[])new Object[this.capacity * 2];
for (int i = 0; i < this.capacity; i++) {
newArray[i] = this.stackArray[i];
}
this.stackArray = newArray;
this.capacity *= 2;
}
/**
* Returns the string representation of the stack.
*
* [] (if the stack is empty)
* [bottom, item, ..., item, top] (if the stack contains items)
7. *
* @return the string representation of the stack.
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append('[');
boolean firstItem = true;
for (int i = 0; i < this.size(); i++) {
if (!firstItem) {
builder.append(", ");
}
else {
firstItem = false;
}
// String.valueOf will print null or the toString of the item
builder.append(String.valueOf(this.stackArray[i]));
}
builder.append(']');
return builder.toString();
}
/**
* Two stacks are equal iff they both have the same size and contain the
8. * same elements in the same order.
*
* @param other
* the other object to compare to this
*
* @return {@code true}, if the stacks are equal; {@code false} otherwise.
*/
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other == null) {
return false;
}
if (this.getClass().equals(other.getClass())) {
ArrayBasedStack<?> otherStack = (ArrayBasedStack<?>)other;
if (this.size() != otherStack.size()) {
return false;
}
Object[] otherArray = otherStack.toArray();
for (int i = 0; i < this.size(); i++) {
if (!(this.stackArray[i].equals(otherArray[i]))) {