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) 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...
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.
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...
Please Code Using Java Create a class called SoccerPlayer Create 4 private attributes: First Name, Last...
Please Code Using Java Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games, and Goals Have two constructors Constructor 1 – default constructor; all values to "NONE" or zero Constructor 2 – accepts input of first name, last name, games and goals. Create get and set methods for each of the four attributes Create a method the returns a double that calculates the average goals per game This method checks for zero games played: If...
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,...
CODE IN JAVA Create a class Student includes name, age, mark and necessary methods. Using FileWriter,...
CODE IN JAVA Create a class Student includes name, age, mark and necessary methods. Using FileWriter, FileReader and BufferedReader to write a program that has functional menu: Menu ------------------------------------------------- Add a list of Students and save to File Loading list of Students from a File Display the list of Students descending by Name Display the list of Students descending by Mark Exit Your choice: _ + Save to File: input information of several students and write that information into a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT