Using String Tokenizer And Buffer To Decode A Message?

Apr 15, 2014

So I have this file in which has a few sentences on a single line. What I need to be able to do is read the file and then take each word and create a token out of it. Then what it does is it selects the first letter of every 5th word, uppercase it, and then allow me to use append it via a stringbuffer object to create a word out of it.

I know I'll need to use a string tokenizer but I'm not sure how to do so in a way that makes each word separate and how to tell it to only hit the 1st letter of every 5th word.

Here's what I've come up with so far, but I'm currently at a loss at what to do and my textbook/documentation is just not working.

Java Code:

String line; // The line we read from the file.
char letter; // The first letter of each 5th word.
String sw; // The completed string.
public static void main (String [] args)throws IOException {

[Code] ....

View Replies


ADVERTISEMENT

Caesar Cipher - Encode / Decode Message With Given Key

Nov 1, 2014

I have been assigned to make a program that encodes and decodes a given message with the given key (spaced numbers, for example: 3 1 7 4 2 5). I'll post the code for all the classes that I am using below.

QueueInterface:

import java.util.*;
public interface QueueInterface<T>
{
T dequeue() throws QueueUnderflowException;
boolean isEmpty();

[Code] ....

Ok, so the classes to focus on are these:

CircularLinkedUnbndQueue
CircularLinkedQueueITD
Encoder
Decoder
EncodeDecodeConsole
EncodeDecodeITD

Because those are the ones I had to write myself, the others were given to us to use. As far as these classes go, they work fine without causing any errors from the input I give. For example if I enter a message and a key, it correctly encodes and decodes the message with the given key. What I'd like for you fine programmers to do is give feedback on those 6 classes. Like, suggestions on how to make them better or more efficient, neater, changing any of the methods to make them more efficient or prevent any errors beforehand, etc.

View Replies View Related

Decoder Ring - Prompt User For A Message To Decode

Nov 7, 2014

So it is the question: This program implements a simple "decoder ring". It will prompt the user for a message to decode and decode the message based on the following substitution rules:

ABCDEFGHIJKLMNOPQRSTUVWXYZ will map to
ZEBRASCDFGHIJKLMNOPQTUVWXY

abcdefghijklmnopqrstuvwxyz will also map to
ZEBRASCDFGHIJKLMNOPQTUVWXY

any other characters (like space, punctuation, will map to themselves)

so if it sees an 'A' (or an 'a'), it will map to 'Z', etc... All i could think of is this but can't figure out the rest.

import java.util.Scanner;
public class DecoderRing
{
public static void main(String[] args)
{
String1[] = 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z';
String2[] = 'Z','E','B','R','A','S','C','D','F','G','H','I','J','K','L','M','N','O','P','Q','T','U','V','W','X','Y';
}
}

Not sure, what things are necessary such as switch statements or if and else or for loops and such...

View Replies View Related

String Encode / Decode Method

Apr 4, 2014

I was asked to write program in Java, that should code and encode some String in following way:

i) coding : "rrryyyyyaaaa" -> "r3y5a4"
ii) encoding: "r3y5a4" -> "rrryyyyyaaaa"

The code works fine, but I forgot the name of this coding method.

View Replies View Related

Read Line Of Input For A File - String Tokenizer

Jan 27, 2015

So I'm having a problem with the .hasMoreElement() method. I try to read lineOfInput for a file which contains:

Hobbit, Long,t@gmail.com,475-555-4444,3
Long, Hobbit,b@yahoo.com,445-222-5342,2
Hobbit,Long,b@yahoo.com,465-222-5342,2
Help,Yerp,,455-222-2222,4

but when i get to the ,, on the last line I get a NoSuchElementException and the program crashes.

StringTokenizer inputField = new StringTokenizer(lineOfInput, ",");
while(inputField.hasMoreElements()) //for each fields is a line
{
lastName = inputField.nextElement().toString();
firstName = inputField.nextElement().toString();
email = inputField.nextElement().toString();
phoneNumber = inputField.nextElement().toString();
level = Integer.parseInt(inputField.nextElement().toString());
}

View Replies View Related

Splitting Values From A File With String Tokenizer And Storing It In Another Class

Aug 26, 2014

I'm new to java. I have a Product class with getters and setters.

E.g. setProdType & getProdType

I want to store the values from a file into that

StringTokenizer token = new StringTokenizer(line,"**");
while(token.hasMoreElements()) {
int p.setProdType = Integer.parseInt(token.nextElement().toString());
}

View Replies View Related

C Buffer To Java String

Sep 4, 2014

Due to compatibility reasons, I need to be able to store a random C buffer inside of a Java String. THis means that the Java String should contain the exact same buffer information (i.e. byte sequence) as the original C buffer. How would I do that?

All the functions I found will always somehow code/decode the C buffer, and modify its content depending on the selected encoding.

I need to do this inside JNI. Following is what I have:

Java Code:

unsigned char* cBuffer=getCBuffer();

// Transfer the C buffer to s:
jstring s=NULL;
if (env->EnsureLocalCapacity(2) >= 0)
{
jbyteArray bytes = env->NewByteArray(signalLength);
if (bytes != NULL)

[Code] ....

View Replies View Related

Retrieving Result By User Input Different Combination Using String Tokenizer (MYSQL)

Mar 30, 2014

I am creating a simple Symptom Checker application. The problem I have is that I'm trying to retrieve user input (JTextField) by comma's using StringTokenizer which contacts the database for a result which matches the user's input (SELECT * FROM DIAGNOSIS WHERE ?, ?, ?) . It successfully finds the correct result however only in a particular format. Not different combinations....

for example, if I enter say within the JTextField: "tearful, nausea, lack of motivation" it will find the result successfully (as that is how it is formatted within the particular column (in the database table) i wish to display a result from) however, if i enter a different combination of these symptoms: "nausea, lack of motivation, tearful" - it will not find any result. I'm very unsure how to make it work regardless of what is inputted first, second or last.

Here is the code:

public void actionPerformed(ActionEvent e) {
try {
String abc = fieldsymp1.getText();
StringTokenizer str = new StringTokenizer(abc);
while (str.hasMoreTokens()) {
str.nextToken((", ")).trim();
 
[Code] ....

View Replies View Related

String Buffer Append Method

Feb 17, 2014

I have the following code which always gives me java heap space error because of line number 65 due to string buffer append method in this line, I don't know why?

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import samy.*;
import java.util.Scanner;
public class InfixToPostfix {
OrderedList list = new OrderedList();
Scanner input = new Scanner(System.in);
public StringBuffer postfix = new StringBuffer();

[Code] .....

View Replies View Related

Difference Between Stringbuilder And String Buffer

Apr 3, 2014

what is the difference between stringbuffer and string builder?

View Replies View Related

How To Split A String Message

Nov 11, 2014

String path = "/AUTOSAR/Os_0?type=EcucModuleConfigurationValues";
String path1[] = path.split("?type");

I want to split string in such a way that I should get the content before "?" in an another variable. I tried various way but some how I am not getting expected behavior.

View Replies View Related

How To Compare Int To A Empty String To Input Error Message To User

Apr 16, 2015

I made a guess a number program but I am having issue figuring out a way that when a user enter's in nothing for the program to spit out a message saying "hey entering nothing doesn't work try again" then ask for input. I have done some research and from what I have found is to read the input in as a String rather than int, and use something like Integer.valueOf() to get the integer value but I am completely lost on how to apply that to my program here is my code

//import statements
import java.util.*; //for scanner class
// class beginning
public class Guess {
public static void main(String[] args ) {
//Declare variables area
int guess, secretNumber = (int) (Math.random() * 10 + 1), lowGuess,highGuess;

[Code] ....

View Replies View Related

ToString Method Return A String Rather Than Display A Message To Screen

Aug 11, 2014

I need making the toString() method return a String rather than display a message to the screen. Also, I'm not supposed to call the toString method in my demo class to test it, so what should I do instead?

public class cupDispenser {
String location;
int noOfCups;
cupDispenser(String location,int cups)
{
this.location=location;
this.noOfCups=cups;
}
public String getlocation()

[Code]...

View Replies View Related

Result Of Encoded Message Cannot Restore To Original Message By Decoder

Sep 28, 2014

The problem is the result of encoded message can't not restore to the original message by the decoder. Here are my three class's code

SecureMsgMain:

package securemsg.core;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
 import securemsg.database.*;
 public class SecureMsgMain {
 
[Code] .....

View Replies View Related

Encode / Decode A Jar File In Java

Feb 13, 2014

how to decode a .jar file to view its methods and later encode it. i wanted to write the program in java instead of using winzip

View Replies View Related

Reading In A File With BufferedReader / Using Tokenizer For Adding Into Adjacency Matrix

Mar 6, 2015

I am having trouble adding numbers read from a file with BufferedReader, using Tokenizer to split the numbers up by " " - space and adding them to an adjacency matrix.Below is the text file and my code, that I have at the moment.

0 1 0 0 1 1 0 0
1 0 0 0 0 1 1 0
0 0 0 1 0 0 1 0
0 0 1 0 0 0 0 1
1 0 0 0 0 1 0 0
1 1 0 0 1 0 0 0
0 1 1 0 0 0 0 1
0 0 0 1 0 0 1 0

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.StringTokenizer;
public class Foo
{
@SuppressWarnings("null")
public static void main(String[] args) throws Exception
{
String line, token = null, delimiter = " ";

[code]....

View Replies View Related

How Does A Buffer Reader Work

Mar 5, 2014

a buffer reader , how does it work and what is the code for it ?

View Replies View Related

Sending XML Records To Sax Parser Using Buffer

Mar 26, 2014

i am having a below piece of code in my worker thread. In my output i am getting xml records from the database. I'm sending this output to a input stream & finally to a sax parser.My query is, before sending to the parser i need to store the input stream in buffer. The buffer should store 1000 records. For every 1000 records the parser should be called from buffer.

while (orset.next()) {
output = orset.getString("xmlrecord");
writeCount++;
InputStream in = new ByteArrayInputStream(output.getBytes("UTF-8"));
InputStream inputStream = new ByteArrayInputStream(output.getBytes("UTF-8"));
Reader reader = new InputStreamReader(inputStream,"UTF-8");

[code]....

View Replies View Related

Swing GUI Freezing With Bounded-buffer

Jul 12, 2014

I'm writing a simple application, that provides a Swing GUI to a bounded-buffer problem. The application is composed by:

- Main.java: it creates a map of four threads (four instances of the class MyThread). Also it creates a shared database (an instance of the class Database) between the four threads.

- MyThread.java: it's an extension of Thread, and it shows a Swing GUI associated to this thread. Each thread is associated a GUI.

- GUI.java

- Database.java: it's an extension of ArrayList and and it can contain a maximum of five elements. An element is an instance of the class User. Also it implements put() and extract() method consistent with the algorithm of bounded-buffer problem.

- DatabaseException.java: it's a simple message.

- User.java

public class Main {
public static void main(String[] args) {
Database db = new Database();
Map<String, Thread> tdg_m = new HashMap();
for (int i = 1; i <= 4; i++) {
tdg_m.put("T" + i, new MyThread(db));

[Code] .....

The issue is the following. When the database is full, and i try to put an element, the GUI freezes. The same problem occurs when I try to extract an element from the empty database.

View Replies View Related

Smoothing Input Using Ring / Circular Buffer?

Aug 11, 2014

Normally I would just implement a circular buffer and be happy but there's a fundamental problem with that.OK, so I'm working on a piece of cheap Android hardware that's being used for demo purposes. One of the problems, primarily because it's cheap (imo) is that the screen input is not clean and is interfering with the UI experience. Specifically when gliding your finger, the result is quite non linear.

I know that's not the best drawing but it sort of explains the problem to a degree. In reality, it's probably a bit smoother than that, but there is still noisy data getting in, and the problem is it causes the UI to be jittery at times.

I would like to smooth this using something like a Circular Buffer. Now I figured the best way to do this would be to store the last 4 float inputs and then effectively calculate the next value based on an average, so say our input was this:10, 15, 20, 25 and 35 is the current input.

15 - 10 = 5
20 - 15 = 5
25 - 20 = 5

Then for the next value, 35 - 25 = 10. 10 + (3 * 5) = 25 / 4 = 6.25...Then adding 6.25 to the previous value resulting in this: 10 15 20 25 31.25 which would appear theoretically smoother. However I'm struggling to work out in my head the best way to implement such a function.

View Replies View Related

Instant Message GUI

Mar 14, 2014

import java.awt.*;
import javax.swing.*;
public class InstantMessageFrame extends JFrame
{
private JList friends;
private JTextField message;
private JButton send;

[code]...

1. Open the source code file of your InstantMessageFrame class from Lab 12.2.

2. Add the following three fields to the InstantMessageFrame class: a JTextField named message, a JList named friends, and a JButton named send.

3. Add a method to your InstantMessageFrame class named getMessagePanel()that returns a JPanel and has no parameters. (This method will create a JPanel that will appear in the south border of your JFrame. It will contain a text field in which a message can be entered and a button that sends an instant message to all the friends in the list.)

4. Within getMessagePanel(), instantiate a new JPanel and give it BorderLayout.Assign a message equal to a new JTextField by using the no-argument constructor of JTextField. Assign send to a new JButton,passing in "Send" to the constructor. (This will be the label on the button.)

5. Within getMessagePanel(), add the message text field to the center of the JPanel and add the send button to the east border of the JPanel. The panel is now ready, so return the JPanel reference.

6. Add a method to your InstantMessageFrame class named get-FriendsPane() that returns a JScrollPane and has no parameters.(This method will create a scrollable list that will contain the names of others that you can chat with.)

7. Within getFriendsPane(), assign friends to a new JList by using theno-argument constructor of JList.

8. Within getFriendsPane(), instantiate a new JScrollPane using the following statement: JScrollPane pane = new JScrollPane(friends);

9. The scroll pane is ready, so return the reference pane at the end of getFriendsPane().

10. Within the constructor of InstantMessageFrame, invoke getMessagePanel(),placing the returned panel in the south border of the content pane of InstantMessageFrame.An Introduction to GUI Programming 399

11. Within the constructor of InstantMessageFrame, invoke get-FriendsPane(), placing the returned scroll pane in the center of the content pane of InstantMessageFrame.

12. Save, compile, and run the InstantMessageFrame class.Your InstantMessageFrame now has three visible components: a JList,a JTextField, and a JButton.

View Replies View Related

Error Message Debug

Mar 11, 2014

I'm very new to java code I'm currently learning about loops I've tried to write this for a statement in the program I'm making but its not working. I keep getting this message

LoanQualifier.java:26: error: illegal start of expression
if (salary >0||<=250000)
^
LoanQualifier.java:28: error: illegal start of type
if (yearsOnJob >0||<50)

I'm using Jgrasp for a complier

View Replies View Related

Socket Should Only Read One Message

Apr 4, 2015

if i send messages as in the code below, is there a way to read only one message, if the client doesn't know how long it is (or if he only knows the maximum length)?in the documentation it says, that the method read(byte[]) reads until no data ist available or end of file is decteted. What does the latter mean? Can i extend the array that i sent by a byte that signals the end? Here is my Code:

Server

public class Server implements Runnable{
 ServerSocket server;
HashMap<Short,Socket> clients;
 public Server(){
clients = new HashMap<>();

[code]....

Both are startet in seperate threads. At the moment the first output of the client is "12 bytes read", and then continously "-1 bytes read"(because the server closes).

View Replies View Related

EJB / EE :: How To Pass XML File As Message In JMS

Apr 22, 2014

I am new to the JMS technology. I have written one sample sender and receiver program to pass a string message to the JMS queue and retrieve it back. It is working fine as well. But now, I want to pass a xml file to the JMS queue. Then from there I need to read the XML file and convert it into a Java object Using Jaxb. I know how to convert an XML into java object using Jaxb. But i am unable to send the XML file as a jms message to the listener.

View Replies View Related

How To Send A Message To A Client

Jan 22, 2015

I want to send a message to a specific client in a server. This is my code and what I tried(I have only given you 3 classes in which I believe I have the problem).

TextClient:
import java.io.*;
import java.net.*;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
public class TextClient {
public TextClient() {

[Code]...

View Replies View Related

JSF :: Message Resource Bundle

Sep 17, 2014

Im debugging a code that has the following setting:

<application>
<message-bundle>com.web.resources</message-bundle>
<locale-config>
<default-locale>en_US</default-locale>
<supported-locale>fr_FR</supported-locale>
</locale-config>
<resource-bundle>
<base-name>com.web.resources.message</base-name>
<var>message</var>
</resource-bundle>
</application>

Just want to ask, for example I have message_en_US.properties and message_en_SG.properties.And the web is currently using the SG property but one property is not exist on it, can I just redirect to use the US property?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved