Question

1. Build the windowing interface shown below (most of us did this in class)

scramble

2. The user will input a sentence in the upper textbox.

3. When Scramble is clicked the following steps will occur

A. words in the sentence will be found and put into an array.

B. The array length will be used to place the words into a second array in random order.

C. The words from the second array will be used to fill in the textbox or label on the right listing the words one per line.

D. The words from the second array will be used to rebuild the sentence with spaces between the words.

E. The scrambled sentence will be displayed in the bottom box.

8. The textboxes or labels can be cleared with the clear button and a new sentence scrambled.SWT Application Type a sentence Scramble Clear Scrambled Sentence

0 0
Add a comment Improve this question Transcribed image text
Answer #1
package com.pivovarit.stream;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Objects;
import java.util.Queue;
import java.util.Spliterator;
import java.util.function.Consumer;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public class SlidingWindowSpliterator<T> implements Spliterator<Stream<T>> {
    static <T> Stream<Stream<T>> windowed(Collection<T> stream, int windowSize) {
   return StreamSupport.stream(
new SlidingWindowSpliterator<>(stream, windowSize), false);
    }
private final Queue<T> buffer;
private final Iterator<T> sourceIterator;
private final int windowSize;
private final int size;
private SlidingWindowSpliterator(Collection<T> source, int windowSize) {
this.buffer = new ArrayDeque<>(windowSize);
this.sourceIterator = Objects.requireNonNull(source).iterator();
this.windowSize = windowSize;
this.size = calculateSize(source, windowSize);
    }
@Override
public boolean tryAdvance(Consumer<? super Stream<T>> action) {
        if (windowSize < 1) {
return false;
  }
        while (sourceIterator.hasNext()) {
buffer.add(sourceIterator.next());
            if (buffer.size() == windowSize) {
  action.accept(Arrays.stream((T[]) buffer.toArray(new Object[0])));
buffer.poll();
   return sourceIterator.hasNext();
 }
  }
        return false;
}
@Override
public Spliterator<Stream<T>> trySplit() {
        return null;
    }
    @Override
    public long estimateSize() {
        return size;
 }
 @Override
public int characteristics() {
        return ORDERED | NONNULL | SIZED;
    }
private static int calculateSize(Collection<?> source, int windowSize) {
 return source.size() < windowSize
  ? 0
: source.size() - windowSize + 1;
}
Add a comment
Know the answer?
Add Answer to:
1. Build the windowing interface shown below (most of us did this in class) 2. The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an...

    Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an order at a fast-food burger joint. This class will be used in Part B, when we work with a list of orders. As vou work through this part and Part B, draw a UML diagram of each class in using the UML drawing tool 1) Create a new Lab5TestProject project in Netbeans, right-click on the lab5testproject package and select New>Java Class 2) Call your...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT