Skip to content

Commit

Permalink
not working
Browse files Browse the repository at this point in the history
  • Loading branch information
ShobhitMaheshwari committed Jan 22, 2017
1 parent 586c0c1 commit ece0ed7
Show file tree
Hide file tree
Showing 17 changed files with 679 additions and 29 deletions.
8 changes: 0 additions & 8 deletions example/MojiEclipseQuickStart/.classpath

This file was deleted.

17 changes: 0 additions & 17 deletions example/MojiEclipseQuickStart/.project

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file removed example/MojiEclipseQuickStart/lib/moji-1.0.2.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public static void main(String[] args) throws Exception {
// a list of students' source code files located in the prepared
// directory.
Collection<File> files = FileUtils.listFiles(new File(
"C:\\temp\\moss-dir"), new String[] { "java" }, true);
"src/main/resources/files"), new String[] { "java" }, true);

// a list of base files that was given to the students for this
// assignment.
Collection<File> baseFiles = FileUtils.listFiles(new File(
"C:\\temp\\moss-base-dir"), new String[] { "java" }, true);
"src/main/resources/Base"), new String[] { "java" }, true);

// get a new socket client to communicate with the MOSS server
// and set its parameters.
Expand Down
40 changes: 40 additions & 0 deletions src/main/resources/Base/FileIO/FileIO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//-----------------------------------------------------------------------------
// FileIO.java
// Illustrates file IO and tokenization using String.split()
//-----------------------------------------------------------------------------

import java.io.*;
import java.util.Scanner;

class FileIO{
public static void main(String[] args) throws IOException{
Scanner in = null;
PrintWriter out = null;
String line = null;
String[] token = null;
int i, n, lineNumber = 0;

if(args.length < 2){
System.err.println("Usage: FileIO infile outfile");
System.exit(1);
}

in = new Scanner(new File(args[0]));
out = new PrintWriter(new FileWriter(args[1]));

while( in.hasNextLine() ){
lineNumber++;
line = in.nextLine()+" "; // add extra space so split works right
token = line.split("\\s+"); // split line around white space
n = token.length;
out.println("Line "+lineNumber+" contains "+n+" token"+(n==1?"":"s")+":");
for(i=0; i<n; i++){
out.println(token[i]);
}
out.println();
}

in.close();
out.close();
}
}
25 changes: 25 additions & 0 deletions src/main/resources/Base/FileIO/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#------------------------------------------------------------------------------
# Makefile for FileIO
#------------------------------------------------------------------------------

MAINCLASS = FileIO
JAVAC = javac -Xlint
JAVASRC = $(wildcard *.java)
SOURCES = $(JAVASRC) Makefile README
CLASSES = $(patsubst %.java, %.class, $(JAVASRC))
JARCLASSES = $(patsubst %.class, %*.class, $(CLASSES))
JARFILE = $(MAINCLASS)

all: $(JARFILE)

$(JARFILE): $(CLASSES)
echo Main-class: $(MAINCLASS) > Manifest
jar cvfm $(JARFILE) Manifest $(JARCLASSES)
chmod +x $(JARFILE)
rm Manifest

%.class: %.java
$(JAVAC) $<

clean:
rm -f *.class $(JARFILE)
59 changes: 59 additions & 0 deletions src/main/resources/Base/ListClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//-----------------------------------------------------------------------------
// ListClient.java
// A test client for the List ADT. Use this to test your list module. The
// correct output is given below.
//-----------------------------------------------------------------------------

public class ListClient{
public static void main(String[] args){
List A = new List();
List B = new List();

for(int i=1; i<=20; i++){
A.append(i);
B.prepend(i);
}
System.out.println(A);
System.out.println(B);

for(A.moveFront(); A.index()>=0; A.moveNext()){
System.out.print(A.get()+" ");
}
System.out.println();
for(B.moveBack(); B.index()>=0; B.movePrev()){
System.out.print(B.get()+" ");
}
System.out.println();

List C = A.copy();
System.out.println(A.equals(B));
System.out.println(B.equals(C));
System.out.println(C.equals(A));

A.moveFront();
for(int i=0; i<5; i++) A.moveNext(); // at index 5
A.insertBefore(-1); // at index 6
for(int i=0; i<9; i++) A.moveNext(); // at index 15
A.insertAfter(-2);
for(int i=0; i<5; i++) A.movePrev(); // at index 10
A.delete();
System.out.println(A);
System.out.println(A.length());
A.clear();
System.out.println(A.length());
}
}

// Output of this program:
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// false
// false
// true
// 1 2 3 4 5 -1 6 7 8 9 11 12 13 14 15 -2 16 17 18 19 20
// 21
// 0


25 changes: 25 additions & 0 deletions src/main/resources/Base/Queue/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#------------------------------------------------------------------------------
# Makefile for Queue
#------------------------------------------------------------------------------

