Packet switching is the backbone technique for today’s modern communication networks. The term “packets” refers to the fact that the data stream from your computer is broken up into packets of about 200 bytes (on average), which are then sent out onto the network. Each packet contains a “header” with information necessary for routing the packet from origin to destination and determining its sequence in the original message. Thus each packet in a data stream is independent.

The main advantage of packet-switching is that it permits a statistical sharing (multiplexing) of the communications lines. That is, the packets from many different sources can share a line, allowing for very efficient use of the fixed capacity. With current technology, packets are generally accepted onto the network on a first-come, first-served basis. If the network becomes overloaded, packets are delayed or discarded (“dropped”). The receiving computer takes the packets (in whatever order they are received) and then “assembles” the original message. One might visualize the process as taking a bowl of scrambled eggs and trying to put each yoke back into their respective shells.

In this project we will simulate packet switching using lists and collections – reading a file of packets and reassembly to the appropriate destination files.

The following defines the scope of the problem you are to solve:

• Your program will read a data file, the information contained within represents a stream of packets with an arbitrary number of destinations.
• Because we are simulating a communications stream, you can only read the file once.
• Each set of three (3) lines in the stream represents a single packet.
o The first line is the “destination” – the name of a file to which the assembled message is to be written.
o The second line contains the index number of the next packet (beginning with 1) in the message or a value of 0 if it is last packet in the message.
o The third line contains the text of the message. An empty line should be considered to be the same as a newline.
• Once the packet stream (data file) has been completely exhausted, the messages for each “destination” should be saved to the “destination” file.
• Keep in mind that an arbitrary number of messages can be sent to an arbitrary number of destinations in an arbitrary order and that packets can be lost.

By way of example consider the following stream of packets:
bone technique for tod
two classes
ay's modern communic
LottoADT and at least
Packet switching is the back
ation networks.
consist of the Interface
Your program should

One might be tempted to employ a queue, however, the output to a.txt without reassembly is “bone technique for today's modern communicPacket switching is the backation networks.”

The assembled output to a.txt is “Packet switching is the backbone technique for today's modern communication networks.” And b.txt is “Your program should consist of the Interface LottoADT and at least two classes”.

Use the standard problem solving methodology that has been described. Examine the description and determine which ADT or combinations of ADTs would be most appropriate. As a start, you should develop a ‘Packet’ class. Test data will be provided.

HINT: the LinkedList class in the Java library implements the Queue interface and employs a doubly linked list with methods to add and remove elements. To insert a packet in the proper order means that you will have to determine where in the queue to add the newly arrived packet. (Ordering is according to packet number.) Thus, when the packet stream is exhausted, removing the head of the queue will yield an output that is ‘assembled’.

The following guidelines apply:
1. Your program should prompt the user for the pathname to the file containing the packets. The file can only be read once.
2. Use of the Java Collections Framework is restricted to the Stack and LinkedList (which implements the Queue interface) classes. Or you may use a linked list class as described in the text. Except for some source code from the text, all work must be original and your own!

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.util.Stack;

public class DataFile {
    private Stack<Packet> packets;
    private String name;

    * constructor
    * @param name
    public DataFile(String name) {
       packets = new Stack<>(); = name;
    * add new packet to the date file
    * @param p
    public void addPacket(Packet p){
       Stack<Packet> tmp = new Stack<>();
       // get to the right place
       while (packets.isEmpty() == false &&
                packets.peek().compareTo(p) < 0) {...
$33.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats