1. Homepage
  2. Programming
  3. CISC124 Introduction to Computing Science II Assignment 5: Using interfaces and inheritance

CISC124 Introduction to Computing Science II Assignment 5: Using interfaces and inheritance

Engage in a Conversation
JavaUsing interfaces and inheritanceCISC124Introduction to Computing Science IICanadaQueens University

CISC124 Assignment 5: Using interfaces and inheritance

Instructions

Download and save this eclipse project archive file but do not extract it. Copy or move the file into the assignment directory on your computer. CourseNana.COM

In eclipse, import the project archive using the following steps: CourseNana.COM

  1. Under the File menu choose Import…
  2. Under General choose Existing Projects into Workspace
  3. Click the radio button beside Select archive file and browse for the zip file A5_project.zip
  4. Make sure that the project A5 appears in the list of projects and has a check mark beside it.
  5. Click Finish to import the project.

Submitting your work

Submit your work on onq under Assignment 4. You should upload two files: CourseNana.COM

  • WidthWrapper.java
  • SpacesWrapper.java
  • FlushLefttJustifier.java
  • FlushRightJustifier.java
  • CenterJustifier.java

DO NOT upload a zip file containing your work. Doing so greatly slows down the processing of assignments, and you will receive a grade of zero on this assignment if you do so. CourseNana.COM

Your classes should both be in the package a5 (the same package that they appear in in the project file). DO NOT change the package name or remove the package name from your files. CourseNana.COM

Marking

Marking is based primarily on the correctness of your submitted files. Each file has a grading weight as shown below: CourseNana.COM

  • 35% WidthWrapper.java
  • 35% SpacesWrapper.java
  • 10% FlushLeftJustifier.java
  • 10% FlushRightJustifier.java
  • 10% CenterJustifier.java

Background information

Wrapping text

Many text-based applications require the ability to wrap text to a fixed column width. Wrapping text involves breaking the text into separate lines so that the length of each line (ideally) is less than some specified maximum width. For example, the following text: CourseNana.COM

Of course you have a purpose -- to find a purpose.

can be wrapped to lines all having a width of exactly 15 like so (a numbered bar is included below to indicate the column width): CourseNana.COM

123456789012345

Of course you h
ave a purpose -
- to find a pur
pose.

Alternatively, if the text represents written English, it might be preferable to break the lines at spaces like so: CourseNana.COM

123456789012345

Of course you
have a purpose
-- to find a
purpose.

Notice that in the above example, each line is as long as possible but no longer than 15 characters wide, and no word is split over two lines. CourseNana.COM

If the width is too small, then breaking the lines at spaces may not always be possible. In this case, we might choose to break at spaces when we can, and otherwise break in the middle of a word when we have no other choice. For example, wrapping the example text to a width of 5 might produce: CourseNana.COM

12345

Of
cours
e
you
have
a
purpo
se
--
to
find
a
purpo
se.

In the output above, some lines are shorter than 5 characters because there is a space where the line can be broken at, and some lines are exactly 5 characters long because there are no spaces where the line can be broken at. CourseNana.COM

Examples of programs that employ word wrapping include: CourseNana.COM

  • eclipse wraps lines of code longer than 80 characters when the user asks eclipse to format their code; the line wrapping strategy employed by eclipse needs to be aware of the programming language so that it does not break lines in locations where a syntax error would occur
  • PowerPoint (and other word processing programs) wraps lines of text as you type
    • if you enter text in a narrow text box, PowerPoint tries to break lines at spaces if it can; otherwise, it breaks lines at the width of the text box
  • web browsers must dynamically wrap lines of text as the size of browser window is changed (for example, when the user rotates their mobile device)

Justifying text

Justification or alignment of text determines how text is aligned to the width of a page or column. Common types of alignment include: CourseNana.COM

  • flush left, or left justified, where the beginning of the text is aligned with the left side of the column,
  • flush right, or right justified, where the end of the text is aligned with the right side of the column, and
  • center where the text is aligned to the middle of the column

For our purposes, justifying a string involves adding spaces to parts of the string so that the length of the string is equal to the column width. CourseNana.COM

Justification typeSpaces are added to…
flush leftthe end of the string
flush rightthe front of the string
centerthe front and end of the string

In center justification, an equal number of spaces are added to the front and end of the string if possible; if not, then the end of the string contains one more space than the front of the string. CourseNana.COM

Consider justifying the string 12345 to a column of width 10. The following table illustrates the justified string using . to indicate an added space character. CourseNana.COM

Justification typeResulting string
flush left12345.....
flush right.....12345
center..12345...

