Questions
Write an Application that extends the Thread class, call it MyThread.java. Have your new class accept...

Write an Application that extends the Thread class, call it MyThread.java. Have your new class accept an integer(i.e. 200) when it is instantiated. (MyThread mt = new MyThread(200); )
This integer number will be the number of times that this class loops and prints a message. The message should read “Thread Running...200”. The 200 would be whatever number is passed into the constructor. If the number was 300, then the output should read “ Thread Running ..... 300”. Use a main method to test this class. In the main start 2 Threads, one Thread with 250 and one Thread with 300. What happens? You do not need to use the sleep() method for this exercise.

  1. 2.) Modify 1.) from above. Change this class to use the Runnable Interface instead of the Thread class. Any difference how the code runs?

  2. 3.) Lastly, have the main method start 4 different threads, all with different loop counts. Test the application, what happens?

PLEASE provide a screenshot or image of the code running!

In: Computer Science

SWITCH CASE, WHILE, DO WHILE STRUCTURES, using ARDUINO. Urgent Please for Arduino! Implement the following programs,...

SWITCH CASE, WHILE, DO WHILE STRUCTURES, using ARDUINO. Urgent Please for Arduino!

Implement the following programs, attach a flow chart, photos of its operation and use your own values.
1. Read a number that represents the month and say what months it is.
2. Using the conditional "while" calculate the factorial of a number
3. Using the “do-while” conditional, make a program that prints all numbers from 1 up to a maximum number entered by the user.

In: Computer Science

This task is solved in Python 3. Develop a program that lets the user add new...

This task is solved in Python 3.

Develop a program that lets the user add new people to the file phone.txt

Add name and number, end with <enter>

Name and number: Robin 94567402

Name and number: Jessica 99468283

Name and number:

>>>

Phone.txt

Expanded to ------>

Phone.txt

Mary 98654321 June 99776655 Chris 99112233 Viv 98554455 John 99776612 Joe 97888776 Rick 99455443 Susan 98122134 Jill 99655732

Bob 98787896

Mary 98654321

June 99776655

Chris 99112233

Viv 98554455

John 99776612

Joe 97888776

Rick 99455443 Susan 98122134 Jill 99655732

Bob 98787896

Robin 94567402 Jessica 99468283

In: Computer Science

The equation A = Ao * e^(-t(log2/h)) is used to model the decay of radioactive materials....

The equation A = Ao * e^(-t(log2/h)) is used to model the decay of radioactive materials. Where A is the amount of material at time t, A0 is the amount at time 0 and h is the half-life.

Write a program that prompts for a decay time and how long of an interval you want to look at. Then write the code that creates a table with the appropriate information.

For example, the decay rate is 6 months for material xyz. What does it look like over 30 hours?

In: Computer Science

Respond to the following in a minimum of 175 words: Risk appetite is the quantity and...

Respond to the following in a minimum of 175 words:

Risk appetite is the quantity and nature of risk that organizations are willing to accept as they evaluate trade-offs between "perfect security" and unlimited accessibility. Often when a risk is examined in detail, the result or the risk appetite can result in a decision to expand their capacity to handle that risk in order to take advantage of the business opportunity, or it might result in a decision not to move forward with that opportunity.

Consider risks that exist at a typical small business. Provide an example of determining the risk appetite of the small business to a specific risk. How would you determine what to examine, what data to use in that examination, and what the risk appetite is?

In: Computer Science

This task is solved in Python 3. Develop a program that can change the phone number...

This task is solved in Python 3.

Develop a program that can change the phone number of a person in phone.txt (hint: the easiest thing is probably to make a new version of the file, and then delete the old one before the new is renamed to phone.txt)

Name: John

Old phone number: 99776612

New number: 99889999

>>>

phone.txt

Replaced by ------>

phone.txt

Mary 98654321

June 99776655

Chris 99112233

Viv 98554455

John 99776612

Joe 97888776

Rick 99455443

Susan 98122134

Jill 99655732

Bob 98787896

Mary 98654321

June 99776655

Chris 99112233

Viv 98554455

John 99889999

Joe 97888776

Rick 99455443

Susan 98122134

Jill 99655732

Bob 98787896

In: Computer Science

Write the program WritePatientRecords that allows a doctor’s staff to enter data about patients and saves...

Write the program WritePatientRecords that allows a doctor’s staff to enter data about patients and saves the data to a file called Patients.txt. The output should be in the following format: p#, PATIENT_NAME, BALANCE. Create a Patient class that contains fields for ID number, name, and current balance owed to the doctor’s office.

