Java Program

User Generated

pljsbat

Programming

Description

Write a class, called LetterPrint, for printing a letter as a 7x5 grid of either spaces or asterisks (*).

The letter is made up of a list of thirty-five 1's and 0's, which will be stored in an array representing the letter. This will be the only instance variable of the class.

For example, the input for letter I would look like this:

01110001000010000100001000010001110

Getting and setting the array with data such as this, the class will create a 2-D array (the grid) that holds the characters for the output. To turn the 1-D array into a 2-D array, the class with have a method that would assign a * for every 1 and a space for every 0. The class will have a method to printout the 2D array, where the output will look like:

***
  *
  *
  *
  *
  *
***

Write the following methods:
- A constructor with one parameter, which is an array of thirty-five 0's or 1's. This is the only instance variable for your class. Make sure to enforce the constraint of only 0's and 1's.
- An accessor method

- An equals method
- A toString method for printing out the letter (like the example)

- A method that turns the 1D array into 2D array, which will be called from toString method

As always, you will need to write a tester that will read two (2) series of 1s and 0s from a file, initialize an array (for each) with the input, and create a LetterPrint object passing the array. Then it calles the equals method on one object and pass the other one. Finally, it will call toString on both objects.


Zip all the source files and the input file and submit the zip file here.

need 1 tester file, 1 class file, 1 text file, when complied, all should run and print.

User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

public class letterPrintTester
{
public static void main(String[] args)
{
String[] letterPrint = new String[] {"01110001000010000100001000010001110"};

for (int i = 0; i < letterPrint.length; i++)

{
if (letterPrint[i].equals ("0"))
System.out.print(" ");
else
System.out.print("*");
}


}
}

Yes, that string is hardcoded.

Class file:

public class letterPrint
{

private String numString;

//Constructor
public letterPrint(String numString)
{
this.numString = numString;
}

public letterPrint()
{

}

//Methods

public String getChar(String numString)
{
return numString;
}

}


or

import java.util.ArrayList;

public class letterPrint
{
private String[] list;
private String[][] display;
private static final int ROWS= 7;
private static final int COLUMNS =5;
public letterPrint()
{
list= new String[35];
}

public void addValue(int j)
{
display = new String[ROWS][COLUMNS];
for ( int i = 0 ; i < ROWS; i++ )
{
for ( int h = 0 ; h < COLUMNS; h++ )
System.out.print(display[i][h] = " " );
if (j == 1)
list[i] = "*";
if(j == 0)
list[i] = " ";
}
}

Related Tags