Questions
This problem is about query flooding in P2P networks. Here, we explore the reverse-path routing of...

This problem is about query flooding in P2P networks. Here, we explore the reverse-path routing of the QueryHit messages in Gnutella. Suppose that Alice issues a Query message. Furthermore, suppose that Bob receives the Query message (which may have been forwarded by several intermediate peers) and has a file that matches the query.

5.1. As we know when a peer has a matching file, it sends a QueryHit message along the reverse path of the corresponding Query message. An alternative design would be for Bob to establish a direct TCP connection with Alice and send the QueryHit message over this connection. What are the advantages and disadvantages of such an alternative design?

5.2 In the Gnutella protocol, when the peer Alice generates a Query message, it inserts a unique ID in the message’s MessageID field. When the peer Bob has a match, it generates a QueryHit message using the same MessageID as the Query message. Describe how peers can use the MessageID field and local routing tables to accomplish reverse-path routing.

5.3. An alternative approach, which does not use message identifiers, is as follows. When a query message reaches a peer, before forwarding the message, the peer augments the query message with its IP address. Describe how peers can use this mechanism to accomplish reverse-path routing.

In: Computer Science

JAVA Create an HourlyEmployee class that inherits from Employee and has two new instance variables: hours,...

JAVA Create an HourlyEmployee class that inherits from Employee and has two new instance variables: hours, which represents the hours worked, and wage, which represents the employee's pay per hour. (Both are doubles.) Create a constructor that takes the arguments first name, last name, social security number, hourly wage, and the number of hours worked. Also create accessors, mutators, an earnings method that returns the money earned by the employee this week, and a toString method that returns information about the employee in the form of a String. The setWage method should ensure that the wage is nonnegative, and the setHours method should ensure that the value of hours is between 0 and 168 (the number of hours in a week).

Create a Driver class with a main method that prompts the user to enter a first name, last name, social security number, hours, and wage for an employee. Then, the program should create an HourlyEmployee object and use its toString method to print information about it.

SAMPLE RUN #1: java Driver

Enter·first·name:Bobbi↵
Enter·last·name:Benton↵
Enter·social·security·number:765-42-0092↵
Enter·hours·worked:53↵
Enter·wage:15.8↵
hourly·employee:·Bobbi·Benton↵
social·security·number:·765-42-0092↵
hours:·53.0·↵
wage:·15.80·↵
earnings:·837.40↵

In: Computer Science

How do I add a method to make sure that the user inputs in uppercase only...

How do I add a method to make sure that the user inputs in uppercase only and anything entered in lower case throws an error as well as to make sure when they are halving the questioned number they don't enter any decimals?

import java.util.*;

public class TestCode {
public static void main(String[] args) {
String choice = "YES";
Random random = new Random();
Scanner scanner = new Scanner(System.in);
ArrayList data = new ArrayList();
int count = 0,correct=0;
while (!choice.equals("NO")) {
int randomInt = 2 * (random.nextInt(5) + 1);
System.out.println(randomInt);
System.out.println("Enter half of the random number");
int temp=scanner.nextInt();
if(2*temp==randomInt){
correct++;
System.out.println("Correct");
}
else{
System.out.println("Incorrect");
}
data.add(randomInt);
count++;
System.out.print("Want another number (Yes / No)? ");
choice = scanner.next();
}
System.out.println("You got like "+correct+" answers and "+(count-correct)+" incorrect answers");
int min = Collections.min(data);
int max = Collections.max(data);

System.out.print("Values are: ");
for (int i = 0; i < data.size(); i++) {
System.out.print(data.get(i) + " ");
}
System.out.println();

System.out.println("Percentage of Yes values is " + (((count - 1) * 100.0) / count));
System.out.println("Maximum value is " + max);
System.out.println("Minimum value is " + min);
}
}

In: Computer Science

In 2-3 pages, develop a Secure Application Development Procedure which addresses each of the OWASP Top...

In 2-3 pages, develop a Secure Application Development Procedure which addresses each of the OWASP Top Ten Vulnerabilities. Make sure to address the following:

  • Software Development Processes
  • Secure Coding Techniques
  • Application Configuration Techniques
  • Web Server Configuration Techniques

In: Computer Science

How can I fix this code to accomplish the goal of reading and writing on binary...

How can I fix this code to accomplish the goal of reading and writing on binary or text files?

3 import java.io.*;
4 import java.io.FileOutputStream;
5 import java.io.FileInputStream;
6 import java.util.Scanner;
7
8 public class ReadAndWrite implements Serializable
9 {
10 public static void main(String[] args)
11 {
12 boolean file = true;
13 Scanner inputStream;
14 PrintWriter outputStream;
15 FileInputStream inputBinary;
16 FileOutputStream readBinary;
17 FileInputStreamText writeText;
18 FIleOutputStreamText readText;
19 StringBuffer contents = new StringBuffer();
20 Scanner keyboard = new Scanner(System.in);
21 String yn = "Y N", fileName = " ", line = " ", tb = "T B", rw = "R W";
22
23 while(file)
24 {
25 System.out.println("Enter the file name.");
26 fileName = keyboard.nextLine();
27 System.out.println("Choose binary or text file (b/t):");
28 tb = keyboard.nextLine();
29 if (tb.equalsIgnoreCase("b"))
30 {
31 System.out.println("Choose read or write (r/w):");
32 rw = keyboard.nextLine();
33 if (rw.equalsIgnoreCase("r"))
34 {
35 inputBinary = new PrinterWriter(new FileInputStream(fileName));
36 System.out.println("File contains:" + readBinary);
37 inputBinary.close();
38 }
39 else
40 {
41 System.out.println("Enter a line of information to write to the file:");
42 line = keyboard.nextLine();
43 System.out.println("Would you like to enter another line? (y/n)");
44 yn = keyboard.nextLine();
45 if(yn.equalsIgnoreCase("n"))
46 {
47 file = false;
48 }
49 }
50 }
51 }
52
53 do
54 {
55 System.out.println("Choose read or write (r/w):");
56 rw = keyboard.nextLine();
57 if (rw.equalsIgnoreCase("r"))
58 {
59 FileInputStreamText = new Scanner(new FileInputStream(outputStream + ".txt"));
60 String textLine = null;
61 }
62 else
63 {
64 System.out.println("Enter a line to write to the file:");
65 line = keyboard.nextLine();
66 System.out.println("Would you like to enter another line? (y/n)");
67 yn = keyboard.nextLine();
68 if(yn.equalsIgnoreCase("n"))
69 {
70 file = false;
71 }
72 }
73 }while(tb.equalsIgnoreCase("t"));
74 System.out.println("Process completed");
75 }
76 }

In: Computer Science

Prompt user to enter an integer number from console. Use 2 methods to multiply this number...

Prompt user to enter an integer number from console. Use 2 methods to multiply this number by factor 7, display result. This is required to be done in MIPS Assembly Language.

In: Computer Science

I am struggling with this java code ublic class HW2_Q4 {    public static void main(String[]...

I am struggling with this java code

ublic class HW2_Q4 {

   public static void main(String[] args) {

       // Define the input string. Note that I could have written it all on a
       // single line, but I broke it up to match the question.
       String input = "Book , Cost , Number\n"
                   + "Hamlet , 24.95 , 10\n"
                   + "King Lear , 18.42 , 13\n";
      
       // Construct a Scanner, but have it read the String defined above,
       // rather than System.in. Note that I'm leaving the name of the
       // variable as "keyboard" so that it matches the question.
       Scanner keyboard = new Scanner(input);
      
       // Declare and initialize variables to store the total cost and number.
       double totalCost = 0;
       int totalNumber = 0;

       // Write your code below using only these variables. Your code
       // should not contain literal values. For instance, do not calculate
       // the total cost with the statement "totalCost = 24.95 + 18.42".
       // Instead, use the Scanner to read the values from the keyboard.

In: Computer Science

Python DESCRIPTION Write a program that will read an array of integers from a file and...

Python

DESCRIPTION

Write a program that will read an array of integers from a file and do the following:

Task 1: Revert the array in N/2 complexity time

(i.e., number of steps)

.

Task 2: Find the maximum and minimum element of the array.

INPUT OUTPUT

Read the array of integers from a file named “

inputHW1.txt

”. To do this, you can use code snippet

from the “

file.py

” file. This file is provided in

Canvas. Copy the “

read

” function from this file and

paste it to your program file. Then, if you call the read function like the following:

numbers = read()

# The following "read" function reads values from a file named "inputHW1.txt" and

returns the values in an array.

def read():

file = open("inputHW1.txt", "r")

line = file.readline()

values = []

for value in line.split(' '):

values.append(int(value))

return values

the integers will be read from file and loaded in the numbers array.

Now, print the reverted arra

y, minimum element and maximum element of the array.

For example, if the input array is: 1 4 9 11 8 3 2 5 10

the following will be printed on the screen:

Reverted array: 10 5 2 3 8 11 9 4 1

Maximum element: 11

Minimum element: 1

EXTRA CREDIT - 30%

Find the trend change points of the array. You will get

30% extra credit

for doing this task.

Trend

change points are those points where the array

changes its direction

and

goes from

increasing to decreasing order or decreasing to increasing order.

Note that, you have to find the trend change points of the input array, not the reverted array.

For example, if the input array is: 1 4 9 11 8 3 2 5 10

the following will be printed on the screen:

Trend change points: 11 8 5

In: Computer Science

/* Homework Lab 6 This program does not work. There are three errors that you will...

/* Homework Lab 6

This program does not work. There are three errors that you will need to fix:

TODO: Fix the following 3 errors.

ERROR #1) The compiler knows there is something wrong, and it will issue a
warning and and two error messages, all related to the same problem.
       Read the error and warning messages carefully to point you in the
       right direction. Did you know if you double-click on an error
       message (in the Error List) that it will take you to the spot in
       your program where the compiler detects the problem? Also, get
       in the habit of ALWAYS reading messages carefully. You may not
       understand them right now, but over time you will come to understand
       the messages better and better. One of these three messages will be
       most helpful, but it is still informative to see that the other two
       messages come as a result of this single problem.

ERROR #2) After fixing ERROR #1 your program will run. However, you will get
incorrect results. It will say "Congratulations!" even when not perfect.

ERROR #3)

But when you find and fix that error, something still lurks behind that the
compiler does not complain about and that will give incorrect output. The output
will still display a zero after the decimal point even if it should be .3 or .7...

IMPORTANT NOTE ON ERROR #3: You are NOT allowed to change the data type of any constant
or variable to make this work. You also MUST divide by NUM_OF_SCORES
when calculating the average.
*/

//------------------------------------------------------------------------------
#include <iostream>
#include <iomanip>
using namespace std;

//------------------------------------------------------------------------------

int main()
{
   int score1; // To hold three test scores
   int score2;
   int score3;
   double average; // To hold the average score

   const int NUM_OF_SCORES = 3;

   // Get the three test scores.
   cout << "Enter 3 test scores and I will average them: ";
   cin >> score1 >> score2 >> score3;

   // Calculate and display the average score.
   average = (score1 + score2 + score3) / NUM_OF_SCORES;
   cout << fixed << showpoint << setprecision(1);
   cout << "Your average is " << average << endl;

   // Follow up with a message.
   if (average = 100);
       cout << "Congratulations! Those are all perfect scores" << endl;
   else
       cout << "Not perfect yet - Better luck next time." << endl;

   cout << endl;

   return 0;
}

/* Sample program interactions:
------------------------------------------------------------------------------
BEFORE FIXING ERROR #1:
======================
The program will not run!


AFTER FIXING ERROR #1:
======================

Test #1:
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 100 100 100
Your average is 100.0
Congratulations! Those are all perfect scores

Press any key to continue . . .


Test #2:
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 70 80 90
Your average is 80.0
Congratulations! Those are all perfect scores

Press any key to continue . . .

AFTER FIXING ERROR #2:
======================

Test #1:
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 100 100 100
Your average is 100.0
Congratulations! Those are all perfect scores

Press any key to continue . . .

Test #2:
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 70 80 90
Your average is 80.0
Not perfect yet - Better luck next time.

Press any key to continue . . .

Test #3 (use calculator to see what this average should be):
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 72 80 90
Your average is 80.0
Not perfect yet - Better luck next time.

Press any key to continue . . .

AFTER FIXING ERROR #3:
======================

Test #1:
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 100 100 100
Your average is 100.0
Congratulations! Those are all perfect scores

Press any key to continue . . .

Test #2:
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 70 80 90
Your average is 80.0
Not perfect yet - Better luck next time.

Press any key to continue . . .

Test #3:
-----------------------------------------------------------------------------
Enter 3 test scores and I will average them: 72 80 90
Your average is 80.7
Not perfect yet - Better luck next time.

Press any key to continue . . .

*/

In: Computer Science

Create a C++ program that will prompt the user to input an positive integer number and...

Create a C++ program that will prompt the user to input an positive integer number and output the corresponding number to words. Check all possible invalid input data. (Please use only switch or if-else statements. Thank you.)

In: Computer Science

Create your own data. Ensure the data will test all criteria and prove all sorts worked...

Create your own data. Ensure the data will test all criteria and prove all sorts worked as required. Be sure that all tables and queries have descriptive names. “Query 1” and “Step 1” are examples of poor names.

Step 1

Build a Database named DBMS Course Project. The database should include the following tables:

  • First Table – Students
    • ID
    • First Name
    • Last Name
    • Address
    • City
    • State
    • Zip Code
    • Phone Number with area code
  • Second Table – GPA
    • ID Current GPA (two decimal positions)
    • Class (numeric field, 1 = Freshman, 2 = Sophomore, etc.)
      • Freshman
      • Sophomore
      • Junior
      • Senior
      • Graduate Student
  • Third Table – Scholarships
    • ID
    • Major course of study
    • Academic Scholarship (Use Yes/No data type)
    • Athletic Scholarship (Use Yes/No data type)

Step 2

Extract the First and Last Name, Address, City, State, Zip Code and Phone Number of each Senior on the database. Sort by Last Name, then First Name (1 sort).

Step 3

Extract the First and Last Name, and GPA of each student who qualifies for the Dean’s List. Sort by GPA, then Last Name, then First Name (1 sort). A GPA of 3.25 is required to make the Dean’s List.

In: Computer Science

Write a program that asks the user for a Fahrenheit temperature and calls a function name...

Write a program that asks the user for a Fahrenheit temperature and calls a function name Celsius that returns the temperature in Celsius of the Fahrenheit temperature sent to it. Your function will look similar to this: double celsius(double f)

{

double c;

:

:

return c;

}

In: Computer Science

write a member function in C++ , that takes two lists and return list that contain...

write a member function in C++ , that takes two lists and return list that contain the merge of the two lists


in the returned list: first insert the first list and then the second list  

In: Computer Science

Accounting Program in c++ Write a class to keep track of a balance in a bank...

Accounting Program in c++

Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the balance and the interest rate to some initial values (with defaults of zero). The class should have member functions to change or retrieve the current balance or interest rate. There should also be functions to make a deposit (add to the balance) or withdrawal (subtract from the balance). You should not allow more money to be withdrawn than what is available in the account, nor should you allow for negative deposits. Finally, there should be a function that adds interest to the balance (interest accrual) at the current interest rate. This function should have a parameter indicating how many months’ worth of interest are to be added (for example, 6 indicate the account should have 6 months’ added). Interest is accrued from an annual rate. The month is representative of 1/12 that amount. Each month should be calculated and added to the total separately. For example: 1 month accrued at 5% APR is Balance = ((Balance * 0.05)/12) + Balance; For 3 months the calculations you repeat the statement above 3 times. Use the class as part of the interactive program provided below.

In: Computer Science

Using Java Write the class RecursiveProbs, with the methods listed below. Write all the methods using...

Using Java

Write the class RecursiveProbs, with the methods listed below. Write all the methods using recursion, NOT LOOPS. You may use JDK String Methods like substring() and length(), but do not use the JDK methods to avoid coding algorithms assigned. For example, don’t use String.revers().

public boolean recursiveContains(char c, String s) {

if (s.length() == 0)

return false;

if (s.charAt(s.length() - 1) == c)

return true;

else

return recursiveContains(c, s.substring(0, s.length() - 1));

}

public boolean recursiveAllCharactersSame(String s) return true if all the characters in the String are identical, otherwise false. if the String has length less than 2, all characters are identical.   

public String recursiveHead(int n, String s) returns the substring of s beginning with the first character and ending with the character at n-1; in other words, it returns the first n characters of the String. Return empty String("") in cases in which n is zero or negative or exceeds the length of s.

Write either a main() or a JUnit test case for test

In: Computer Science