Question

In: Computer Science

Using JAVA: Create a simple numeric code class SimpleCode that takes a set of numbers and...

Using JAVA:

Create a simple numeric code class SimpleCode that takes a set of numbers and turns them into words and sentences. The code should use the 0 to represent a space between words and 00 to represent a period at the end of a sentence. The 26 letters of the alphabet should be represented in reverse order. In other words, Z is 26 and A is one. In your final product, only the first letter of a sentence should be capitalized. Hint: StringBuilder might be useful as well as a set of parallel arrays or perhaps Enums.

You should use JOptionPane for your interactions with users.

Please make sure you comment your code thoroughly.

The code should be nicely formatted and should use proper variables.

Solutions

Expert Solution

Screenshot of the Code:

Sample Output:

Code to Copy:

import javax.swing.*;

//Define the class.
public class SimpleCode
{
   //Define the constructor.
   SimpleCode()
   {
       //Print the instruction.
       JOptionPane.showMessageDialog(null, "Enter numbers between 0 - 26 including both"
       +" 0 for space\n 00 for period."
               +"\n Separate each number with space.",
               "Instructions.",JOptionPane.INFORMATION_MESSAGE);
      
       //Prompt the user for input.
       String input = JOptionPane.showInputDialog(null,"Enter numbers between(0 - 26): ");
      
       //Split the number by spaces.
       String sep[] = input.split(" ");
      
       //Define the variable.
       String sen = "";
      
       //Create the string array.
       String rep[] = {" ", "z", "y", "x", "w", "v", "u",
               "t", "s", "r", "q", "p", "o", "n", "m", "l",
               "k", "j", "i", "h", "g", "f", "e", "d", "c",
               "b", "a"};
      
       //Iterate through the input.
       for(int i = 0; i < sep.length; i++)
       {
           //Get the integer value.
           int v = Integer.parseInt(sep[i]);
          
           //Iterate through the numbers.
           for(int j = 0; j <= 26; j++)
           {
               //If the input is valid.
               if(v == j)
               {
                   //Add space for 0.
                   if(i == 0)
                       sen += rep[j].toUpperCase();
                  
                   //Add period for 00.
                   else if(sep[i].equals( "00"))
                       sen += ".";
                  
                   //Add character for other numbers.
                   else
                       sen += rep[j];
                  
                   //Break the loop.
                   break;
               }
           }
       }
      
       //Display the resulting string.
       JOptionPane.showMessageDialog(null, sen,"Sentence.", JOptionPane.INFORMATION_MESSAGE);
   }
  
   //Define the main method.
   public static void main(String[] ss)
   {
       //Create the constructor of the class.
       new SimpleCode();
   }
}


Related Solutions

Using import java.util.Random, create a simple java code that populates an array with 10 random numbers...
Using import java.util.Random, create a simple java code that populates an array with 10 random numbers and then outputs the largest number.
In Java, using the code provided for Class Candle, create a child class that meets the...
In Java, using the code provided for Class Candle, create a child class that meets the following requirements. Also compile and run and show output ------------------------------------------------------------------------ 1. The child class will be named  ScentedCandle 2. The data field for the ScentedCandle class is:    scent 3. It will also have getter and setter methods 4. You will override the parent's setHeight( ) method to set the price of a ScentedCandle object at $3 per inch (Hint:   price = height * PER_INCH) CODE...
I know this code takes in a set of numbers into a doubly linked list and...
I know this code takes in a set of numbers into a doubly linked list and sorts it using insertion sort. Could you explain exactly how this code is working? main.c Source Code: #include #include #include "node.h" int main() { struct mynode *head=NULL; int value; printf("Give first value: \n"); scanf("%d",&value); printf("Give next values, and input 0 to end list: \n"); do{ if(value>0){    head = pushNode(head, value);    scanf("%d",&value); } }while (value>0); printf("Before insertion sort: "); printlist(head); head=insertsort(head); printf("After insertion...
In C++ create a simple larger3( ) function that takes 3 positive numbers as parameters and...
In C++ create a simple larger3( ) function that takes 3 positive numbers as parameters and returns the largest value of the three numbers.
Java Class Create a class with a main method. Write code including a loop that will...
Java Class Create a class with a main method. Write code including a loop that will display the first n positive odd integers and compute and display their sum. Read the value for n from the user and display the result to the screen.
(JAVA) Create a program that takes in 15 numbers in sorted order from the console and...
(JAVA) Create a program that takes in 15 numbers in sorted order from the console and stores them in a 1D array of size 15. Next, prompt the user for a number to search for in the array (target). Then, print the array. Next, search the array using a linear search – printing out each of the indices (or “indexes”) that are being examined until the algorithm either finds the target or doesn’t. Then, do the same thing for a...
Simple Java class. Create a class Sportscar that inherits from the Car class includes the following:...
Simple Java class. Create a class Sportscar that inherits from the Car class includes the following: a variable roof that holds type of roof (ex: convertible, hard-top,softtop) a variable doors that holds the car's number of doors(ex: 2,4) implement the changespeed method to add 20 to the speed each time its called add exception handling to the changespeed method to keep soeed under 65 implement the sound method to print "brooom" to the screen. create one constructor that accepts the...
Create a simple Java class for a Month object with the following requirements:  This program...
Create a simple Java class for a Month object with the following requirements:  This program will have a header block comment with your name, the course and section, as well as a brief description of what the class does.  All methods will have comments concerning their purpose, their inputs, and their outputs  One integer property: monthNumber (protected to only allow values 1-12). This is a numeric representation of the month (e.g. 1 represents January, 2 represents February,...
create a code in JAVA that takes arguments to do a bfs(breadth first search) or a...
create a code in JAVA that takes arguments to do a bfs(breadth first search) or a dfs( depth first search) using a txt file as the graph input. I have made most of the main function as well as a nose function I just need the bfs and dfs functions to work here's what I have so far, the comments that start with TODO are the parts that I need to finish Main.java import java.io.*; import java.util; ArrayList; import java.util.Iterator;...
this is a C++ class Topics Numeric Input (Whole Numbers) Assignment Finding Quotient Finding Remainder Numeric...
this is a C++ class Topics Numeric Input (Whole Numbers) Assignment Finding Quotient Finding Remainder Numeric Output (Whole Numbers) Description Write a program that will convert a distance entered in inches to a distance in yards, feet and inches. The program will ask the user to input a distance in inches as a whole number. It will convert the distance entered into yards, feet and inches. Then it will display the distance in yards, feet and inches. For example, the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT