Starting from:
$35

$29

Programming Assignment 3 Solution

In this PA, you need to apply the singleton pattern to create objects for the Stack type (actually sub-class of Stack due to its abstract feature), based on the lecturenotes of 9/25. In other words, at any time, only one instance of the Stack type can be created. Note you have two classes extends Stack via ArrayList and LinkedList. Here are the abstract class you need to further implement:

(we use abstract class Stack instead of interface bc we wouldn’t be able to have static members in an interface)

abstract class Stack {

void push(char c); // push a char c onto a stack

char pop(); // pop a stack from a stack

int size(); // return the number of elements on the stack

static Stack instance(); // by default create an Arraylist object;

static Stack instance(String subClassName); // subClassName is the sub-class name where an object is created.

}

You can copy the class from PA2 that implements the following interface:

Interface IDoublyLinkedList{

boolean remove (int index); // remove a node at index

boolean add(INode node, int index); //add a new node at the position index

INode get_HeadNode(); // return the first node in the list

int get_size(); // return the number of nodes in the list

}

Interface INode {

void set_Data(char c);

char get_Data();

vod set_Pred(INode n);

void set_Succ(INode n) ;

INode get_Pred();

INode get_Succ();

}





There are two methods you need to apply the singleton pattern:

Class Stack is an implementation of a class that only allows one instantiation of a subclass. And the constructor in a subclass must be private and your implementation must fulfill the open-close principle when a new sub-class is created after your implementation. Implemented by SubClassName1. (use Java reflection)
Class Stack is an implementation of a class that only allows one instantiation of a subclass. This version requires its subclasses to provide an implementation of a static instance() method. And the constructor in a subclass must be private. Implemented by SubClassName2. (don’t need to use Java reflection)
To test your private constructor, we will test any object creation via a constructor is illegal.

class Application {

public static void main(){

// use the singleton pattern to create objects with their class names, connect the objects together via using the setter method appropriately, check the input string, and print out the result in the console; print out whether the object exists or not and its type via the console when the singleton method instance() is called;

……………
}





Requirements for PA3,

You must use the Eclipse IDE to create a Java project.
You must follow the instruction to submit your Java project (http://www.cs.wmich.edu/~wwshen/cs1120_Fall2012/documents/HowtoSubmitPAinEclipse.pdf).
Study the slides of 10/2 about the subtype substitution principle. Number all locations where type checking is performed by the Java compiler. As of output, for each location, you use a line comment to provide the subtype relation between the two types as well as you export all the type checking information to a text file as part of your Java project.








More products