QuestionQuestion

Java: Socket Application
Assignment:
Socket client
Beartooth Hiking Company has decided that they would also like to provide rate quotes as a socket service in addition to the Web-start solution. For this homework, you are to modify your last homework to connect to a socket servoer to get the quote information instead of using the Rates and BookingDay classes.
The BHC server will be on web7.jhuep.com:20025. It expects data in the form of
hike_id:begin_year:begin_month:begin_day:duration (e.g: 1:2008:7:1:3)
Gardiner Lake is hike_id 0, with durations of 3 or 5 days
Hellroaring Plateu is hike_id 1, with durations of 2, 3, or 4 days
Beaten Path is hike_id 2, with durations of 5 or 7 days
January is month 1, and the years are in four digits, and all values are separated by ":"s
The returned result will be the cost followed by a ":", followed by some text. If things go well, you'll get the cost and the text "Quoted Rate", if there is a problem, the cost will by -0.01 and the text will have some explanation. You will need to parse the return results and display them in your GUI. You are not responsible for the logic of the rate quote, as the server will handle it. All you are doing is designing the GUI client and then displaying the results from the server.
You should use a Java app solution (executable jar) solution for this application that is uploaded to the Blackboard server.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.net.Socket;

public class SocketClient extends JFrame {

// SERVER CONSTANTS
private static String URL = "web7.jhuep.com";
private static int PORT = 20025;

private final JLabel trail;
private final JLabel cost;
private final JLabel startDate;
private final JLabel duration;
private final JLabel costShow;

private JTextField year;
private JTextField month;
private JTextField day;

private final JRadioButton roaring;
private final JRadioButton gardiner;
private final JRadioButton beaten;
private JRadioButton duration1;
private JRadioButton duration2;
private JRadioButton duration3;

private final JButton quote;

private final JPanel labels = new JPanel();
private final JPanel trailButtons = new JPanel();
private final JPanel durationButtons = new JPanel();
private final JPanel textFields = new JPanel();

private final ButtonGroup trailGroup = new ButtonGroup();
private final ButtonGroup durationGroup = new ButtonGroup();

String durationShow = "";
String trailChosen = "";

public SocketClient() {
   
    //Frame Layout            
    setLayout(new GridBagLayout());
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setTitle("Beartooth Hiking Company Tour Cost");
   
    //Show Labels
    trail = new JLabel("Trail: ");
    duration = new JLabel("Duration: ");
    startDate = new JLabel("Start Date: ");               
    cost = new JLabel("Total Cost: ");
    costShow = new JLabel("");
   
    //Radio Buttons to choose a trail
    roaring = new JRadioButton("HELLROARING");
    gardiner = new JRadioButton("GARDINER");
    beaten = new JRadioButton("BEATEN");
   
    trailGroup.add(roaring);
    trailGroup.add(gardiner);
    trailGroup.add(beaten);
   
    //After choosing a trail, duration will be represented
    duration1 = new JRadioButton("_ days");
    duration2 = new JRadioButton("_ days");
    duration3 = new JRadioButton("_ days");
   
    durationGroup.add(duration1);
    durationGroup.add(duration2);
    durationGroup.add(duration3);
   
    //Initialize TextFields for Dates
    month = new JTextField("mm", 10);
    day = new JTextField("dd", 10);
    year = new JTextField("yyyy", 10);
   
    //Button for getting total cost               
    quote = new JButton("GET A QUOTE");
   
    //Generate the layout constraints
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = GridBagConstraints.RELATIVE;
    gbc.anchor = GridBagConstraints.EAST;
   
    add(trail, gbc);
    add(duration, gbc);
    add(startDate, gbc);
    add(cost, gbc);
   
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.anchor = GridBagConstraints.WEST;
   
    add(trailButtons,gbc);
    trailButtons.setLayout(new GridLayout(1,3,2,2));
    trailButtons.add(roaring);
    trailButtons.add(gardiner...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$50.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.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
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