Starting from:

$20

CSC20- Lab 10: Programming Concepts and Methodology II Solved

Objective: The objective of this lab is to get you some experience in using generic classes, enums, foreach loops and the Java class library.

The Java class library: The Java Class Library is a set of dynamically loadable libraries that Java application programs can call at runtime. Like other standard code libraries, Java class library provides the programmer a well-known set of functions to perform common tasks, such as maintaining lists of items or performing complex string parsing. For Java 1.5 or later, some generic classes and generic interfaces are included in the Java class library. Examples:

import java.util.*;

public class Stack<E> extends Vector<E> {       public Stack(); // constructor  public Boolean empty();  public E peek();            public E pop();             public E push(E item);

}

public class LinkedList<E> extends AbstractSequentialList<E>

                               implements List<E>, Queue<E>, Cloneable, Serializable {

               public LinkedList(); // constructor

            public E getFirst();       public E removeFirst();  public void addLast(E item);

               public Boolean isEmpty();

}

The programming assignment: In your lab07,

Replace your stack of Object with the generic class Stack<E>.
Replace your queue of Object with the generic class LinkedList<E>.
Replace Post.toString() method with a for-each loop.
Replace your exception classes with the following exception class.
Remove all unnecessary type casts.
enum errorType { ExcessLeftParenthesis, ExcessRightParenthesis, ExcessOperator, ExcessOperand}; class infixException extends Exception {      private errorType etype;

            public infixException(errorType et) { // constructor

                        etype = et;

             }

            public String toString() {

                        return etype.name();

             }

More products