Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

find and fix the error import java.io.*; import java.net.*; class TCPclient { public static void main(String argv[]) throws Exception { String sentence; String modifiedSentence; BufferedReader

find and fix the error
import java.io.*;
import java.net.*;
class TCPclient {
public static void main(String argv[]) throws Exception
{
String sentence;
String modifiedSentence;
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket = new Socket("Localhost", 6789);
DataOutputStream outToServer =
new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer =
new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
sentence = inFromUser.readLine();
outToServer.writeBytes(sentence + ' ');
modifiedSentence = inFromServer.readLine();
System.out.println("FROM SERVER: " + modifiedSentence);
clientSocket.close();
}
}
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
class TCPserver {
public static void main(String argv[]) throws Exception
{
String clientSentence;
String newSentence="";
ServerSocket welcomeSocket = new ServerSocket(6789);
while(true) {
Socket connectionSocket = welcomeSocket.accept();
BufferedReader inFromClient =
new BufferedReader(new
InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient =
new DataOutputStream(connectionSocket.getOutputStream());
clientSentence = inFromClient.readLine();
//here we modify the sentence
//we first need to define and initialize a boolean to check wether a letter is the first letter in a word
boolean spaceAhead = true ; // to capitalize first letter in the sentence immedietly without checking for a space ahead
//we will loop through the sentence
for (int i = 0; i
//when found a letter
if(Character.isLetter(clientSentence.charAt(i))){
//if it the first letter in a word
if(spaceAhead){
char modified = Character.toUpperCase(clientSentence.charAt(i));
newSentence+=modified;
spaceAhead = false;
}
//if it was just a part of a word (not first letter)
else{
char notmodified = Character.toUpperCase(clientSentence.charAt(i));
newSentence+=notmodified;
spaceAhead = false;
}}
//if it was not a letter (it must be a space) then change isSpace to true
char space = Character.toUpperCase(clientSentence.charAt(i));
newSentence+=space;
spaceAhead = true;
}
outToClient.writeBytes(newSentence);
}
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students also viewed these Databases questions