Thursday, August 8, 2013

Python Check URL



Part 1

Write a program that takes the URL from the command-line, checks that it is a valid URL, opens
the web page at that URL, grabs and prints the URLs in lexicographic order. For
example, if you run the program from the terminal shell, python test1.py http://scholar.google.com, the output should look like:

http://support.google.com/bin/answer.py?answer=23852
http://www.google.com/chrome/
http://www.google.com/imghp?hl=en&
http://www.google.com/intl/en/about.html
http://www.google.com/intl/en/options/
http://www.google.com/intl/en/privacy.html
http://www.google.com/webhp?hl=en&
http://www.mozilla.com/firefox/

while python test1.py scholar.google.com,  would report an invalid URL

The program should:

·          import both sys and parse_url,
·          check that there are two command-line arguments,
·          check that the URL in sys.argv[1] begins with http:// (look up the string function
startswith),
·          call get_links from the parse_url module to get the set of URLs, and
·          print the sorted URLs, one per line of output.

Part 2

Modify the code so that it calls get_links in turn for each URL returned by the first call to get_links. Save all of the resulting links, together with the original links, in a single set, and print the URLs in order. For example, if you start with http://scholar.google.com, your code should output the eight URLs shown above together with all of the URLs found on those eight pages. At the end, output the number of different URLs found.

IT252 Part 4 Sales Representative

Download Solution From here
Enhance your application by creating a DISPLAY button. When this button is selected, the stars.txt file will be read in and displayed. Create a Sales Representative class that stores sales representative information. A Sales Representative object will be created for each sales representative that is read in when the DISPLAY button is selected. Select appropriate attributes for your sales representative. Ensure that you have created appropriate constructor(s) that will allow you to create sales representatives with the values read in from the file for sales rep ID, sales rep first name, sales rep last name, and so on.

With each sales representative that is read in from your stars.txt input file, you will create a Representative object that holds the sales representative data and add each Representative object to an ArrayList. Do not store your sales representative information as a String and add this String into your ArrayList. You must use your Representative class to create Representative objects. You should store Representative objects that encapsulate your sales representative information and store these in your ArrayList.

Hint: You may want to look into overriding the toString() method to provide a readable string representation of the Representative object.

After the ArrayList has been created, this ArrayList will be iterated over and displayed to the jTextArea. Override the toString() method for your Representative class so that each sales representative is printed in a readable manner. Total sales representatives should also be displayed.

Design Constraint:
You must use an ArrayList to collect all Representative objects that represent the sales representative data in the file.
An example of the printing of the contents of the ArrayList:

TOTAL SALES REPRESENTATIVES: 2
101 Jeannette Roberts
Supplies: 850.20
Books: 950.10
Paper: 855.23
SOUTH
PHONE

102 Anthony Laine
Supplies: 875.55
Books: 1000.50
Paper: 908.25
NORTH
EMAIL

ITS 320 Java Program 3



 
Decision Control and Loops with User Interaction
1) Write a Java application that prompts the user for pairs of inputs of a product number (1-5), and then an integer quantity of units sold (this is two separate prompts for input values). You must use a switch statement and a sentinel-controlled loop (i.e. a loop that stops execution when an out of range value, such as -1, is input). All 15 items below are for a single purchase. There are five sets of inputs as follows:

Product 1 1 unit (cost is $2.98 per unit)
Product 2 2 units (cost is $4.50 per unit)
Product 3 3 units (cost is $9.98 per unit)
Product 4 4 units (cost is $4.49 per unit)
Product 5 5 units (cost is $6.87 per unit)
Your application must calculate and display the total retail value of all products sold, after all 5 pairs of inputs are completed. You must also display the total after each new pair of input values is entered.
(This program was taken from Exercise 5.17 on page 228 of Deitel & Deitel's "Java How to Program (Sixth Edition)" (2005 by Pearson Publishing Co.))
2) You may use the Windows Command Prompt command line interface or any Java IDE you choose to compile and execute your program.

3) You are to submit the following deliverables to the Assignment Dropbox in a single Microsoft Word file: a) A screen snapshot of your Java source code (just the beginning is OK) as it appears in your IDE (e.g. jGRASP, Net Beans, Eclipse, etc.) or editor (e.g. a Windows Command Prompt DOS "more" of the .java file's first screen).
b) A listing of your entire Java source code in the same Microsoft Word file as item a), and following item a). You can simply copy and paste the text from your IDE into Word. Be sure to maintain proper code alignment by using Courier font for this item.
c) A screen snapshot of your program’s input and output in the same Microsoft Word file, and following item b). You must include screen snapshots of all inputs and all outputs, not just a sample.

4) Your instructor may compile and run your program to verify that it compiles and executes properly. 

5) You will be evaluated on (in order of importance): a) Inclusion of all deliverables in Step #3.
b) Correct execution of your program.
c) Adequate commenting of your code.
d) Good programming style (as specified in the textbook's examples).
e) Neatness in packaging and labeling of your deliverables.

Deficiencies in any of the above areas are subject to deductions in each area, based on the severity of the deficiency.
6) Here is some pseudocode/skeleton Java code for one possible solution to the program to get you started (this shows procedural code, but an object-oriented solution would have been better, since Java is a pure object-oriented language): 
 
import the classes you need
main
declare productNo and quantity variables
declare and initialize lineAmount and orderAmount variables
set up a String for your output via the Scanner class (or you may use the JTextArea
GUI component – this will require additional research beyond the textbook!)
start filling the String (or JTextArea) with the headers for Product, Quantity, Line
Cost, and Total Cost
prompt the user for the first productNo
while the productNo is not the sentinel value of -1
get the quantity
if the quantity is -1 then exit
switch on productNo
in each case, determine the new lineAmount
add the lineAmount to the orderAmount
add the new subtotal/order line information to the output String (or JTextArea)
get the next productNo
output the total orderAmount
7) Here is an example of what the beginning of your output might look like after the first product has been input and the information for the second one is starting to be entered. Note that this output uses a JTextArea GUI component for easy assembly and output of multiline text.

It is NOT required that you use a JTextArea component! You may use the Scanner class if you want.
If you do want to use a JTextArea component though, you will have to do some research beyond our textbook. Note that this is a frequent activity you'll find yourself doing day-to-day in any IT programming job. Not all answers are "right in the book"! Look at it as a learning opportunity to familiarize yourself with the Java API.
This would continue with a quantity of 2 for Product No. 2, then Product 3 with a quantity of 3, then Product 4 with a quantity of 4, and finally Product 5 with a quantity of 5.
Therefore the quantity of each product matches the Product No. And there are 15 total units for order.
Note that there is a single correct answer for the order total!
8) You must put all your screen snapshots and source code to a single Microsoft Word file.

Phone Dailing Program CIS 170

A prepaid phone service needs a program that converts alphanumeric keyboard input into a phone number. The user will input eight characters and the program will output either an error message or the translated seven-digit phone number. The input may contain digits, letters, or both. Letters can be uppercase or lowercase.

The program will perform the conversion per a standard telephone keypad layout.

0


5

J K L

1


6

M N O

2

A B C

7

P Q R S

3

D E F

8

T U V

4

G H I

9

 W X Y Z

The program implements the following methods.
  • Main(): Declares seven character variables and passes these to the following methods by reference:
    • ProcessInput(): gets user input and performs the conversion
    • ShowResults(): displays the results
  • GetInput(): Gets seven characters from the user and stores them into the seven variables Main() has passed by reference.
  • ProcessInput(): Calls ToDigit() for each, passing each character variable by reference, and returns one of these codes to Main() by value:
    • 0 if there were no input errors
    • -1 if there were input errors
Input errors include the following:
  • The first character is 0 (seven-digit phone numbers can't start with 0).
  • The first three characters are "555" (no phone numbers start with 555).
  • Any character is not a digit or an uppercase or lowercase letter.
  • ToDigit(): Converts a character (passed by reference) to its corresponding digit per the table above, and returns one of these codes to ProcessInput() by value:
    • 0 if the character is valid (a digit or uppercase or lowercase letter)
    • -1 if the character is not valid
  • ShowResults(): Writes converted telephone number to the screen, inserting a dash (-) between the third and fourth digits, and accepts the seven character variables from Main() by reference.
Sample Output:
Enter a 7 character phone number: 2132121
The converted phone number is: 213-2121
Enter a 7 character phone number: 2scdfER
The converted phone number is: 272-3337
Enter a 7 character phone number: 555resw
Invalid input, please try again.
Enter a 7 character phone number: 0988765
Invalid input, please try again.
Enter a 7 character phone number: 12345678
Invalid input, please try again.
Enter a 7 character phone number: @34*uy
Invalid input, please try again.

Write an outline in comments based on the requirements and the pseudocode. Then, implement declaring seven char variables. Make sure to fix any compiler errors before implementing more. Then, write and call an empty GetInput() method that accepts parameters, but does nothing but return a dummy value. Make sure you can pass the seven character variables by reference without compiler errors before implementing any of the GetInput() logic. Keep working incrementally like this, testing as you go. Set breakpoints and use the debugger at each phase to make sure your logic is working correctly. Then, use the same approach to implement the other methods. Test each phase with valid input before handling any invalid conditions.
Pseudocode:
ProcessInput( ) Method
  • Get 7 characters from the user and store them in the 7 variables that Main() has passed by reference
  • Call ToDigit() for each of the 7 characters
    • If toDigit returns an error code (-1), return an error code (-1)
  • If the first character is 0, return an error code (-1) to Main()
  • If the first three characters are 555, return an error code (-1)
  • If there are no errors, return 0
  • ToDigit ( ) Method
    • Convert the characters (passed from ProcessInput() by reference) to upper case
    • Use a switch statement to translate characters into their corresponding digits.
      • Write a case statement for each digit and for each valid uppercase letter
      • Write a default case that returns an error code (-1) for invalid letters
    • If there are no invalid letters, return 0
  • ShowResults ( ) Method
    • Display the Phone Number using the character variables Main() has passed by reference
  • Main() Method
    • Declare 7 char variables
    • Get user input by calling the GetInput() method, passing it the 7 variables by reference
    • Perform the conversion by calling the ProcessInput( ) method, passing it the 7 variables by reference
    • Display an error message or call ShowResults(), depending on the code ProcessInput() returns

Patient Class for the Wrightown Hospital C#

Download Solution from here
Create a patient class for the Wrightown Hospital Billing Department. Include a patient ID number, name, age, and amount due to the hospital. Include properties and any other methods you need. Override the ToString() method to return all the details for a patient. Write an application that prompts the user for data for five Patients. Sort them in patient ID number Oder and display them all, including a total amount owed.

Save the program as PatientDemo.es

Using the patient as a base, derive an InsuredPatient class. An insuredPatient contains all the data of a patient, plus fields to hold an insurance company name, and the percentage of the hospital bill the insurance company will pay. Insurance payment are Based on the following table:

Insurance Company Portion of bill paid by insurance (%)
Wrights town mutual 80
Red umbrella 60
All other companies. 25

Create an array of five InsuredPatient object. Create a program that justifies the following:
• prompt the user for all the patient
data, plus the name of insurance company; the insurance company set accessor determines the percentage paid.
• override the patient class ToString() method to include the name of the insurance company, the percent paid, and the amount due after the insurance has been applied to the bill.
•Sort all records in ID number order and display them with a total amount due from all insured patients.

Save the program as patientDemo2.cs

Write application that uses an extension method for the patient class. The method computers and returns a patient's quarterly insurance payment (one-fourth of the annual premium). The application should allow the user to enter data for five Patients and then display all Patient data for each, including the quarterly payment.

Save the program as PatientDemo.cs

Embed the program in a Microsoft word document.

Cite any sources in APA format on a separate page.

Linked List Using Insertion Sort CS230-1303A IP4

Download Solution from here
You will read the contributor information from a file similar to this table below; it is a comma delimited (CSV) file.
First Name in first column
Last Name in second column
Country in third column
Phone # in fourth column
Donation amount in fifth column
Contributor ID in sixth column

As each record is read, create a sorted Linked list of the contributors using the Insertion sort method.
You also need to maintain your table, with one modification.
You need to add an object to the Hash Collision Object that is a pointer to the data in the Linked list.
In addition, you need to implement Contributor search functionality based on a Contributor Name.
Your design should include the following:
High Level Implementation Instructions:
Sorted Linked list
Sorted using Insertion sort
Hash bucket of size 5 with a collision solution using a linked list (no need to order)
A Search Algorithm based on ID and Contributor Name.

The Contributor Name Algorithm needs to be implemented using the Sequential Search Each contributor will have the following information:
Name: String; //the name of the contributor
City: String; //the city in which the contributor lives
Country: String; //the country in which the contributor lives
Phone: String; //the phone number for the contributor
Contribution: Double; //the amount of the contribution given by the contributor to the zoo
ID: Integer; //identifier key for future needs

Contributor functions/methods:
Input constructor: //to accept a string for the name and additional information for each contributor (this should call the Add constructor to implement the sorted list)
Print constructor: //to print out the contributor data
Print All constructor: //to print the entire list of contributor names
Add constructor: //to traverse the Linked list and find the proper location for adding the instance

Search constructor: //the Search algorithm to implement is Sequential Search Each hash bucket collision item will have the following information:
ID: Integer; //identifier key for future needs Contributor
Address: Pointer; //a pointer to the address of the contributor instance in the sorted linked list Hash bucket

functions/methods:
Input constructor: //to accept a string for the name and additional information for each contributor (you will only need the ID portion of the input data)
Hash Function constructor: //Hint: You only have 5 Hash buckets so the function can be very a simple calculation
Pop constructor
Push constructor Print constructor: //to show the information of the contributor based on a given ID

CS230-1303A IP3 Read Contributor info from CVS file

Download Solution From here
Based on the new requirement from your boss to be able to search for a contributor's name, you decide it will be a good idea to have the data sorted. You will read the contributor information from a file provided; it is a common delimited (CSV) file. As each record is read, create a sorted Linked list of the contributors using the Insertion sort method.

At this point,  you no longer need to maintain the stack. Your design should include the following:

Each contributor will have the following information:
    Name: String; //the name of the contributor
    City: String; //the city in which the contributor lives
    Country: String; //the country in which the contributor lives
    Phone: String; //the phone number for the contributor
    Contribution: Double; //the amount of the contribution given by the contributor to the zoo
    ID: Integer; //identifier key for future needs

Contributor Functions/Methods:
    Input constructor: //to accept a string for the name and additional information for each contributor (this should call the Add constructor to implement the sorted list)
    Print constructor: //to print out the contributor data
    Print All constructor: //to print the entire list of contributor names
    Add constructor: //to traverse the linked list and find the proper location for adding the instance

Trading Company Division Sales For Each Quarter CPP

Download Solution from here
A trading company has three divisions, each responsible for sales to different locations. Design a DivSales class that keeps the sales data for a division, with the following members:
  • An array with four elements for holding four quarters of sales figures for the division.
  • A private static variable for holding the total corporate sales for all divisions for the entire year
  • A member function that takes four arguments, each assumed to be the sales for a quarter. The value of the arguments should be copied into the array that holds the sales data. The total of the four arguments should be added to the static variable that holds the total yearly corporate sales.
  • A function that takes an integer argument within the range of 0-3. The argument is to be used as a subscript into the division quarterly sales array. The function should return the value of the array element with that subscript.
Write a program that creates an array of three DivSales objects. The program should ask the user to enter the sales for four quarters for each division. After the data are entered, the program should display a table showing the division sales for each quarter. The program should then display the total corporate sales for the year.
  • For this question, name your class DivSales. For example, my class would be named: LeongLeeDivSales.
  • Use inline member functions for all the method functions mentioned.
  • You need to submit the following files:
1. DivSales.h: Specification (and inline member functions) for class and other functions should be in this .h file
2. DivSales_Demo.cpp : You need to write a separate program to test the class. In other words, main() is here.
Important: If you do not put to the above mentioned fields (class name and filename), you will get 0 point for the question.

SAMPLE RUN
Your output should look similar to the following. Things in bold are typed by the user.
Enter sales data for Division 1
Quarter 1: 1000
Quarter 2: 2000
Quarter 3: 3000
Quarter 4: 4000
Enter sales data for Division 2
Quarter 1: 2100
Quarter 2: 3200
Quarter 3: 4200
Quarter 4: 5200
Enter sales data for Division 3
Quarter 1: 6000
Quarter 2: 7000
Quarter 3: 8000
Quarter 4: 9000
================================
--- Report ---
Sales for Division 1
Quarter 1: $1000.00
Quarter 2: $2000.00
Quarter 3: $3000.00
Quarter 4: $4000.00
Sales for Division 2
Quarter 1: $2100.00
Quarter 2: $3200.00
Quarter 3: $4200.00
Quarter 4: $5200.00
Sales for Division 3
Quarter 1: $6000.00
Quarter 2: $7000.00
Quarter 3: $8000.00
Quarter 4: $9000.00
Press Enter to Continue.
Total Corporate Sales: $54700.00

Two-Dimensional Array to Store Floating Point C

Download Solution From here:
Learning Outcomes
This assessment tests the following learning outcomes:
  • Write and debug small programs in C using system libraries and APIs in an appropriate IDE.
  • Demonstrate an appreciation of accessing, manipulating and managing system-level resources, such as memory.
  • Demonstrate an understanding of the principles of imperative and structured programming.

Assignment Task
For this assignment you are required to create an application which creates a two-dimensional array to store floating point numbers representing the actual values of samples of steel bar in a production process. The number of samples in the array will be determined at run-time. This is very similar to containing the data in a spreadsheet.

The array should store the following:
  1. The sample number, length, diameter and weight of each sample;
  2. The average value for each of the above
  3. The maximum and minimum values of each of the above
Your program should be able to print this out in a user friendly format and to have the option of printing to a text file.

Submission:
You should submit a single program file named yourname.c

The file should be fully commented and should run on the computers in the labs.