Question

IN JAVA

Goals The primary goal of this lab is to write, test and complete a program with multiple classes, where you have designed and implemented those classes. You will also code and use methods and at tributes. This program will have an interactive behavior. This will reinforce the need for good design and creating and using new classes. The lab will build a rudimentary chat system to reinforce the concept ofc objects. betweern 1. Design a Person class. 2. Instantiates an object from a class you design (class Person). 3. Stores the data in your Person class. 4. Design a Chatroom class. 5. Integrate multiple Person objects into the Chatroom object. 6. Carry out a conversation between multiple people by inputting data and posting it to the console of the Chatroom object. Specifications The class you create will be a Person class. The Person class will connect to Chatroom. The Chatroom object will allow multiple Person objects to communicate to each other. The class will contain the following list of data attributes. You must decide the correct types for each, and minimally use the attributes and methods listed below

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The process here will be like,

1) First we need to create the server class to create server socket to establish the connection on a particular port.

2) We will use person class to send and recieve messages on the same connection.

You will need to have knowledge about the following classes and its methods:

PrintWriter (to write the data)

BufferedReader (to read the the input stream)

We will establish the connection will server as,

ServerSocket server_socket = new ServerSocket(3000); //3000 is port number

Socket sock = new Socket("127.0.0.1", 3000); // to connect to the server socket

Socket sock = server_socket.accept(); //to accept the client

Server Class will be:

public static void main(String[] args) throws Exception ServerSocket server_socket- new ServerSocket(3000); System.out.println(Server is Started!!!); // to accept the client Socket sock server_socket.accept) // sending to client Printwriter pwrite -new Printhriter (sock.getoutputStream(), true) // receiving from client BufferedReader msgFromClient -new BufferedReader(new InputStreamReader(sock.getInputStream())); BufferedReader readInput- new BufferedReader(new InputStreamReader(System.in)); System.out.println(Please begin the chat!) String receiveMessage, sendMessage; while(true) if( (receiveMessage msgFromClient.readLine))null) System.out.println(receiveMessage); sendMessage -readInput.readLine(); pwrite.println (sendMessage); pwrite.flush();

Person Class will be:

Add a comment
Know the answer?
Add Answer to:
IN JAVA Goals The primary goal of this lab is to write, test and complete a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA you will design and write a class that represents a real-world object of your choice....

    JAVA you will design and write a class that represents a real-world object of your choice. In the second part, you will write a program that demonstrates the use of the class. Part I: Select a "real-world" object that has not been used in class lecture and/or the textbook. The object you choose must be defined by at least: Have at least two characteristics (attributes). Have at least two behaviors (operations). The class that you write to represent the object...

  • IN JAVA Design and code a class hierarchy that demonstrates your understanding of inheritance and polymorphism....

    IN JAVA Design and code a class hierarchy that demonstrates your understanding of inheritance and polymorphism. Your hierarchy should contain at least 5 classes and one driver program that instantiates each type of object and runs multiple methods on those objects. Inheritance and Polymorphism must be apparent in the project. Please keep in mind that polymorphism was in chapter 37, so you will need to have read both chapters to understand what goes into this project. Bonus if you add...

  • write in java and please code the four classes with the requirements instructed You will be...

    write in java and please code the four classes with the requirements instructed You will be writing a multiclass user management system using the java. Create a program that implements a minimum of four classes. The classes must include: 1. Employee Class with the attributes of Employee ID, First Name, Middle Initial, Last Name, Date of Employment. 2. Employee Type Class that has two instances of EmployeeType objects: salaried and hourly. Each object will have methods that calculates employees payrol...

  • Java is an object-oriented programming language that enables us to define classes and to instantiate them...

    Java is an object-oriented programming language that enables us to define classes and to instantiate them into objects. These objects then call each other’s methods to implement the behavior of the application. The Unified Modeling Language (UML) is an object-oriented visual notation to document the design of object-oriented classes. For this discussion, you will practice designing a Java class called Course, drawing a UML class diagram for the Course class, and then implementing the Course class in Java code. Review...

  • Creating a Programmer-Defined Class in Java Summary In this lab, you will create a programmer-defined class...

    Creating a Programmer-Defined Class in Java Summary In this lab, you will create a programmer-defined class and then use it in a Java program. The program should create two Rectangle objects and find their area and perimeter. Instructions Make sure the class file named Rectangle.java is open. In the Rectangle class, create two private attributes named lengthand width. Both length and width should be data type double. Write public set methods to set the values for length and width. Write...

  • In this lab, you complete a partially written Java program that includes methods that require multiple...

    In this lab, you complete a partially written Java program that includes methods that require multiple parameters (arguments). The program prompts the user for two numeric values. Both values should be passed to methods named calculateSum(), calculateDifference(), and calculateProduct(). The methods compute the sum of the two values, the difference between the two values, and the product of the two values. Each method should perform the appropriate computation and display the results. The source code file provided for this lab...

  • Please use Java to write the program The purpose of this lab is to practice using...

    Please use Java to write the program The purpose of this lab is to practice using inheritance and polymorphism. We need a set of classes for an Insurance company. Insurance companies offer many different types of policies: car, homeowners, flood, earthquake, health, etc. Insurance policies have a lot of data and behavior in common. But they also have differences. You want to build each insurance policy class so that you can reuse as much code as possible. Avoid duplicating code....

  • Can you please pick Automobile For this assignment. Java Programming Second Inheritance OOP assignment Outcome: Student...

    Can you please pick Automobile For this assignment. Java Programming Second Inheritance OOP assignment Outcome: Student will demonstrate the ability to use inheritance in Java programs. Program Specifications: Programming assignment: Classes and Inheritance You are to pick your own theme for a new Parent class. You can pick from one of the following: Person Automobile Animal Based on your choice: If you choose Person, you will create a subclass of Person called Student. If you choose Automobile, you will create...

  • IN JAVA 2 A Binary Search Tree The goal of this lab is to gain familiarity...

    IN JAVA 2 A Binary Search Tree The goal of this lab is to gain familiarity with simple binary search trees. 1. Begin this lab by implementing a simple class that represents a "node” in a binary search tree, as follows. public class MyTreeNode<t extends Comparable<T>> { public T data; public MyTreeNode<T> leftchild; public MyTreeNode<T> rightChild; public MyTreeNode<T> parent; 2. Have the second member of your pair type in the code for the simple binary search tree interface. public interface...

  • java. do it on eclipse. the same way its instructed Second Inheritance OOP assignment Outcome: ...

    java. do it on eclipse. the same way its instructed Second Inheritance OOP assignment Outcome:  Student will demonstrate the ability to understand inheritance Program Specifications: Programming assignment: Classes and Inheritance You are to pick your own theme for a new Parent class. You can pick from one of the following:  Person  Automobile  Animal  If you choose Person, you will create a subclass of Person called Student.  If you choose Automobile, you will create a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT