Java: Socket Application
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 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.*;

public class SocketClient extends JFrame {

private static String URL = "";
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());
    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");
    //After choosing a trail, duration will be represented
    duration1 = new JRadioButton("_ days");
    duration2 = new JRadioButton("_ days");
    duration3 = new JRadioButton("_ days");
    //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;
    trailButtons.setLayout(new GridLayout(1,3,2,2));

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

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