THE PROBBLEM Design and write a program in java that will wr

THE PROBBLEM: Design and write a program in java that will write out all the printable characters in the ASCII chart with their corresponding ASCII code values.  This means the characters numbered 32 through 127, inclusive.  The program must have a repeating menu (using a switch statement) with instructions that allow the user to dump out the ASCII chart using a while loop, a do-while loop and a for-loop.  Non-printable characters (below 32 or above 127) should be skipped, but the rows should still line up neatly.  In each case, the chart should look neat and readable, and each version of the chart should appear to be identical, except for a title at the top identifying which type of loop produced the chart.  One option on the menu should allow the user to exit the program.

Example:

                  ASCII Chart Using While-Loop:

32=   33=!  34=\"  35=#  36=$  37=%  38=&  39=\'

40=(  41=)  42=*  43=+  44=,  45=-  46=.  47=/

48=0  49=1  ...

.

.

.

etc. (to char 127)

IMPLEMENTATION: In your program you must write several methods, including ones to write out the menu, to read in an option and (using a switch statement) to call the appropriate function, and three functions to draw the chart each of the three different ways.  Note that the idea is to use three different types of loops to produce the charts.  Just using System.out and typing it in by hand will not be acceptable.  You should also have a working exit option in your menu.

In addition, I want each loop and the menu to exist as separate classes. You will then create objects of those classes in order to access the member methods of each. From here on out, your main method should consist primarily of method calls to other classes, where your actual code will reside.

Solution

package asciichart;

import java.util.Scanner;

/**

* main class

*/

public class ASCIIChart {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

int choice;

do{

System.out.println(\"press 1 for printing ASCII Chart using while loop.\ \");

System.out.println(\"press 2 for printing ASCII Chart using do-while loop.\ \");

System.out.println(\"press 3 for printing ASCII Chart using for loop.\ \");

System.out.println(\"press 4 for Exit\");

Scanner scan= new Scanner(System.in);//used to read choice of user

choice=scan.nextInt();

  

switch(choice){

case 1:

ASCIIChartWhile objWhile=new ASCIIChartWhile(); // creating obj of class i.e. printing ASCII Chart using while loop

objWhile.ASCIIChart_while(); // calling method of class to print ASCII Chart

break;

case 2:

ASCIIChartDoWhile objDoWhile=new ASCIIChartDoWhile(); // creating obj of class i.e. printing ASCII Chart using do-while loop

objDoWhile.ASCIIChart_dowhile(); // calling method of class to print ASCII Chart

break;

case 3:

ASCIIChartFor objFor=new ASCIIChartFor(); // creating obj of class i.e. printing ASCII Chart using for loop

objFor.ASCIIChart_for(); // calling method of class to print ASCII Chart

break;

case 4: System.exit(0);

default: System.out.println(\"please made right choice\ \");

break;

}

}while(choice!=4);

}

}

/**

* class to print ASCII chart using while loop

*/

class ASCIIChartWhile{

  

/*** ASCII Chart using whileLoop (from 32 to 127 inclusive) */

public void ASCIIChart_while() {

int inc=32;

System.out.println(\"ASCII Chart using while loop:\ \");

System.out.println(\"Decimal ASCII\ \");

System.out.println(\"....... ......\");

while(inc<127){

char temp=(char)inc; // convert integer value to ascii value

System.out.println(inc+\" = \"+temp);

inc++;

}

}   

}

/**

* class to print ASCII chart using while loop

*/

class ASCIIChartDoWhile{

  

/*** ASCII Chart using do-while Loop (from 32 to 127 inclusive) */

public void ASCIIChart_dowhile() {

System.out.println(\"ASCII Chart using do-while loop:\ \");

System.out.println(\"Decimal ASCII\ \");

System.out.println(\"....... ......\");

int inc=32;

  

do{

char temp=(char)inc; // convert integer value to ascii value

System.out.println(inc+\" = \"+temp);

inc++;

}while(inc<127);

}   

}

/**

* class to print ASCII chart using for loop

*/

class ASCIIChartFor{

  

/*** ASCII Chart using For Loop (from 32 to 127 inclusive) */

public void ASCIIChart_for() {

System.out.println(\"ASCII Chart using For loop:\ \");

System.out.println(\"Decimal ASCII\ \");

System.out.println(\"....... ......\");

for(int inc=32; inc<127; inc++){

char temp=(char)inc; // convert integer value to ascii value

System.out.println(inc+\" = \"+temp);

}

}   

}

THE PROBBLEM: Design and write a program in java that will write out all the printable characters in the ASCII chart with their corresponding ASCII code values.
THE PROBBLEM: Design and write a program in java that will write out all the printable characters in the ASCII chart with their corresponding ASCII code values.
THE PROBBLEM: Design and write a program in java that will write out all the printable characters in the ASCII chart with their corresponding ASCII code values.
THE PROBBLEM: Design and write a program in java that will write out all the printable characters in the ASCII chart with their corresponding ASCII code values.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site