[SOLVED] SOLVED:Lab 10 generic classes, enums, foreach loops Solution

19.99 $

Programming resource
Digital learning resource
Category:
Practical programming resource
Suitable for guided study and reference
Tutor guidance available when needed

Description

Rate this product

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 public Stack(); // constructor
public Boolean empty();
public E peek();
public E pop();
public E push(E item);
}
public class LinkedList 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,
1. Replace your stack of Object with the generic class Stack<E.
2. Replace your queue of Object with the generic class LinkedList<E.
3. Replace Post.toString() method with a for-each loop.
4. Replace your exception classes with the following exception class.
5. 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();
}
}

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.