MAINCLASS = QueueTest
JAVAC = javac -Xlint
JAVASRC = $(wildcard *.java)
SOURCES = $(JAVASRC) Makefile README
CLASSES = $(patsubst %.java, %.class, $(JAVASRC))
JARCLASSES = $(patsubst %.class, %*.class, $(CLASSES))
JARFILE = $(MAINCLASS)

all: $(JARFILE)

$(JARFILE): $(CLASSES)
echo Main-class: $(MAINCLASS) > Manifest
jar cvfm $(JARFILE) Manifest $(JARCLASSES)
chmod +x $(JARFILE)
rm Manifest

%.class: %.java
$(JAVAC) $<

clean:
rm -f *.class $(JARFILE)
160 changes: 160 additions & 0 deletions src/main/resources/Base/Queue/Queue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
//-----------------------------------------------------------------------------
// Queue.java
// An integer queue ADT
//
// This file constitutes the solution to the first excercise in the ADT handout.
// Recall that all ADT operations must state their own preconditions in a comment
// block, then check that those conditions are satisfied. If a precondition is
// violated, the ADT operation should cause the program to quit with a useful error
// message. See functions getFront() and Dequeue() below for examples on how to do
// this. Observe that we've added two other operations called equals() and copy().
//
//-----------------------------------------------------------------------------

class Queue{

private class Node{
// Fields
int data;
Node next;

// Constructor
Node(int data) { this.data = data; next = null; }

// toString(): overrides Object's toString() method
public String toString() {
return String.valueOf(data);
}

// equals(): overrides Object's equals() method
public boolean equals(Object x){
boolean eq = false;
Node that;
if(x instanceof Node){
that = (Node) x;
eq = (this.data==that.data);
}
return eq;
}
}

// Fields
private Node front;
private Node back;
private int length;

// Constructor
Queue() {
front = back = null;
length = 0;
}


// Access Functions --------------------------------------------------------

// isEmpty()
// Returns true if this Queue is empty, false otherwise.
boolean isEmpty() {
return length==0;
}

// getLength()
// Returns length of this Queue.
int getLength() {
return length;
}

// getFront()
// Returns front element.
// Pre: !this.isEmpty()
int getFront(){
if( this.isEmpty() ){
throw new RuntimeException(
"Queue Error: getFront() called on empty Queue");
}
return front.data;
}

// Manipulation Procedures -------------------------------------------------

// Enqueue()
// Appends data to back of this Queue.
void Enqueue(int data){
Node N = new Node(data);
if( this.isEmpty() ) {
front = back = N;
}else{
back.next = N;
back = N;
}
length++;
}

// Dequeue()
// Deletes front element from this Queue.
// Pre: !this.isEmpty()
void Dequeue(){
if(this.isEmpty()){
throw new RuntimeException(
"Queue Error: Dequeue() called on empty Queue");
}
if(this.length>1){
front = front.next;
}else{
front = back = null;
}
length--;
}


// Other Functions ---------------------------------------------------------

// toString()
// Overides Object's toString() method.
public String toString(){
StringBuffer sb = new StringBuffer();
Node N = front;
while(N!=null){
sb.append(" ");
sb.append(N.toString());
N = N.next;
}
return new String(sb);
}

// equals()
// Overrides Object's equals() method. Returns true if x is a Queue storing
// the same integer sequence as this Queue, false otherwise.
public boolean equals(Object x){
boolean eq = false;
Queue Q;
Node N, M;

if(x instanceof Queue){
Q = (Queue)x;
N = this.front;
M = Q.front;
eq = (this.length==Q.length);
while( eq && N!=null ){
eq = N.equals(M);
N = N.next;
M = M.next;
}
}
return eq;
}

// copy()
// Returns a new Queue identical to this Queue.
Queue copy(){
Queue Q = new Queue();
Node N = this.front;

while( N!=null ){
Q.Enqueue(N.data);
N = N.next;
}
return Q;
}

}
32 changes: 32 additions & 0 deletions src/main/resources/Base/Queue/QueueTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//-----------------------------------------------------------------------------
// QueueTest.java
// A test client for the Queue ADT
//-----------------------------------------------------------------------------

class QueueTest{
public static void main(String[] args){
Queue A = new Queue();
Queue B = new Queue();
Queue C;

for(int i=1; i<=10; i++){
A.Enqueue(i);
B.Enqueue(11-i);
}
System.out.println("A = " + A);
System.out.println("B = " + B);

for(int i=1; i<=6; i++){
A.Enqueue(B.getFront());
B.Dequeue();
}
System.out.println("A = " + A);
System.out.println("B = " + B);
C = A.copy();
System.out.println("C = " + C);
System.out.println("A " + (A.equals(B)?"equals":"does not equal") + " B");
System.out.println("A " + (A.equals(C)?"equals":"does not equal") + " C");
}
}


Loading

0 comments on commit ece0ed7

Please sign in to comment.