Sale!

Assignment 6 CSC300 solved

$30.00 $18.00

Original Work ?

Download Details:

  • Name: AssignmentSix-ws5fgh.zip
  • Type: zip
  • Size: 299.25 KB

Category: Tags: , You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (1 vote)

In the class, you used the **Stacks class** to write a method that recognizes palindromes, where palindromes are strings that read the same backward as forward. However, another kind of palindrome exists in which we examine words rather than individual letters. A word-by-word palindrome is a string of words in which the words read the same forward and backward. For example, the quote “You can cage a swallow, can’t you, but you can’t swallow a cage, can you?” is a word-by-word palindrome, i.e. and modify the Dequeter class (Question 4.2) to write a program that tests an input string and declares whether it is a word-by-word palindrome. Consider upper-and lowercase letters to be the same letter. Define a word as any string consisting of only letters or an apostrophe and bounded at each end with one of the following: a space or the end of the line. Your program should feature user-friendly interface and allow a user to check more lines until she wishes to quit the program. You are free to use any Java string tokenizer of your choice for word splitting.

### – Dequeter class:

class Deque
{
private int maxSize;
private long[] dekArray;
private int left;
private int right;
private int nItems;
//—
public Deque(int s) // constructor
{
maxSize = s;
dekArray = new long[maxSize];
int center = maxSize/2 – 1;

left = center+1; // left and right
right = center; // start out “crossed”
nItems = 0;
}

//—
public void insertLeft(long j) // put item at left of deque
{
if(left == 0) // deal with wraparound
left = maxSize;
dekArray[–left] = j; // insert and decrement left
nItems++; // one more item
}

//—
public void insertRight(long j) // put item at right of deque
{
if(right == maxSize-1) // deal with wraparound
right = -1;
dekArray[++right] = j; // insert and increment right
nItems++; // one more item
}

//—
public long removeLeft() // take item from left of deque
{
long temp = dekArray[left++]; // get value and incr left
if(left == maxSize) // deal with wraparound
left = 0;
nItems–; // one less item
return temp;
}

//—
public long removeRight() // take item from right of deque
{
long temp = dekArray[right–]; // get value and decr right
if(right == -1) // deal with wraparound
right = maxSize-1;
nItems–; // one less item
return temp;
}

//—
public boolean isEmpty() // true if deque is empty
{ return (nItems==0); }

//—
public boolean isFull() // true if deque is full
{ return (nItems == maxSize); }

//—
public int size() // number of items in deque
{ return nItems; }

//—
public void display()
{
System.out.print(“Array: “);
for(int j=0; j<maxSize; j++) // print array contents
System.out.print(dekArray[j] + ” “);
System.out.println(“”);

System.out.print(“Deque: “);
if(left <= right) // print deque contents
for(int j=left; j<=right; j++) System.out.print(dekArray[j] + ” “);
else if( isEmpty() == false )
{
for(int j=left; j<maxSize; j++) System.out.print(dekArray[j] + ” “);
for(int j=0; j<=right; j++) System.out.print(dekArray[j] + ” “);
}
System.out.println(“”);
} // end display()
//—
} // end class Deque

**Notes:**

1. The program must compile without syntax errors; 50% of the assignment points will be deducted if your program does not compile, even if your program is “essentially” correct.
2. To get full credit for an assignment, your program must solve the assignment problem completely.
3. Please add comments to the source code. Your program should have a reasonable amount of comments.
4. At the very beginning of each file, there should be a block comment containing the student name, course number, and assignment number.
5. Follow the programming styles and guidelines discussed in class, such as using meaningful names for variables and camel case conventions for variables, classes, etc.
6. Using ChatGPT or any LLM is not allowed. Your code will be examined if written using an AI tool.
7. To submit your Java files on Moodle:
a. Create a folder with your last name.
b. Place your java files inside the folder.
c. Zip the folder.
d. Upload it to Moodle.