using System;
using static System.Console;
using System.IO;
class WritePatientRecords
{
static void Main()
{
// Your code here
}
}

In: Computer Science

Create the following classes and show a “Hierarchical” relationship between them:           Company, Products and Employee...

Create the following classes and show a “Hierarchical” relationship between them:     

     Company, Products and Employee   

  • Define at least 2 instance variables of these classes.
  • company: company_code, company_name
  • Employee: employee_ name, number_of_employees.
  • Choose the appropriate members for Products by your own understanding.
  • Write default and overloaded constructors for each class
  • Include a method in all the classes by the same name that overrides the direct or indirect base classes.

In: Computer Science

Problem Description Objective This practical will test your capability of implementing a linked list. Design Think...

Problem Description

Objective

This practical will test your capability of implementing a linked list.

Design

Think of how you are going to solve the problem and test your implementation with the test cases you designed based on the stages below.

Testing Hint: it’s easier if you test things as a small piece of code, rather than building a giant lump of code that doesn’t compile or run correctly. As part of your design, you should also sketch out how you are going to build and test the code.

Problem

Linked lists are dynamic data structures that allow storing a list of items in separate places in the memory. Each item of the list, together with the address of the next item, is placed in one object of type Node (find the description below). The last node of the list should include the last item and a null pointer (NULL or nullptr).

Lists, as abstract data types, can be implemented by different structures, including arrays, vectors and linked lists. Please do not use arrays or vectors for this practical. In this practical, you should write the code for two classes named LinkedList, and Node.

You must include separate header and implementation files for both classes. The class Node should consist of two member variables, an integer data and a pointer to Node next, and 5 functions, a constructor, and getter and setter for the two member variables.

The class LinkedList must have only one member variable: head, which is of type pointer to Node. If the list is empty, head should contain NULL or nullptr. It should also have at least the following member functions. Note that add functions should construct nodes from the heap, and delete functions should manually delete the one that is removed from the list. Don’t forget to write test cases for each function and ensure that the tests pass before progressing to the next function.

  • void addFront(int newItem) : The function inserts a new node, containing the newItem, at the beginning of the list.
  • void addEnd(int newItem) : The function inserts a new node, containing the newItem, at the end of the list.
  • void addAtPosition(int position, int newItem) : The function inserts a new node, containing the newItem, such that it is the position-th member of the list. i.e. we assume the first element of the list is in position 1. If position is larger than the size of the list, the new item is added to the end of the list. If position < 1, the new item is added at the beginning of the list.
  • int search(int item) : The function searches the list for the first instance of the item, and if found, both prints the position of the of the item (followed by a space) and returns the position of the item in the list (positions start from 1). If not found, both prints 0 (followed by a space) and returns 0. Note that the returning type is different from what was explained in the search function in the lecture.
  • void deleteFront() : The function deletes the first element of the list.
  • void deleteEnd() : The function deletes the last element of the list.
  • void deletePosition(int position) : The function deletes the element at the given position of the list. If the position < 1 or it is larger than the size of the list, only print ”outside range”.
  • int getItem(int position) : The function both prints the value of the item (followed by a space) and returns the value of the item at the given position of the list, If beyond the size of the array, both prints std::numeric_limits < int >::max() (followed by a space) and returns std::numeric_limits< int >::max(). You should include <limits> for this. Take a look at
    http://www.cplusplus.com/reference/limits/numeric_limits/ if you need.
  • void printItems() : The function prints the value of the items of the list from head to tail. In case of an empty list, it does not print anything
  • A constructor with no parameters, which makes an empty list.
  • A constructor that takes an array of integers and makes a linked list, containing all the elements of the array, in the same order. As the second parameter, it takes the size of the array.
  • A destructor that manually deletes all the elements that are still in the list.

Note that the printing in the functions search and getItem is for the purpose of easy testing.

Main function

The test script will compile your code using

g++ -o main.out -std=c++11 -O2 -Wall *.cpp

  

It is your responsibility to ensure that your code compiles on the university system. g++ has too many versions, so being able to compile on your laptop does not guarantee that it compiles on the university system. You are encouraged to debug your code on a lab computer (or use SSH).

You are asked to create a main function (main.cpp). It takes in one line of input.
  

int1 int2 ... intn FUNCTIONINITIAL param1 param2

int1, until intn are integers, separated by space, which should be placed in an integer array, and passed to the linked list constructor. For simplicity, we assume that the size of this array never exceeds 100; therefore, you can take an static array with the size of 100.

After the elements of the list, the input consists of an string, denoting a function, followed by its parameters. The string is one of these:

  • AF standing for addFront
  • AE standing for addEnd
  • AP standing for addAtPosition
  • S standing for search
  • DF standing for deleteFront
  • DE standing for deleteEnd
  • DP standing for deletePosition
  • GI standing for getItem

Call the indicated function with its parameter. If the function has only one parameter, then the last integer value from the input is not used. At the end, call the function printItems, to produce the required output.

  

Sample input: 5 2 7 10 AP 3 9

expected output: 5 2 9 7 10

Sample input: 3 4 2 1 DP 3 0

expected output: 3 4 1

Sample input: 45 20 2 10 GI 3 0

expected output: 2 45 20 2 10

In: Computer Science

Trace the following program. This means you need to fill the table in which you show...

Trace the following program. This means you need to fill the table in which you show the output of each executed instruction as if you are the computer executing the program. Put your comments under the table.

#include<iostream>

using namespace std;

int main ()

{

cout.setf(ios :: fixed);

cout.setf(ios :: showpoint);

cout.precision(2);

int A=7.5, B=2.5, C;                                                                                        //statement 1

double X,Y;

char Letter;

C = A/B;                                                                                                          //statement 2

X = 1.0*A/B;                                                                                                    //statement 3

if (C<X)

        Letter = 30*C;                                                                                         //statement 4

if (C=X)

        Letter = 20*C;                                                                                         //statement 5

if (C>X)

        Letter = 10*C;                                                                                         //statement 6

cout << "Letter = " << Letter+10 << endl;                                                       //statement 7

Letter = Letter + 10;                                                                                        //statement 8

cout << "Letter = " << Letter << endl;                                                             //statement 9

Y = 1.0*(A/B);                                                                                                 //statement 10

X = Y/ (B+5) + 2.5;                                                                                          //statement 11

cout.precision(1);

cout << "X = " << X << endl;                                                                           //statement 12

return 0;

}

In: Computer Science

Correct and complete this C++ program. You are not allowed to include a directory nor changing...

Correct and complete this C++ program. You are not allowed to include a directory nor changing a variable type or a loop syntax. Stick on the number of lines.

#include<iostream>

using namespace std;

int main ()

{

int N1, N2;

int power;

cout<<"Please enter N1 and N2 in order to calculate N1^N2. N1 should be a positive number. N2 should be between -9 and 9.\n";

cin>>N1>>N2;

while (…………..)

{

cout<<………………………………………….

cin>>………………………………………….

}

while (…………..)

{

cout<<………………………………………….

cin>>………………………………………….

}

……………………………………………..

if(power>0)

{

for(………… ; ………… ; …………)

………………………………………….

cout<<………………………………

}

else if(power<0)

{

for(………… ; ………… ; …………)

………………………………………….

cout<<………………………………

}

else

cout<<………………………………

return 0;

}

In: Computer Science

Write a C++ program to computer the nth Fibonacci Number in 3 ways. Clearly define which...

Write a C++ program to computer the nth Fibonacci Number in 3 ways. Clearly define which way you are solving in your code using comments. You must provide an algorithm to solve for the nth Fibonacci Number in 1. a straight-forward recursive solution 2. a top-down memoized solution and 3. a bottom-up dynamic programming solution. These algorithms will be tested with randomly generated input, and a single non-negative number will be given through command line.

In: Computer Science

JAVA (1) Create two files to submit: ItemToPurchase.java - Class definition ShoppingCartPrinter.java - Contains main() method...

JAVA

(1) Create two files to submit:

  • ItemToPurchase.java - Class definition
  • ShoppingCartPrinter.java - Contains main() method

Build the ItemToPurchase class with the following specifications:

  • Private fields
    • String itemName - Initialized in default constructor to "none"
    • int itemPrice - Initialized in default constructor to 0
    • int itemQuantity - Initialized in default constructor to 0
  • Default constructor
  • Public member methods (mutators & accessors)
    • setName() & getName() (2 pts)
    • setPrice() & getPrice() (2 pts)
    • setQuantity() & getQuantity() (2 pts)

(2) In main(), prompt the user for two items and create two objects of the ItemToPurchase class. Before prompting for the second item, call scnr.nextLine(); to allow the user to input a new string. (2 pts)

