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...
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...
(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...
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...
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...
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...
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?");...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT