Programming
Java Program

Question 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.

Final 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] = " ";
}
}

prince9599 (43)
UCLA

Anonymous
I was on a very tight deadline but thanks to Studypool I was able to deliver my assignment on time.

Anonymous
The tutor was pretty knowledgeable, efficient and polite. Great service!

Anonymous
I did not know how to approach this question, Studypool helped me a lot.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors