Java GUI Application: Need to have the class files from the OnLine Shopping Syst
ID: 661666 • Letter: J
Question
Java GUI Application:
Need to have the class files from the OnLine Shopping System at the link below:
http://www.chegg.com/homework-help/questions-and-answers/write-java-program-simulates-simple-online-shopping-system-4-part-pragram-using-uml-diagra-q7349603
Question: Design an appropriate GUI application to set up and run the proposed OnLine Shopping System that would allow the customer to select the reading material of their choice.
NOTE: It is expected that you should not need to rewrite any of the classes from Part 1. Rather you will create instances of the relevant classes when you need them for Part 2.
The GUI for this assignment should create at least two new classes one being the JFrame for displaying the GUI JPanel, and the GUI JPanel with its components.
The GUI needs to be able to allow:
*** preload reading material from information read from a file such as ReadingMaterialInputFile.txt;
*** collect a customer's request for reading material in a particular category;
*** run a search to find all available reading material for a match;
*** print out the results of the search to the screen; and
*** calculate purchase price and write out the results to a file such as salesFile.txt.
Remember to incorporate as much error checking in your code to prevent problem user input.
Explanation / Answer
//UDPClient.java
package com.online.shopping;
import java.io.*;
import java.net.*;
import java.util.*;
public class UDPClient
{
private InetAddress IPAddress;
boolean done;
boolean keepGoing;
public UDPClient(String sHostName)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter your Category: ");
String category = sc.nextLine();
System.out.print("Enter your Title: ");
String title=sc.nextLine();
System.out.println(" Quering server");
BufferedReader br;
try {
IPAddress = InetAddress.getByName(sHostName);
}
catch (UnknownHostException ex)
{
System.err.println(ex);
System.exit(1);
}
// set up the buffered reader to read from the keyboard
try {
done = false;
DatagramSocket clientSocket = new DatagramSocket();
byte[] sendData = new byte[1024];
String s1 = category+","+title;
sendData = s1.getBytes();
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress, 9000);
clientSocket.send(sendPacket);
byte[] receiveData = new byte[1024];
keepGoing = true;
DatagramPacket receivePacket =
new DatagramPacket(receiveData, receiveData.length);
System.out.println ("Waiting for return packet");
clientSocket.setSoTimeout(10000);
int counter = 0;
while (keepGoing && counter < 10) {
counter++;
try {
clientSocket.receive(receivePacket);
String modifiedSentence =
new String(receivePacket.getData());
System.out.println(" Query Result: " + modifiedSentence);
keepGoing = false; // a packet has been received : stop sending
}
catch (SocketTimeoutException e) {
System.out.println(" No response. Sending data for "+ counter + " times ");
}
}
clientSocket.close();
}
catch (IOException ex)
{
System.err.println(ex);
}
}
public static void main(String args[]) throws Exception
{
String serverHostname = new String ("127.0.0.1");
if (args.length > 0)
serverHostname = args[0];
new UDPClient (serverHostname);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.