Question

This assignment illustrates the use of inheritance and interfaces to create hierarchy of classes to perform text wrapping and justification. Inheritance is used to create different types of text wrappers and interfaces are used to create different types of text justifiers, but either approach (or a combination of the two) could be used to solve the text wrapping and justification problems. CourseNana.COM

Text wrapping

Implement the following class hierarchy: CourseNana.COM

CourseNana.COM

The AbstractStringWrapper class is already implemented. Study the implementation so that you understand what fields and methods it provides for its subclasses to use. In particular, read the contract for the method wrap() for instructions on how subclasses are expected to store the wrapped lines of text. CourseNana.COM

WidthWrapper

The WidthWrapper class wraps strings so that each line of the wrapped text is exactly equal to the desired maximum width, except for possibly the last line of the wrapped text. It pays no attention to spaces in the string that is being wrapped. CourseNana.COM

The main method should output the following: CourseNana.COM

width:30, lines: 1, lines = [ABCDEFGHIJKLMNOPQRSTUVWXYZ]

width:20, lines: 2, lines = [ABCDEFGHIJKLMNOPQRST, UVWXYZ]

width: 5, lines: 6, lines = [ABCDE, FGHIJ, KLMNO, PQRST, UVWXY, Z]

width: 1, lines:26, lines = [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z]

SpacesWrapper

The SpacesWrapper class wraps strings by breaking lines so that each line of the wrapped text is as long as possible, up to the desired maximum width, trying to break lines at spaces. If a wrapped line has no spaces in it, then the line is broken at the desired maximum width. If a wrapped line has one or more spaces located before or at the desired maximum width, then the line is broken at the last space before or at the desired maximum width. CourseNana.COM

The main method should output the following: CourseNana.COM

width:30, lines: 1, lines = [ABC DEFGH I JKLMNOPQ RSTUVWXYZ]

width:20, lines: 2, lines = [ABC DEFGH I JKLMNOPQ, RSTUVWXYZ]

width: 5, lines: 7, lines = [ABC, DEFGH, I, JKLMN, OPQ, RSTUV, WXYZ]

width: 1, lines:26, lines = [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z]

Text justification

Study the implementation and documentation of the TextJustifier interface. CourseNana.COM

Implement the classes FlushLeftJustifier, FlushRightJustifier, and CenterJustifier. CourseNana.COM

The String method repeat is useful, but not required, when implementing the justifier classes. CourseNana.COM

Cowsay

The cowsay program is a Linux program that prints a cow (or other figure) saying some string provided the user. The user of the program can control the width of the printed text; thus, cowsayrequires the ability to wrap text. CourseNana.COM

The Cowsay.java program included in the project archive is a simple version of the cowsay program. It uses a string wrapping class and a string justifier class to wrap and justify a message and then prints the message like so: CourseNana.COM

   Of course you    
   have a purpose   
    -- to find a    
      purpose.      
       \
        \   ^__^
         \  (oo)\_______
            (__)\\       )\\/\\
                ||----w |
                ||     ||

You can edit the message, the wrapped line length, and change the classes that perform the wrapping and justification by editing the main method of the program after you have completed the assignment question. CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
Java代写,Using interfaces and inheritance代写,CISC124代写,Introduction to Computing Science II代写,Canada代写,Queens University代写,Java代编,Using interfaces and inheritance代编,CISC124代编,Introduction to Computing Science II代编,Canada代编,Queens University代编,Java代考,Using interfaces and inheritance代考,CISC124代考,Introduction to Computing Science II代考,Canada代考,Queens University代考,Javahelp,Using interfaces and inheritancehelp,CISC124help,Introduction to Computing Science IIhelp,Canadahelp,Queens Universityhelp,Java作业代写,Using interfaces and inheritance作业代写,CISC124作业代写,Introduction to Computing Science II作业代写,Canada作业代写,Queens University作业代写,Java编程代写,Using interfaces and inheritance编程代写,CISC124编程代写,Introduction to Computing Science II编程代写,Canada编程代写,Queens University编程代写,Javaprogramming help,Using interfaces and inheritanceprogramming help,CISC124programming help,Introduction to Computing Science IIprogramming help,Canadaprogramming help,Queens Universityprogramming help,Javaassignment help,Using interfaces and inheritanceassignment help,CISC124assignment help,Introduction to Computing Science IIassignment help,Canadaassignment help,Queens Universityassignment help,Javasolution,Using interfaces and inheritancesolution,CISC124solution,Introduction to Computing Science IIsolution,Canadasolution,Queens Universitysolution,