Git Product home page Git Product logo

mini-word-processor-java's Introduction

Mini-Word-Processor

Using Java Collection - Stack to implement a mini-word processor

For this assignment you will be writing a mini-word processor. You are mainly concerned with inserting characters, deleting characters and positioning the cursor. If you think about it, that's mostly what the user does when entering or editing text. The user only adds and deletes characters next to the cursor. You can therefore get away with using two stacks. One stack holds the characters to the left of the cursor. The other stack holds the characters to the right of the cursor. This diagram shows how to represent the word elephantine with the cursor between the letters p and h: LEFT STACK RIGHT STACK ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ |e|l|e|p| |h|a|n|t|i|n|e| bottom top top bottom To move the cursor right, you would just pop the h from the right stack and push it onto the left stack:

     LEFT STACK               RIGHT STACK
     ___ ___ ___ ___ ___       ___ ___ ___ ___ ___ ___
|_e_|_l_|_e_|_p_|_h_|     |_a_|_n_|_t_|_i_|_n_|_e_|
bottom            top     top                bottom

Build a small word-processor class that uses this two-stack representation. The class will include methods for inserting and deleting characters, and for moving the cursor. To help you along, you will implement the MiniWPI interface that is linked here. Your MiniWP constructor must be able to take in an initial string. The default will initialize an empty string. To test your class, you will retrieve the commands from a Queue then execute them. Make sure you use appropriate exception handling such as dealing with an empty stack, entering invalid commands into the queue, etc. Sample output for part 2 For the following commands: commandqueue.put("insert J"); commandqueue.put("insert K"); commandqueue.put("insert L"); commandqueue.put("move left"); commandqueue.put("move right"); commandqueue.put("move left"); commandqueue.put("move left"); commandqueue.put("search K"); This would be the output: Starting Word processor!

Initial: [i, n, i, t, i, a, l, , c, o, n, t, e, n, t, s]|[] insert J: [i, n, i, t, i, a, l, , c, o, n, t, e, n, t, s, J]|[] insert K: [i, n, i, t, i, a, l, , c, o, n, t, e, n, t, s, J, K]|[] insert L: [i, n, i, t, i, a, l, , c, o, n, t, e, n, t, s, J, K, L]|[] move left: [i, n, i, t, i, a, l, , c, o, n, t, e, n, t, s, J, K]|[L] move right: [i, n, i, t, i, a, l, , c, o, n, t, e, n, t, s, J, K, L]|[] move left: [i, n, i, t, i, a, l, , c, o, n, t, e, n, t, s, J, K]|[L] move left: [i, n, i, t, i, a, l, , c, o, n, t, e, n, t, s, J]|[K, L] search K: [i, n, i, t, i, a, l, , c, o, n, t, e, n, t, s, J, K]|[L] Press any key to continue . . .

mini-word-processor-java's People

Contributors

xiunhon avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.