Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a Stack class and the main(). Stack must contain one of our previous List classes as a private instance variable. All the methods of

Create a Stack class and the main(). Stack must contain one of our previous List classes as a private instance variable. All the methods of class must work by simply calling a method of the contained List class. The Stack can NOT contain ArrayList. It must contain List. Need help in my stack and main.

//inputs:

5 2 - 6 7 + * 3 / 20 2 / 2 / 2 / 6 2 + 3 - 4 * 7 / 90 sin 180 cos 270 sin 45 tan 135 tan 225 tan 

//outputs:

Expression: 5 2 - 6 7 + * 3 /

Value: 13.0

Expression: 20 2 / 2 / 2 /

Value: 2.5

Expression: 6 2 + 3 - 4 * 7 /

Value: 2.857142857142857

Expression: 90 sin

Value: 1.0

Expression: 180 cos

Value: -1.0

Expression: 270 sin

Value: -1.0

Expression: 45 tan

Value: 0.9999999999999999

Expression: 135 tan

Value: -1.0000000000000002

Expression: 225 tan

Value: 0.9999999999999997

//Class List:

import java.util.ArrayList; import java.util.Collections;

/** * @author * List with using Imported Java Array List * */ public class List { private ArrayList mList;

/** * Create a List with the indicated size * * @param size the maximum number of items in the List */ public List() { mList = new ArrayList(); }

public List(List myList) { mList = new ArrayList(); for(int i = 0; i < myList.askCount();i++) { mList.add(myList.getMember(i)); } } private String getMember(int index) { return mList.get(index); }

/** * If the List is not full, item becomes the new front element * * @param item the item to add */ public void addToFront(String item) { mList.add(0, item); }

/** * If the List is not full, item becomes the new rear element * * @param item the item to add */ public void addToRear(String item) { mList.add(item); }

/** * If the List is not full and beforeItem is in the List item becomes the element before beforeItem * If the List is full, prints "List Full" * If List is not full but beforeItem is not in List, prints "Item Not Found" * * @param beforeItem the item in the list to add item before * @param item the item to add to the list */ public void addBeforeItem(String beforeItem, String item) { if (isPresent(beforeItem)) { int index = 0; for (String s : mList) { if (s.equals(beforeItem)) { mList.add(index, item); break; } index++; } } else { System.out.println("Item Not found"); } }

/** * If the List is not full and afterItem is in the List item becomes the element after afterItem * If the List is full, prints "List Full" * If List is not full but afterItem is not in List, prints "Item Not Found" * * @param afterItem the item in the list to add item before * @param item the item to add to the list */

public void addAfterItem(String afterItem, String item) { if (isPresent(afterItem)) { int index = mList.indexOf(afterItem); { mList.add(index +1, item); } } else { System.out.println("Item Not found"); } }

/** * Returns the item at the front of the List (List is not altered) * * @return the item at the front of the List */ public String getFront() { if (mList.size() == 0) { System.out.println("List Empty"); return ""; } return (mList.get(0));

}

/** * Returns the item at the rear of the List (List is not altered) * * @return the item at the rear of the List */ public String getRear() { if (mList.size() == 0) { System.out.println("List Empty"); return ""; }

return (mList.get(mList.size() - 1)); }

/** * Return true if item is in List, false otherwise * * @param item to check presence in List * @return true if item is in List, false otherwise */ public boolean isPresent(String item) { return mList.contains(item);

}

/** * Returns the number of items in the List * * @return the number of items in the List */ public int askCount() { return mList.size(); }

/** * If the List is empty, prints "List Empty" * If the List is not empty, removes the item at the front of the List */ public void removeFront() { if (mList.size() > 0) { mList.remove(0); } else { System.out.println("List Empty"); } }

/** * If the List is empty, prints "List Empty" * If the List is not empty, removes the item at the rear of the List */ public void removeRear() { if (mList.size() == 0) { System.out.println("List Empty"); } else { mList.remove(mList.size() - 1); } }

/** * If the List is empty, prints "List Empty" * If item is not present in List, prints "Item not found" * Otherwise, item is removed from the List * * @param item the item to remove */ public void removeItem(String item) { if (mList.size() == 0) { System.out.println("List Empty"); }

else if (mList.contains(item)) { mList.remove(item); } else { System.out.println("Item not found"); } }

/** * Print title on a line by itself * Prints the List from front to rear with 1 space between each item * * @param title the description of the List */ public void print(String title) { System.out.println(" " + title); int size = mList.size(); if (size > 0) { for (int i = 0; i < mList.size();i++) { System.out.print(mList.get(i) + " "); } } System.out.println(""); }

/** * Print title on a line by itself * Prints the Sorted List with 1 space between each item * Does not alter the List * * @param title the description of the List */ public void printSorted(String title) { ArrayList temp = new ArrayList (); for (String s : mList) { temp.add(s); }

Collections.sort(temp); System.out.println(" " + title); for (String s : temp) { System.out.print(s + " "); }

System.out.println();

}

}

//Class Stack:

import java.util.Arrays;

public class Stack { private int stack []; private int top; public Stack() {

} public void push(String item) { if (top == stack.length) { Stack(); }

stack[top]= i; top++; } public void pop(int i) { } public String getTop() { return getTop(); } public boolean isEmpty() { } }

//main:

import java.util.Scanner;

public class AssignmentSix { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String num = sc.nextLine(); System.out.println("Expression:" + System.in); System.out.println("Value" + ); } private boolean isBinary(int number) { }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

JDBC Database Programming With J2ee

Authors: Art Taylor

1st Edition

0130453234, 978-0130453235

More Books

Students also viewed these Databases questions