Im having trouble creating a Word Decoder, Basically I'm trying to write a method that chooses a random character, and increases in by one place (a to b, b to c) and so on.

Any ideas in how to approach that?

Thanks,

JavaRookie

Use arrays. Create an array of letters a to z. For each letter you need to decode, look for it in the array. then output the array element.

I need to be able to use letters, numbers and symbols. I'm so lost as to how to get the method to select a random character, and increase its "place by one"

Here's my subclass so far,

import javax.swing.*;
import java.awt.*;
import java.util.Scanner;
import java.util.Random;

public class Scrambler {

    private TextField topField, midField, bottomField, stepField;
    private final static String newline = "\n";
    private TextField quantityField;
    private Scanner scanner, string;
    private char chars;
    public Scrambler(JFrame window){
        Label directions, encodet, encodek, steps;
        directions = new Label("Enter Text Here");
        directions.setBounds(50,50,500,30);
        directions.setForeground(Color.black);
        directions.setBackground(Color.green);
        window.add(directions);

        encodet = new Label("Encoded Text");
        encodet.setBounds(50,125,500,30);
        encodet.setForeground(Color.black);
        encodet.setBackground(Color.green);
        window.add(encodet);

        encodek = new Label("Encoding Key");
        encodek.setBounds(50,200,500,30);
        encodek.setForeground(Color.black);
        encodek.setBackground(Color.green);
        window.add(encodek);

        steps = new Label("Encoding Steps Remaining");
        steps.setBounds(50,275,500,30);
        steps.setForeground(Color.black);
        steps.setBackground(Color.green);
        window.add(steps);

        topField = new TextField();
        topField.setBounds(55,75,400,20);
        topField.repaint();
        window.add(topField, 0);

        midField = new TextField();
        midField.setBounds(55,150,400,20);
        midField.repaint();
        midField.setEditable(false);
        window.add(midField, 0);

        bottomField = new TextField();
        bottomField.setBounds(55,225,400,20);
        bottomField.repaint();
        bottomField.setEditable(false);
        window.add(bottomField, 0);

        stepField = new TextField();
        stepField.setBounds(225,280,50,20);
        stepField.repaint();
        stepField.setEditable(false);
        window.add(stepField, 0);

    }

    public void startEncode(){
        String midFieldAtPre;

        midFieldAtPre = midField.getText();
        midField.setText(topField.getText());

    }

    public void encodeText() {
        char[] ch = {'a','b','c','d'};
        
       
    }
    

    public void decodeText(){

    }

    public void repaintWindow(){

    }

}

As I understand your problem.

1. User input text on midField.
2. Then you will get the text inputted and you will decode the whole string by changing each letter in the string to the next letter in the alphabet. eg (a to b, b to c)
3. Then you will display this decode text.

For example,

User Input: eric

Decoded text: fsjd

Is that right??

Well basically all four of those Methods are a button. Each time you hit Start "Eric" will move to the midField text box, and the number of Encryption steps will show in the stepField. Then every time you hit the encodeText button, it selects a random character and increases it by one place. so: "Esic" now appears, and that character place shows in the bottomField, while the stepField shows one. Hit encode again it selects another random character and increases it by one place so: "Esid" now appears and the character place shows in the bottom field, while the stepField shows 2. And so on. Then every time you hit the decodeText button, it removes one step/ecryption, so it goes back to "Esic" reduces the step and removes that character place.

Have you done studying arrays?? I think its possible with arrays. You need to create 3 arrays:

inputArray (where you put the inputted String)
encodeArray (consists of 1 or 0, 1 if that char is encoded, 0 if not)
lettersArray (where you pt the letters of the alphabet)

With regards to randomization, you can search Google for random java.

This article has been dead for over six months. Start a new discussion instead.