Ex:

Item 1
Enter the item name:
You entered: Chocolate_Chips

Enter the item price:
You entered: 3

Enter the item quantity:
You entered: 1



Item 2
Enter the item name:
You entered: Bottled_Water

Enter the item price:
You entered: 1

Enter the item quantity:
You entered:10


(3) Add the costs of the two items together and output the total cost. (2 pts)

Ex:

TOTAL COST
Chocolate_Chips 1 @ $3 = $3
Bottled_Water 10 @ $1 = $10

Total: $13

In: Computer Science

4. DNS hijacking is a common technique that is used by censors (i.e., networks who perform...

4. DNS hijacking is a common technique that is used by censors (i.e., networks who perform censoring actions), where fake DNS responses can be injected. As a DNS request could traverse a number of routers along the path, each router along the path could inject a fake DNS response. In the paper “The Collateral Damage of Internet Censorship by DNS Injection”, authors use a technique similar to traceroute to identify the router that actually injects the fake DNS response. Authors deliberately decrease the TTL (time-to-live) value in the IP header to monitor ICMP packet and fake DNS response to decide the router that injects fake response. In this paper, DNS is built on UDP. However, DNS can also be built on top of TCP. This expands the attack surface for attackers. Specifically, the censors inject RST packets to both the client and the server in one TCP connection if a DNS query in this connection carries “sensitive” information. Different from UDP, TCP requires three-way handshake. Therefore, the packet that carries sensative information (e.g., a TCP-based DNS query) will be the packet that comes later than packets for three-way handshake. Let us make the following assumptions for this question 1. We assume that DNS over TCP is using a publicly-known port number. 2. Censors are stateless, which means that they will not consider whether a TCP packet belongs to an established connection. They make decision based on each individual packet instead of packets belonging to the same connection. In order to make the method discussed in “The Collateral Damage of Internet Censorship by DNS Injection” to be useful in this new setting, we need to make a few changes of this method. Question: Please verify whether each of the following changes is needed or not (1 Point). And please justify your answer (1 Points). a. When you select a target IP to send honey queries, this IP should never respond you with TCP RST packets if you send a TCP-based DNS query to this IP. b. When you send out a honey query (a TCP-based DNS query with a sensitive domain) to a target IP, you can directly send this TCP-based DNS query to this target IP without establishing a TCP connection with the target IP (i.e., through 3-way handshake). c. You should now expect RST packets from the censor rather than a forged DNS response.

In: Computer Science

Problem Description: Game: Bean Machine or Galton Box To figure out if the ball falls to...

Problem Description: Game: Bean Machine or Galton Box

To figure out if the ball falls to Left or Right, you can generate a random number using Math.random(). If this random number is greater than or equal to 0.5 we assume the ball falls to the Right otherwise it falls to the Left (or vise versa).

If there are 8 slots, the ball should hit 7 nails (8 -1), thus you should run a loop 7 times to figure out the path for that ball. If you have N balls, this whole process should be repeated N times. Here is a basic algorithm.

# of balls = N

# of slots = K

array of K elements

for ( i = 0 to N) {

   int R = 0;

   for (j = 0 to K-1) {

        if ( random number >= 0.5)

                  R++;

}//end loop j

array[R] ++;

}// end loop i

Output the array to show how many balls are in each slot.

Things to DO!!!!!

Analysis: (3 points)

(Describe the problem including inputs and outputs in your own words.)

Design: (3 points)

(Describe the major steps in your algorithm for solving the problem.)

Coding: Write a well documented and properly indented Java source program. Your program should have a block comment with your name and a statement of purpose at the very top. Use meaningful variable names. You must have proper labels and informative statements for all inputs and outputs. (10 points)

Testing: (Describe how you test this program, you should use your own input data to test not just the test cases given in sample runs.) (4 points)

Test your program according to following test schedule and generate output to show the number of balls in each slot.

N K
10 8
50 10
100 20
500 30

What to Submit:

  1. A PDF with descriptions of Analysis, Design, and Testing. Must have a title with your name and assignment number. (Do not submit a Word document!!!!)
  2. Error free Java source program (Programs with syntax errors receive 0 credit) with methods, proper comments and indentation. Java source program is the program you wrote with .java file extension. (Do not submit a Word or any other document of your code!!!!)
  3. The Program outputs for the 4 different test cases in a PDF

In: Computer Science