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...
Code in Java Change the instructionLabel to ask the user to enter a numeric value into...
Code in Java Change the instructionLabel to ask the user to enter a numeric value into the textField and click the button to convert the entered value from kilometers to miles (1.609344 km = 1 mile). When the actionButton on the form is clicked, ActionWindow should take the value entered in the textField, convert it from kilometers to miles, and display the result in the resultField. import java.awt.Container; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class...
Write a function that takes a numeric or integer vector and adds up only the numbers...
Write a function that takes a numeric or integer vector and adds up only the numbers whose integer parts are even. Modify your answer to question above to include an option that allows you to choose whether to sum numbers whose integer parts are even or are odd. Your function should have as a default that it gives the same output as the function in question 4. In other words, if the user doesn’t specify whether to sum evens or...
java code Add the following methods to the LinkedQueue class, and create a test driver for...
java code Add the following methods to the LinkedQueue class, and create a test driver for each to show that they work correctly. In order to practice your linked list cod- ing skills, code each of these methods by accessing the internal variables of the LinkedQueue, not by calling the previously de?ined public methods of the class. String toString() creates and returns a string that correctly represents the current queue. Such a method could prove useful for testing and debugging...
Code in Java Create a class named DictionaryWord as: DictionaryWord - word: String                            &n
Code in Java Create a class named DictionaryWord as: DictionaryWord - word: String                                                              - meanings: String + DictionaryWord (String word, String meanings) + getWord(): String + setWord (String word): void + getMeanings(): String + setMeanings(String meanings): void Write a program with the following requirements: Creates 8 DictionaryWord objects with: Word and meanings as the table: word meanings bank robber Steals money from a bank burglar Breaks into a home to steal things forger Makes an illegal copy of something...
in Java using netbeans create a project and in it a class with a main. We...
in Java using netbeans create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste import java.util.Scanner; Part A ☑ In your main method, paste this code. Scanner scan = new Scanner(System.in); System.out.println("What is x?"); int x = scan.nextInt(); System.out.println("What is y?"); int y = scan.nextInt(); System.out.println("What is z?"); int z = scan.nextInt(); System.out.println("What is w?");...
in Java using netbeans create a project and in it a class with a main. We...
in Java using netbeans create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste import java.util.Scanner; Part A ☑ In your main method, paste this code. Scanner scan = new Scanner(System.in); System.out.println("What is x?"); int x = scan.nextInt(); System.out.println("What is y?"); int y = scan.nextInt(); System.out.println("What is z?"); int z = scan.nextInt(); System.out.println("What is w?");...
Using java you have to create a simple program that will allow for the storage of...
Using java you have to create a simple program that will allow for the storage of requests for money. Each request will consist of a person's name and dollar amount (US dollars). The business rules are straight forward. Each name should be a first and last name. The first letter of each element in the name should be capitalized. The dollar amount should be between 1 and 1000 dollars and include cents (2 decimals). You should include validations, but it...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT