Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 10, Problem 12PP
Program Plan Intro
HTTP URL connection
Program Plan:
Filename: Http_URL_Connection.java
- Import the required header files.
- Declare the class “Http_URL_Connection”.
- Declare the main method.
- Declare the variable and assign the URL to the variable.
- Declare the variable and assign the user agent.
- Create an object for URL.
- Open the URL connection.
- Set the request methods.
- Get the response code.
- Display the URL.
- Display the response code.
- If the “res” is equal to “HttpURLCinection.HTTP_OK”, read the file line by line and display it.
- Finally close the stream.
- Otherwise, display error message.
- Declare the main method.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a program to Validate an IPv4 Address.
According to Wikipedia, IPv4 addresses are canonically represented in
dot-decimal notation, which consists of four decimal numbers,
each ranging from 0 to 255, separated by dots, e.g., 172.16.254.1 .
The generalized form of an IPv4 address is (0-255).(0-255).(0-255).(0-255).
Here we are considering numbers only from 0 to 255 and
any additional leading zeroes will be considered invalid.
Your task is to complete the function isValid which returns 1,
if the ip address is valid else returns 0.
The function takes a string s as its only argument .
**************************************************************************/
// SOLUTION (in C++):
#include <bits/stdc++.h>
using namespace std;
int isValid(string s)
{
s += '.';
int countDots = 0;
string str = "";
for (int i = 0; i < s.length(); i++)
{…
Write a JAVA program for HTML is the language of web pages. Items start and end with tags. A table starts with <table> and ends with </table>. In a table, a row starts with <tr> and ends with </tr>. In a row, a column starts with <td> and ends with </td>. Given two integers for rows and columns, generate an appropriately sized html table. Place the character c in each table cell. If the input is 2 3, the output is:
<table> <tr> <td> c </td> <td> c </td> <td> c </td> </tr> <tr> <td> c </td> <td> c </td> <td> c </td> </tr> </table>
Done in Perl. Showing process would be nice.
Write a program to accept in an HTML string. search through the string and use a regular expression to pick out all valid URLs. A URL is enclosed in quotes and should begin with "http://. Display a list of all the valid URLs
Chapter 10 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 10.1 - Why would anybody write a program that sends its...Ch. 10.1 - When we discuss input, are we referring to data...Ch. 10.1 - What is the difference between a text file and a...Ch. 10.2 - Write some code that will create a stream named...Ch. 10.2 - Prob. 5STQCh. 10.2 - Prob. 6STQCh. 10.2 - Prob. 7STQCh. 10.2 - Write some code that will create a stream named...Ch. 10.2 - Suppose you run a program that writes to the text...Ch. 10.2 - Prob. 10STQ
Ch. 10.3 - Prob. 11STQCh. 10.4 - Write some Java code to create an output stream of...Ch. 10.4 - Give three statements that will write the values...Ch. 10.4 - Give a statement that will close the stream toFile...Ch. 10.4 - What import statement(s) do you use when creating...Ch. 10.4 - Prob. 16STQCh. 10.4 - Give three statements that will read three numbers...Ch. 10.4 - Give a statement that will close the stream...Ch. 10.4 - Can you use writeInt to write a number to a file...Ch. 10.4 - Can you use readUTF to read a string from a text...Ch. 10.4 - Prob. 21STQCh. 10.4 - Prob. 22STQCh. 10.4 - Does the class FileInputStream have a method named...Ch. 10.4 - Does the class FileOutputStream have a constructor...Ch. 10.4 - Does the class ObjectOutputStream have a...Ch. 10.4 - Prob. 26STQCh. 10.4 - Suppose that a binary file contains exactly three...Ch. 10.4 - The following code appears in the program in...Ch. 10.4 - Prob. 29STQCh. 10.5 - Prob. 30STQCh. 10.5 - Prob. 31STQCh. 10.5 - Prob. 32STQCh. 10.5 - Prob. 33STQCh. 10.6 - Prob. 34STQCh. 10.6 - Prob. 35STQCh. 10 - Write a program that will write the Gettysburg...Ch. 10 - Modify the program in the previous exercise so...Ch. 10 - Write some code that asks the user to enter either...Ch. 10 - Write a program that will record the purchases...Ch. 10 - Modify the class LapTimer, as described in...Ch. 10 - Write a class TelephoneNumber that will hold a...Ch. 10 - Write a class contactInfo to store contact...Ch. 10 - Write a program that reads every line in a text...Ch. 10 - Repeat the previous exercise, but write the new...Ch. 10 - Write a program that will make a copy of a text...Ch. 10 - Suppose you are given a text file that contains...Ch. 10 - Suppose that you have a binary file that contains...Ch. 10 - Suppose that we want to store digitized audio...Ch. 10 - Write a program RecoverSignal that will read the...Ch. 10 - Even though a binary file is not a text file, it...Ch. 10 - Write a program that searches a file of numbers...Ch. 10 - Write a program that reads a file of numbers of...Ch. 10 - The following is an old word puzzle: Name a common...Ch. 10 - The Social Security Administration maintains an...Ch. 10 - The following is a list of scores for a game....Ch. 10 - Write a program that checks a text file for...Ch. 10 - Prob. 5PPCh. 10 - Prob. 6PPCh. 10 - Revise the class Pet, as shown in Listing 6.1 of...Ch. 10 - Write a program that reads records of type Pet...Ch. 10 - Prob. 12PP
Knowledge Booster
Similar questions
- In Java Pleasearrow_forwardWrite down a program for summing up the total vehicle trip counts between a source location and destination location where each trip data has to get from the user where each trip data is in the following format: SourceLocationID-DestinationLocationID:Trip Counts The output must be sorted based on the Source Location ID Input Format 402-401:15 401-404:05 404-401:03 402-401:15 401-404:09 402-401:15 401-404:15 404-401:03 405-404:03arrow_forwardHTML is the language of web pages. Items start and end with tags. A table starts with and ends with . In a table, a row starts with and ends with . In a row, a column starts with and ends with . Given two integers for rows and columns, generate an appropriately sized html table. Place the character c in each table cell. If the input is 2 3, the output is: c c c c c carrow_forward
- Making a Python program that reads an IP address and determines whether it is syntactically correct or not. Assuming the format of the IP address is ###.###.###.### where 999 represents a number between 0 and 255. Use the `split function to access the values in the input IP address.arrow_forwardCreate a Multi-Client Chat Server using Sockets, Threads & GUI in Java. You should run the Server class first then run multiple Client classes. The output should be as follows: Client Randa Server Server received (Randa) message: Hi Server received (Youssef) message: Hello Server received (Randa) message: How are you? Server received (Youssef) message: I'm fine Server received (Youssef) message: What about you Server received (Randa) message: I'm okay Client Enter name Send (Randa) message: Hi (Youssef) message: Hello (Randa) message: How are you? (Youssef) message: I'm fine X (Youssef) message: What about you (Randa) message: I'm okay Youssef Enter name Send (Randa) message: Hi (Youssef) message: Hello (Randa) message: How are you? X (Youssef) message: I'm fine (Youssef) message: What about you (Randa) message: I'm okayarrow_forwardWrite a program in C that can convert a bit stream of a message into a frame by using Hamming coding. The bit stream is the input parameter of the program. For example, given an input parameter as 1001000, the correct output of the frame is 00110010000. Input bit stream will have 1 to 64 bits. Some self-testing examples are:Input 1001000; output 00110010000Input 1101001100110101; output 011110110011001110101Input 1010101; output 11110100101Input 11111111; output 111011101111 Write a program in C that can convert a bit stream of a message into a frame by using CRC. The bit stream is the first input parameter of the program, which will have 8 to 128 bits. The generator function is the second input parameter of the program, which will have 4 to 16 bits. For example, if the generator function is x^4 + x + 1, the second input will be 10011. The output should be the transmitted bit stream with its CRC checksum bits; see example in Figure 3-9 in the textbook. Some self-testing examples…arrow_forward
- The language used for the code is fortran 2008. Thank you 1. There are many algorithms that can be used to encrypt a message. One of these algorithms can be described as follows: • Choose a “code word”. For example, “fortran”. • Assign integer values to each of the characters in the code word corresponding to their placement in the alphabet. In the case of the code word “fortran”, the integer values would be (6, 15, 18, 20, 18, 1, 14). • Change each character in the message to be encrypted by adding the code word values determined above (in order) to each of the characters in the message to be encrypted. The code word is reused as many times as necessary. For example, suppose that we want to encrypt the message “hello”, we would first determine the integer values for each character in the message (8, 5, 12, 12, 15). Each of these values would be modified by adding the code word values, ie. (8+6, 5+15, 12+18, 12+20, 15+18) = (14, 20, 30, 32, 33). The resulting values are then translated…arrow_forwardEncrypt Caesar cipher is a kind of substitution cipher. Instead of using a substitution table, the alphabets are rotated by a number (a key). For example, if the key is 3, plaintext alphabet a would become d, and plaintext alphabet z would become c. Write a program that implements the Caesar Cipher. You program will first prompt for the key and then for the mode (E for encryption and D for decryption) and finally for the message to be encrypted / decrypted. Your program will then output the encryption / decryption message. For this question, the input message may consists of any character, the program should encrypt or small letter case a to z only. All other characters should be kept intact after encryption or decryption.arrow_forwardDevelop a WCF-REST Web service that takes a string (without spaces) as a parameter and performs following analysis of the string. The service contains two operations: string reverse(string str); // return the original string in the reverse order. int someOfDigits(int number) // return sum of digits in the integer value. for example, if the input number is 1234, sum of digits is 1+2+3+4 = 10 %3Darrow_forward
- Write a python program that scans in a large number of tweets from a file, and prints the top 5 hashtags. Approach Parse each word in the file Find a way to isolate the hashtags from the rest of the tweet Compute the frequency of each unique hashtag. Find the top 5 hashtags. Caveats 1. Because this is public dataset, there are many tweets that use special characters that may cause issues during reading in your file. To avoid this, explicitly specify the encoding mode in open when reading in the file. with open('twitter_data.txt', 'r', encoding='utf8') as f: 2. When parsing hashtags be sure to change everything to lowercase. There are cases in the file where two hashtags are the same but differ in case. 3. There is no standard way of sorting a dictionary based on the values. Python gives you access to a sorted function where you can pass in a collection and also specify a comparator which outlines how you want to sort the values. This can be done with a one line lambda function.arrow_forwardDevelop a crawler that collects the email addresses in the visited web pages. You can write a function emails() that takes a document (as a string) as input and returns the distinct email addresses appearing in it [remove duplicate email addresses]. You should use a regular expression to find the email addresses in the document. Use your WebCrawler to check email links in html <html><body><h4>Absolute HTTP link</h4><a href="http://www.google.com">Absolute link to Google</a><h4>Relative HTTP link</h4><a href="test.html">Relative link to test.html.</a><h4>mailto scheme</h4><a href="mailto:somebody@example.net">Click here to email somebody. </a><br><a href="mailto:somebody@example.net">Click here to email somebody.</a><br><a href="mailto:nobody@example.net">Click here to email nobody.</a><br><a href="mailto:nobody@example.net">Click here to email…arrow_forwardWrite a Java program that asks the user to enter items until the user chooses to stop, stores them into links (nodes), and chains the links together into a linked list. You will need to make the following changes Your linked list should store information about Customers' Transactions that . contain three fields: customer name (string), customer number (int), and transaction description (string) Instead of putting all of your code inside the main source code file, you should . :create the following functions o addToStart(Item x) o addToEnd(Item x) o insertAt(Item x, int n) o remove(int customer_number) (o reverse (o printList Instead of simply asking the user if they want to add. a new link, your main program should offer the user a :menu of options o Add a new link to the end o Add a new link to the beginning .o Insert an element at index n into the list o Remove a link from the list o Reverse the list o Print out the entire list o Quit the programarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,