Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program Names : InvestmentClient InvestmentServer (with an inner class named Han

ID: 664376 • Letter: P

Question

Program Names: InvestmentClient

                               InvestmentServer (with an inner class named HandleClient)

Abstract:

                 Concepts covered in this project include graphics programming, client

                 server technology, and multithreading.

    Design and code a server program and a client program - both with its

   graphical user interface. The client will send the investment amount, number

    of years, and annual interest rate to a server.

    The server will calculate the future value and send the future value to the client.

                The client will display the future value in its window. Restrict the future value

               field so that the end-user cannot type in a value.

                The server will handle multiple clients at the same time. The server uses

                threads to handle the multiple clients simultaneously. The server will display

                the client number, host name, and its IP address for each request from the

                client.

               

Implementation for the server (InvestmentServer.java) – use Server1,java as the base program:

Import packages: java.io.*, java.net.*, java.util.*, java.awt.*,

java.awt.event.*, and javax.swing.*.

               1. Include logic to catch IOException (s) errors

                   Print out the system error message.

               2. Create JTextField object to receive the future value.

3. Create a JTextArea object to display the contents of the processing. Append   

  the messages via a new line for each new message Include the JScrollPane

  class to display more than one screen of information when needed.

4. Create a frame and place the text area on the frame to hold the label and text

   field. Use the BorderLayout manager to arrange the objects on the frame. See

    the sample input/output screen attached to these specifications.

5. Create a server Socket. Display this message:

        “InvestmentServer started at “ xxx

                  where xxx is the current date

          Note an IOException can occur.

6. Keep a count of the number of clients that connect to the server.

7. For each new client that connects to the server:

a. Listen for a new client connection.

b.. Display the client number and its Internet address with the following

     message:

     “Starting thread for client “ xxx “ at “ yyy

          where xxx is the client number and

                     yyy is the current date.

        c. Display the client’s host name and its IP address with the following

           messages (Note place each message on a new line):

           “Client “ xxx “’s host name is “ yyy

     

          where xxx is the client number and

                     yyy is the host name

           “Client “ xxx “’s IP Address is “ yyy

     

          where xxx is the client number and

                     yyy is the IP address

d. Create a new thread for the connection.

e. Start the new thread.

f. Increment the client number by 1.

8. Create an inner class HandleClient to handle any new connection.

    Use the Thread class as the superclass for this inner class

a.Define a client socket.

b.Construct a thread in the default constructor.

c.Run the thread. Define the actions to take in the run() method

d.Create the input and output streams to communicate with the client.

e.Continuously serve the client:

i.calculate the future value for the investment amount, number of years, and annual interest rate sent by the client. Send the future value back to the client. The formula:

                          futureValue = investment Amount * ( 1 + monthlyInterestRate) years *12              

ii.Display the future value with the following message with a new line for each message:

              “Investment amount received from client: “ vvv

                   where vvv is the investment Amount

             “Number of years received from client: “ xxx

                   where xxx is the years

             “Annual interest rate received from client: “ yyy

                   where yyy is the annual interest rate

             “ future value calculated: “ zzz

                                   where zzz is the future value

       iii.      Catch IOException errors

         Print the System error.

Implementation for the client (InvestmentClient) use Client1.java and FutureInvestment2 as the base programs:

Import packages: java.io.*, java.net.*, java.util.*, java.awt.*,

java.awt.event.*, and javax.swing.*, java.text.*.

1. Include logic to catch IOException (s) errors

2.Create four JTextField objects to receive the investment amount, number of years,

    annual interest rate, and future value.

3. Define the input and output streams.

4. Create a panel to hold the labels, text fields and buttons. Use the BorderLayout

     manager to arrange the labels, text fields and buttons on the panel. See the sample

     input/output screens attached to these specifications.

5. Register the listener.

6. Create a socket to connect to the server. Catch any IOException errors.

7. Create an input stream object to receive data (the future value) from the server

8. Whenever the user clicks the Calculate button or chooses Calculate from the Operation

     Menu, create an output stream to send the data (the investment amount, number

     of years, and interest rate) to the server.   

      Examples:

              osToServer.writeDouble(investmentAmount);

              osToServer.writeInt(years);

              osToServer.writeDouble(interestRate);

    After you send the input data to the server, invoke the flush() method on the output

    stream.

     Example:  

          osToServer.flush();

    Display the future value in a text field.

9. Implement the actionPerformed handler to process the events from the text fields.

    Show a message dialog box when the user clicks the About menu item from the Help

    menu. Show blank text fields when the user clicks the Clear button.

          

Documentation Tools: Use an UML class diagram, Javadocs and Pseudo code (or IPO chart). Also include documentation inside your program (you will lose points if your program is not well-documented).

Sample input and output for the server:

Note: You must run the server first and then the client.


Sample input and output for the client -first time processing for the clients:

Sample input and output for the clients -second time processing for the clients:

After Two Runs of the Client Program:

Note the InvestmentServer program keeps track of the request from the client.

After clicking the Clear button:

After clicking the Operation and Calculate options

After clicking the Help option:

After clicking the Help and the About option:

After clicking the Calculate button:

Display of the InvestmentServer Activities:

Some Possible Error Messages:

Java.net.SocketException. Connection reset

java.net.BindException.

UnkownHostException

Program Names: InvestmentClient

                               InvestmentServer (with an inner class named HandleClient)

Abstract:

                 Concepts covered in this project include graphics programming, client

                 server technology, and multithreading.

    Design and code a server program and a client program - both with its

   graphical user interface. The client will send the investment amount, number

    of years, and annual interest rate to a server.

    The server will calculate the future value and send the future value to the client.

                The client will display the future value in its window. Restrict the future value

               field so that the end-user cannot type in a value.

                The server will handle multiple clients at the same time. The server uses

                threads to handle the multiple clients simultaneously. The server will display

                the client number, host name, and its IP address for each request from the

                client.

               

Implementation for the server (InvestmentServer.java) – use Server1,java as the base program:

Import packages: java.io.*, java.net.*, java.util.*, java.awt.*,

java.awt.event.*, and javax.swing.*.

               1. Include logic to catch IOException (s) errors

                   Print out the system error message.

               2. Create JTextField object to receive the future value.

3. Create a JTextArea object to display the contents of the processing. Append   

  the messages via a new line for each new message Include the JScrollPane

  class to display more than one screen of information when needed.

4. Create a frame and place the text area on the frame to hold the label and text

   field. Use the BorderLayout manager to arrange the objects on the frame. See

    the sample input/output screen attached to these specifications.

5. Create a server Socket. Display this message:

        “InvestmentServer started at “ xxx

                  where xxx is the current date

          Note an IOException can occur.

6. Keep a count of the number of clients that connect to the server.

7. For each new client that connects to the server:

a. Listen for a new client connection.

b.. Display the client number and its Internet address with the following

     message:

     “Starting thread for client “ xxx “ at “ yyy

          where xxx is the client number and

                     yyy is the current date.

        c. Display the client’s host name and its IP address with the following

           messages (Note place each message on a new line):

           “Client “ xxx “’s host name is “ yyy

     

          where xxx is the client number and

                     yyy is the host name

           “Client “ xxx “’s IP Address is “ yyy

     

          where xxx is the client number and

                     yyy is the IP address

d. Create a new thread for the connection.

e. Start the new thread.

f. Increment the client number by 1.

8. Create an inner class HandleClient to handle any new connection.

    Use the Thread class as the superclass for this inner class

a.Define a client socket.

b.Construct a thread in the default constructor.

c.Run the thread. Define the actions to take in the run() method

d.Create the input and output streams to communicate with the client.

e.Continuously serve the client:

i.calculate the future value for the investment amount, number of years, and annual interest rate sent by the client. Send the future value back to the client. The formula:

                          futureValue = investment Amount * ( 1 + monthlyInterestRate) years *12              

ii.Display the future value with the following message with a new line for each message:

              “Investment amount received from client: “ vvv

                   where vvv is the investment Amount

             “Number of years received from client: “ xxx

                   where xxx is the years

             “Annual interest rate received from client: “ yyy

                   where yyy is the annual interest rate

             “ future value calculated: “ zzz

                                   where zzz is the future value

       iii.      Catch IOException errors

         Print the System error.

Implementation for the client (InvestmentClient) use Client1.java and FutureInvestment2 as the base programs:

Import packages: java.io.*, java.net.*, java.util.*, java.awt.*,

java.awt.event.*, and javax.swing.*, java.text.*.

1. Include logic to catch IOException (s) errors

2.Create four JTextField objects to receive the investment amount, number of years,

    annual interest rate, and future value.

3. Define the input and output streams.

4. Create a panel to hold the labels, text fields and buttons. Use the BorderLayout

     manager to arrange the labels, text fields and buttons on the panel. See the sample

     input/output screens attached to these specifications.

5. Register the listener.

6. Create a socket to connect to the server. Catch any IOException errors.

7. Create an input stream object to receive data (the future value) from the server

8. Whenever the user clicks the Calculate button or chooses Calculate from the Operation

     Menu, create an output stream to send the data (the investment amount, number

     of years, and interest rate) to the server.   

      Examples:

              osToServer.writeDouble(investmentAmount);

              osToServer.writeInt(years);

              osToServer.writeDouble(interestRate);

    After you send the input data to the server, invoke the flush() method on the output

    stream.

     Example:  

          osToServer.flush();

    Display the future value in a text field.

9. Implement the actionPerformed handler to process the events from the text fields.

    Show a message dialog box when the user clicks the About menu item from the Help

    menu. Show blank text fields when the user clicks the Clear button.

          

Documentation Tools: Use an UML class diagram, Javadocs and Pseudo code (or IPO chart). Also include documentation inside your program (you will lose points if your program is not well-documented).

Sample input and output for the server:

Note: You must run the server first and then the client.


Sample input and output for the client -first time processing for the clients:

Sample input and output for the clients -second time processing for the clients:

After Two Runs of the Client Program:

Note the InvestmentServer program keeps track of the request from the client.

After clicking the Clear button:

After clicking the Operation and Calculate options

After clicking the Help option:

After clicking the Help and the About option:

After clicking the Calculate button:

Display of the InvestmentServer Activities:

Some Possible Error Messages:

Java.net.SocketException. Connection reset

java.net.BindException.

UnkownHostException

Explanation / Answer

this question has lot of sub-parts.Please post 4 more questions for a full solution. It is a full application in java.

server.java

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.OutputStream;

import java.io.OutputStreamWriter;

import java.net.ServerSocket;

import java.net.Socket;

public class Server

{

    private static Socket socket;

    public static void main(String[] args)

    {

        try

        {

            int port = 25000;

            ServerSocket serverSocket = new ServerSocket(port);

            System.out.println("Server Started and listening to the port 25000");

            //Server is running always. This is done using this while(true) loop

            while(true)

            {

                //Reading the message from the client

                socket = serverSocket.accept();

                InputStream is = socket.getInputStream();

                InputStreamReader isr = new InputStreamReader(is);

                BufferedReader br = new BufferedReader(isr);

                String number = br.readLine();

                System.out.println("Message received from client is "+number);

                //Multiplying the number by 2 and forming the return message

                String returnMessage;

                try

                {

                    int numberInIntFormat = Integer.parseInt(number);

                    int returnValue = numberInIntFormat*2;

                    returnMessage = String.valueOf(returnValue) + " ";

                }

                catch(NumberFormatException e)

                {

                    //Input was not a number. Sending proper message back to client.

                    returnMessage = "Please send a proper number ";

                }

                //Sending the response back to the client.

                OutputStream os = socket.getOutputStream();

                OutputStreamWriter osw = new OutputStreamWriter(os);

                BufferedWriter bw = new BufferedWriter(osw);

                bw.write(returnMessage);

                System.out.println("Message sent to the client is "+returnMessage);

                bw.flush();

            }

        }

        catch (Exception e)

        {

            e.printStackTrace();

        }

        finally

        {

            try

            {

                socket.close();

            }

            catch(Exception e){}

        }

    }

}

client.java

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.OutputStream;

import java.io.OutputStreamWriter;

import java.net.InetAddress;

import java.net.Socket;

public class Client

{

    private static Socket socket;

    public static void main(String args[])

    {

        try

        {

            String host = "localhost";

            int port = 25000;

            InetAddress address = InetAddress.getByName(host);

            socket = new Socket(address, port);

            //Send the message to the server

            OutputStream os = socket.getOutputStream();

            OutputStreamWriter osw = new OutputStreamWriter(os);

            BufferedWriter bw = new BufferedWriter(osw);

            String number = "2";

            String sendMessage = number + " ";

            bw.write(sendMessage);

            bw.flush();

            System.out.println("Message sent to the server : "+sendMessage);

            //Get the return message from the server

            InputStream is = socket.getInputStream();

            InputStreamReader isr = new InputStreamReader(is);

            BufferedReader br = new BufferedReader(isr);

            String message = br.readLine();

            System.out.println("Message received from the server : " +message);

        }

        catch (Exception exception)

        {

            exception.printStackTrace();

        }

        finally

        {

            //Closing the socket

            try

            {

                socket.close();

            }

            catch(Exception e)

            {

                e.printStackTrace();

            }

        }

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote