Question

Objectives Problem solving using arrays and ArrayLists. Abstraction. Overview The diagram below illustrates a banner constructed...

Objectives

Problem solving using arrays and ArrayLists. Abstraction.

Overview

The diagram below illustrates a banner constructed from block-letters of size 7. Each block-letter is composed of 7 horizontal line-segments of width 7 (spaces included):

Objectives Problem solving using arrays and ArrayL
SOLID                        as in block-letters F, I, U, M, A, S and the blurb RThere are six distinct line-segment types:

TRIPLE                      as in block-letter M

DOUBLE                   as in block-letters U, M, A

LEFT_DOT                as in block-letters F, S

CENTER_DOT          as in block-letter I

RIGHT_DOT as in block-letter S

You must complete implementations of classes LineSegment, BlockLetter, andBanner.

Specific Requirements

The enum type SegmentType is already implemented. Its values may be referenced as SegmentType.TRIPLE, SegmentType.CENTER_DOT, etc.

2.The LineSegment class represents a line-segment of one of the 6 types

Instance variable: a String of space and dot characters

Implement public methods: length() and toString().

Implement a constructor helper method for each different type ofLineSegment.

3.The BlockLetter class represents an uppercase block-letter

Instance variable: an array of LineSegment elements.

Implement public methods: size(), toString() and getSegment(int index).

Method getSegment(int index) returns a LineSegment element selected byindex.

Implement a constructor helper for letters: A, C, E, F, H, I, L, M, O, P, S, T, U, W

The (default) implementation of any unrepresented character is a blurb -- aBlockLetter with all LineSegments of type SegmentType.SOLID, and using the character itself as the print-symbol of its LineSegments. (R in the diagram above)

4.The Banner class represents a character string in block-letters

Instance variable: an ArrayList of BlockLetter elements.

Implement the constructors and the toString() method only.

BANNERCLIENT:

public class BannerClient
{
public static void main(String[] args)
{
System.out.println( new Banner("MIAMI RULES", 7) );
System.out.println();
System.out.println( new Banner("FIU PANTHERS", 11, 'x') );
}
}

BANNER CLASS:

import java.util.*;
import javax.swing.*;
public class Banner
{
//Instance Variable - A collection of BlockLetter elements
private ArrayList letters;

//Constructor
// @param words : The content of this Banner
// @param height: Height of the letters in this Banner
// default is to construct each letter using the letter
// itself as the print-symbol in each BlockLetter
public Banner(String words, int height)
{
}

//Constructor
// @param words : The content of this Banner
// @param height: Height of the letters in this Banner
// @param symbol: Print-symbol used in all BlockLetter s
public Banner(String words, int height, char symbol)
{
}

public String toString()
{
String image = "";
return image;
}
}

BLOCKLETTER:

//An instance of this class represents a block letter
//Full BlockLetter representations are provided for
// A, C, E, F, H, I, L, M, O, P, S, T, U, W
//All other characters are represented as "blurbs",
// solid lines composed of the character
public class BlockLetter
{
public static final int MIN_SIZE = LineSegment.MIN_WIDTH;

//Instance Variable: a collection of LineSegment elements
private LineSegment[] block;

//Constructor
// @param letter: the character represented by this BlockLetter
// default size : MIN_SIZE
// default print_symbol : the letter
public BlockLetter(char letter)
{
this(letter, MIN_SIZE);
}

//Constructor
// @param letter: the character represented by this BlockLetter
// @param size : size of this BlockLetter, odd number >= MIN_SIZE
// default print_symbol : the letter
public BlockLetter(char letter, int size)
{
this(letter, size, letter);
}

//Constructor
// @param letter: the character represented by this BlockLetter
// @param size : size of this BlockLetter, odd number >= MIN_SIZE
// @param symbol: the "dot"/character used in the LineSegments
public BlockLetter(char letter, int size, char symbol)
{
if (size < MIN_SIZE)
throw new RuntimeException("Minimum Size is " + MIN_SIZE);

if (size % 2 == 0)
size = size + 1;
  
switch ( letter )
{
default : blurb(letter);
}
}

//Accessor - returns a selected LineSegment of this BlockLetter
// @param index: 0 .. this.size()-1, selects a LineSegment
public LineSegment getSegment(int index)
{
return null;
}

//Returns the number of LineSegments in this BlockLetter
public int size()
{
return 0;
}

//Override - returns a printable image of this BlockLetter
public String toString()
{
return "";
}
  
private void blurb(char symbol)
{
}

//*************************************************************
// Throw-away tester
public static void main(String[] args)
{
String chars = "ACEFHILMOPSTUWX";
for (int i = 0; i < chars.length(); i++)
System.out.println( new BlockLetter(chars.charAt(i))
+ "\n" );
}
}

LINESEGMENT:

public class LineSegment
{
public final static int MIN_WIDTH = 5;

//Instance Variable
private final String segment;

//Constructor - create a LineSegment of some given SegmentType
// @param type: the type of this LineSegment
// @param width: the width of this LineSegment, an odd integer
// @param dot: the character used in constructing this LineSegment
// RuntimeExcption thrown if the requested width is even or < MIN_WIDTH
public LineSegment(SegmentType type, int length, char dot)
{
if (length < MIN_WIDTH || length % 2 == 0)
throw new RuntimeException("Width must be odd, >= " + MIN_WIDTH);

switch ( type )
{
case SOLID : segment = solid(length, dot); break;
case TRIPLE : segment = triple(length, dot); break;
case DOUBLE : segment = doubles(length, dot); break;
case LEFT_DOT : segment = leftDot(length, dot); break;
case CENTER_DOT: segment = centerDot(length, dot); break;
case RIGHT_DOT : segment = rightDot(length, dot); break;
default : segment = "";
}
}

//Return the length (width) of this LineSegment
public int length()
{
return 0;
}

//Override - returns a printable image of this LineSegment
public String toString()
{
return "";
}

//*************************CONSTRUCTOR HELPERS***********************

//Return a SegmentType.SOLID LineSegment
// @param width: The width/length of this SOLID LineSegment
// @param dot: The symbol used in constructing this LineSegment
private String solid(int width, char dot)
{
return "";
}

//Return a SegmentType.TRIPLE LineSegment
// @param width: The width/length of this LineSegment
// @param dot: The symbol used in constructing this LineSegment
private String triple(int width, char dot)
{
return "";
}

//Return a SegmentType.DOUBLE LineSegment
// @param width: The width/length of this LineSegment
// @param dot: The symbol used in constructing this LineSegment
private String doubles(int width, char dot)
{
return "";
}

//Return a SegmentType.LEFT_DOT LineSegment
// @param width: The width/length of this LineSegment
// @param dot: The symbol used in constructing this LineSegment
private String leftDot(int width, char dot)
{
return "";
}

//Return a SegmentType.CENTER_DOT LineSegment
// @param width: The width/length of this LineSegment
// @param dot: The symbol used in constructing this LineSegment
private String centerDot(int width, char dot)
{
return "";
}

//Return a SegmentType.RIGHT_DOT LineSegment
// @param width: The width/length of this LineSegment
// @param dot: The symbol used in constructing this LineSegment
private String rightDot(int width, char dot)
{
return "";
}
}

SEGMENTTYPE:

public enum SegmentType
{
//Width 7 Examples
SOLID, // *******
TRIPLE, // * * *
DOUBLE, // * *
LEFT_DOT, // *
CENTER_DOT, // *   
RIGHT_DOT; // *
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class LineSegment
{
public static final int SOLID = 0;
public static final int LEFT_END = 1;

private int style;
private int width;
private char symbol;
private String segment;

public LineSegment(int style, int width, char symbol)
{
this.style = style;
this.width = width;
this.symbol = symbol;
switch(style)
{
case 1 : makeLEFT_ENDSegment(); break;
default : makeSOLIDSegment();
}
}
private void makeSOLIDSegment()
{
this.segment = "";
for(int k=0;k<=width;k++)
segment += symbol;
}
private void makeLEFT_ENDSegment()
{
segment = "" + symbol;
for(int k=1;k<=width-1;k++)
segment += "";
}
public String toString()
{
return segment;
}
}

public class BlockLetter
{
private LineSegment[]block;
private char letter;
private char symbol;
private int size;

public BlockLetter(char letter, char symbol, int size)
{
this.letter=letter;
this.symbol = symbol;
this.size = size;
this.block=new LineSegment[size];
switch( letter )
{
case 'L' : build_L(); break;
default : buildBlockLetter();
}
}
private void build_L()
{
for(int row=0;row<this.size-1;row++)
block[row] = new LineSegment(LineSegment.LEFT_E...
block[block.length-1] = new LineSegment(LineSegment.SOLID,...
}
public LineSegment getSegment(int row)
{
return block[row];
}

private void buildBlockLetter()
{
for(int row=0; row<this.size; row++)
{
this.block[row] = new LineSegment(LineSegment.SOLID,...
}
}
public String toString()
{
??;
}
}

public class BlockLetterTest
{
public static void main(String args[])
{
System.out.println( new BlockLetter('L', '*', 7) );
}
}

Add a comment
Know the answer?
Add Answer to:
Objectives Problem solving using arrays and ArrayLists. Abstraction. Overview The diagram below illustrates a banner constructed...
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
  • Hi I really need help with the methods for this lab for a computer science class....

    Hi I really need help with the methods for this lab for a computer science class. Thanks Main (WordTester - the application) is complete and only requires uncommenting to test the Word and Words classes as they are completed. The needed imports, class headings, method headings, and block comments are provided for the remaining classes. Javadocs are also provided for the Word and Words classes. Word The Word class represents a single word. It is immutable. You have been provided...

  • Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java...

    Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java //package simple; public class PartTest { public static void main(String[] args) { ArrayList<ExpendablePart> system=new ArrayList<ExpendablePart>();   // creating Part Object Part part1 = new ExpendablePart("Last, First"); part1.setNumber("AX-34R"); part1.setNcage("MN34R"); part1.setNiin("ABCD-RF-WDE-KLJM"); // printing information System.out.println(part1.toString());       //Create a part2 object of class Part Part part2=new ConsumablePart("Widget, purple"); part2.setNumber("12345"); part2.setNcage("OU812"); part2.setNiin("1234-12-123-1234");    // printing information System.out.println(part2.toString());    //checking equality of two Part class objects if(part1.equals(part2)) System.out.println("part1 and...

  • I need help with this. I need to create the hangman game using char arrays. I've...

    I need help with this. I need to create the hangman game using char arrays. I've been provided with the three following classes to complete it. I have no idea where to start. HELP!! 1. /** * This class contains all of the logic of the hangman game. * Carefully review the comments to see where you must insert * code. * */ public class HangmanGame { private final Integer MAX_GUESSES = 8; private static HangmanLexicon lexicon = new HangmanLexicon();...

  • Need help coding this List. Lists are a lot like arrays, but you’ll be using get,...

    Need help coding this List. Lists are a lot like arrays, but you’ll be using get, set, add, size and the like instead of the array index operators [].​ package list.exercises; import java.util.List; public class ListExercises {    /**    * Counts the number of characters in total across all strings in the supplied list;    * in other words, the sum of the lengths of the all the strings.    * @param l a non-null list of strings   ...

  • JAVA PROBLEM! PLEASE DO IT ASAP!! REALLY URGENT! PLEASE DO NOT POST INCOMPLETE OR INCORRECT CODE...

    JAVA PROBLEM! PLEASE DO IT ASAP!! REALLY URGENT! PLEASE DO NOT POST INCOMPLETE OR INCORRECT CODE Below is the program -- fill the code as per the instructions commented: //---------------------------------------------------------------------------------------------------------------------------------------------------------------// /* The idea of this HW is as follows : A password must meet special requirements, for instance , it has to be of specific length, contains at least 2 capital letters , 2 lowercase letters, 2 symbols and 2 digits. A customer is hiring you to create a class...

  • Please fill in the remaining code necessary and follow the instructions below this is an abstract...

    Please fill in the remaining code necessary and follow the instructions below this is an abstract class; it represents an department in the company. This class cannot be instantiated (objects created), but it serves as the parent for other classes. Department – This class represents a department within the company. 1. Provide the implementation (the body) for the following methods: public int getDepartmentID()) public String getDepartmentName()) public Manager getManager()) 2. Fix the implementation for the following method– substitute “blah” with...

  • Using the diagram below and the starter code, write Document Processor that will read a file...

    Using the diagram below and the starter code, write Document Processor that will read a file and let the user determine how many words of a certain length there are and get a count of all of the word lengths in the file. Your program should do the following: The constructor should accept the filename to read (word.txt) and then fill the words ArrayList up with the words from the file. The countWords method should accept an integer that represents...

  • Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters...

    Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...

  • Lab Assignment : In this lab, you are going to implement QueueADT interface that defines a...

    Lab Assignment : In this lab, you are going to implement QueueADT interface that defines a queue. Then you are going to use the queue to store animals. 1. Write a LinkedQueue class that implements the QueueADT.java interface using links. 2. Textbook implementation uses a count variable to keep track of the elements in the queue. Don't use variable count in your implementation (points will be deducted if you use instance variable count). You may use a local integer variable...

  • In Java. What would the methods of this class look like? StackADT.java public interface StackADT<T> {...

    In Java. What would the methods of this class look like? StackADT.java public interface StackADT<T> { /** Adds one element to the top of this stack. * @param element element to be pushed onto stack */ public void push (T element);    /** Removes and returns the top element from this stack. * @return T element removed from the top of the stack */ public T pop(); /** Returns without removing the top element of this stack. * @return T...

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