Questions
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

one can tell by comparing nodes between two given trees whether they relate to each other,...

one can tell by comparing nodes between two given trees whether they relate to each other, by having a reflected symmetric structure (i.e. being mirror images of each other), having identical structure, or not being related at all. In this assignment, you are asked to implement the following features.
Hard-code some paired lists of integers.
Build binary search trees from each list
Print the binary search trees in the three orders discussed in class.
Determine if the two binary search trees are identical, mirrors of each other, or neither
Remove a number in each tree at random and compare the tree pair again

Further, since the methods of the binary search tree class have been presented with recursive function calls, it is now up to you to implement these recursive functions with iterative loops.

You must write a Class Node, a class TreeChecker and a class BinarySearchTree. For Java users, they must implement the following interfaces respectively:
public interface INode {

   //Getter of node data
   T getData();

   //Setter of node data
   void setData(T data);

    INode getLeftChild() ;

   void setLeftChild(INode leftChild) ;

   INode getRightChild() ;

   void setRightChild(INode rightChild);
  
}
public interface ITree {
   void setRoot(INode root);
INode getRoot();
void preorder();   // print tree in a preorder traversal
void inorder();   // print tree in an inorder traversal
void postorder();   // print tree in a postorder traversal
INode insert(INode root, T data); // insert data into tree
   INode remove(INode root, T data); //search/remove node with data
   T search(INode root, T data); //search and return data if it exists
   INode getMax(INode root); //return node with maximum value of subtree
   INode getMin(INode root); //return node with minimum value of subtree
}  
public interface ITreeChecker {
  
boolean isMirror(ITree root1, ITree root2); // check if two trees are mirror
// images
   boolean isSame(ITree root1, ITree root2); // check if two trees are identical
}

Then if you could run the code in this main class.

public class Main {

   public static void main(String[] args) throws IOException {  
       // build a tree for the following lists
// int array1[] = [4,1,9,12,3,2,8,7,16,20,13,11];
       // int array2[] = [4,1,9,12,3,2,8,7,16,20,13,11];

       //add more examples here

       Bst1 = new BinarySearchTree();
       Bst2 = new BinarySearchTree();
      
      
       //more trees for each example

       treeChecker = new TreeChecker();

       //build each BST

       //print each tree with each order of traversal

       //compare bst1 and bst2 as mirror images with tree checker
       If(treeChecker.isMirror(bst1, bst2))
           Print messages saying the trees are mirrors of each other
       // compare bst1 and bst2 as being identical with tree checker
       Else If(treeChecker.isSame(bst1, bst2))
           Print messages saying the trees are identical to each other
       Else
           Print message saying the trees are not related

       //randomly remove a number from each tree
       //compare bst1 and bst2 again

// more code here to finish regarding comparing the other BST pairs…
}

In: Computer Science

#include <stdlib.h> #include <stdio.h> #include <string.h> void clrScreen(int lines){     int i = 0;     for( i =...

#include <stdlib.h>

#include <stdio.h>

#include <string.h>

void clrScreen(int lines){

    int i = 0;

    for( i = 0; i < lines; ++i ){

        printf("\n");

    }

    return;

}

void printRules(void){

    printf("\t|*~*~*~*~*~*~*~*~*~ How to Play ~*~*~*~*~*~*~*~*~*~|\n");

    printf("\t|   This is a 2 player game. Player 1 enters the   |\n");

    printf("\t|   word player 2 has to guess. Player 2 gets a    |\n");

    printf("\t|   number of guesses equal to twice the number    |\n");

    printf("\t|   of characters. EX: If the word is 'example'    |\n");

    printf("\t|   player 2 gets 14 guesses.                      |\n");

    printf("\t|*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~|\n");

    clrScreen(10);

    return;

}

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

/* /\DO NOT MODIFY ABOVE THIS LINE /\*/

void playGame(){

int correctGuess = 1;

    char garbage;

clrScreen(40);

    printRules();

    printf("Player 1: Enter a word smaller than 50 characters: ");

    clrScreen(40);

    if( -1 == correctGuess ){

        printf("CoNgRaTuLaTiOnS!!!!!! You figured out the word!!!\n");

        printf("\t\t%s\n");

    } else {

        printf("You didn't figure out the word.....it was %s\n");

        printf("Better luck next time!\n");

    }

    printf("Press 'enter' to continue to main menu.\n");

    scanf("%c", &garbage);

}

int menu(void){

    int loop = 1;

    while( loop ){

        clrScreen(40);

        printf("*~*~*~*~*~*~*~*~*~*~Welcome to Hangman!*~*~*~*~*~*~*~*~*~*~\n");

        printf("\t1.) Play the game\n");

        printf("\t2.) Quit\n");

        printf("Please make a selection: ");

    }

}

/*

    hangman game RULES:

    2 player game

        player 1

            enter a word for player 2 to guess

            enter a number of guesses player 2 gets to have. It must be at least 2x as big

                as the number of letters in the word.

            For example, if you enter the word 'sky' you must give the player at least 6 guesses.

        player 2

            try to guess the word player 1 has entered.

            you get X number of guesses

*/

int main(void){

    return 0;

}

//In c programming language

//please help me finish this hangman program. Thank you.

In: Computer Science

PYTHON LANGUAGE PLEASE DO NUMBER 5 ONLY """ # 1. Based on Textbook R6.28 # Create...

PYTHON LANGUAGE

PLEASE DO NUMBER 5 ONLY

"""
# 1. Based on Textbook R6.28
# Create a table of m rows and n cols and initialize with 0
m = 3
n = 4

# The long way:
table = []
for row in range(m) :
table.append([0]*n)   

# The short way:

# 2. write a function to print the table in row, column format,
# then call the function
'''
# using index
def printTable(t):
for i in range(len(t)) : # each i is an index, i = 0,1,2
for j in range(len(t[i])) : # j = 0,1,2,3
print(t[i][j], end=' ')
print()
'''
# without index:
def printTable(t):
for row in t :
for col in row :
print(col, end=' ')
print()
print()

printTable(table)


# what does the following print?

for i in range(m):
for j in range(n):
table[i][j] = i + j

printTable(table)
'''
Answer:
print: from these index values:
0 1 2 3 [0,0] [0,1] [0,2] [0,3]
1 2 3 4 [1,0] [1,1] [1,2] [1,3]
2 3 4 5 [2,0] [2,1] [2,2] [2,3]
'''
  
# 3. copy table to table2
table2 = copy.deepcopy(table)

'''
table2 = table => table2 is another reference to the same mem location
table2 = table.copy() => shallow copy
only copy the 1D list (outer list) of references,
which has row1 - row4 references
table => [ row1 => [ , , , ]
row2 => [ , , , ]
row3 => [ , , , ]
row4 => [ , , , ]
]
'''
  
table[0][0] = -1 # will table2 be changed? No
printTable(table2)


# 4. fill elements of bottom row of table2 with -1's
# and all elements of left col of table2 with 0's

for i in range(len(table2[-1])) :
table2[-1][i] = -1
  
for i in range(len(table2)) :
table2[i][0] = 0
  
printTable(table2)
"""
"""
# 5. We start with a dictionary of student ids and associated gpa's
d = {123:3.7, 456:3.8, 789:2.7, 120:2.8}
print(d)

# create a list of sid list and a tuple of gpa from d

# create a list of tuples (k,v) from d

# How do you construct a dictionary from a list of tuples?


# How do you construct a dictionary from the list of id and gpa?


"""

In: Computer Science

Description Your program must start and keep dialog with the user. Please create the first prompt...

Description Your program must start and keep dialog with the user. Please create the first prompt for the dialog. After that your program must accept the user’s response and echo it (output to screen) in upper case and adding the question mark at the end. The program must run endlessly until the user say “stop” in any combination of cases. Then you program must say “GOODBYE!” and quit. Example: HELLO, I AM THE PROGRAM Hi, I am Michael HI, I AM MICHAEL? Are you kidding? ARE YOU KIDDING?? I prefer to speak to somebody smarter I PREFER TO SPEAK TO SOMEBODY SMARTER? Stupid STUPID? You YOU? sToP! STOP!? stop GOODBYE!

In: Computer Science

What is Stuxnet and what are its real-world implications? Should your national government be concerned about...

What is Stuxnet and what are its real-world implications? Should your national government be concerned about the potential of a Stuxnet-like attack? Why or why not.

In: Computer Science

Implement (provide pseudocode) the 'A la Russe' algorithm which does not use arrays.

Implement (provide pseudocode) the 'A la Russe' algorithm which does not use arrays.

In: Computer Science

C programming language only! a file is given that has comma-separated integers. the files contents are...

C programming language only!

a file is given that has comma-separated integers. the files contents are -1,-9,1,45,3,2,1,-1...

Create a function that takes as an input a filename and returns an array containing the list of integers in the file

In: Computer Science

((PYTHON)) Finish the calories_burned_functions.py program that we started in class. Take the original calories_burned program and...

((PYTHON))

Finish the calories_burned_functions.py program that we started in class. Take the original calories_burned program and rework it so that it uses two functions/function calls.

Use the following file to get your program started:

"""

''' Women: Calories = ((Age x 0.074) - (Weight x 0.05741) + (Heart Rate x 0.4472) - 20.4022) x Time / 4.184 '''
''' Men: Calories = ((Age x 0.2017) + (Weight x 0.09036) + (Heart Rate x 0.6309) - 55.0969) x Time / 4.184 '''
"""
#Declare Variable names and types

age_years = int(input())
weight_pounds = int(input())
heart_bpm = int(input())
time_minutes = int(input())

#Performing Calculations

calories_woman = ( (age_years * 0.074) - (weight_pounds * 0.05741) + (heart_bpm * 0.4472) - 20.4022 ) * time_minutes / 4.184

calories_man = ( (age_years * 0.2017) + (weight_pounds * 0.09036) + (heart_bpm * 0.6309) - 55.0969 ) * time_minutes / 4.184

#Print and format results in detail

print('Women: {:.2f} calories'.format(calories_woman))
print('Men: {:.2f} calories'.format(calories_man))

"""

#Here are the functions to this program

def calc_calories_woman(years, pounds, heartrate, minutes):
  
return ( (age_years * 0.074) - (weight_pounds * 0.05741) + (heart_bpm * 0.4472) - 20.4022 ) * time_minutes / 4.184

#This is the main part of the program

#------------------------------------------------------------------------------

#Prompt the user at the keyboard for the necessary information

age_years = int(input("Please enter your age: "))
weight_pounds = int(input("Please enter your weight: "))
heart_bpm = int(input("Please enter your heart rate: "))
time_minutes = int(input("Please enter the time: "))

#Calculate the calories

calories_woman = ( (age_years * 0.074) - (weight_pounds * 0.05741) + (heart_bpm * 0.4472) - 20.4022 ) * time_minutes / 4.184

calories_man = ( (age_years * 0.2017) + (weight_pounds * 0.09036) + (heart_bpm * 0.6309) - 55.0969 ) * time_minutes / 4.184

#Print the results

print('Women: {:.2f} calories'.format(calories_woman))
print('Men: {:.2f} calories'.format(calories_man))

In: Computer Science

Construct this program in C programming Please. Using a do/while loop, your program will ask/prompt the...

Construct this program in C programming Please.

Using a do/while loop, your program will ask/prompt the user to enter in a positive value representing the number of values they wish to have processed by the program or a value to quit/exit. If the user enters in a 0 or negative number the program should exit with a message to the user indicating they chose to exit. If the user has entered in a valid positive number, your program should pass that number to a user defined function. The user defined function will use a for loop to compute an average value. The function will use the number passed to it to determine how many times it will prompt the user to supply a value. The user may enter in any number value positive, floating point or negative. The for loop will continue to prompt the user, calculating the average of the values entered. The function should return the calculated value to the calling function. The calling function using the do/while loop should print out the average and then repeat the process until the user enters in the signal to stop as described previously.

In: Computer Science

Database - Data Control Language    Exercise Write few system and object privileges. Create user with...

Database - Data Control Language   

Exercise

Write few system and object privileges.

Create user with your name and grant above discussed system and object privileges to the user created. Revoke update and select from the user which you have created.

In: Computer Science

Sleeping Barber Problem where there is only 1 barber in the shop for x clients function...

Sleeping Barber Problem where there is only 1 barber in the shop for x clients

function Customer()

acquire(mutex)

if num_waiting < num_chairs then

num_waiting + 1

release(customer)

release(mutex)

acquire(barber)

Cutmyhair()

else

release(mutex)

end

end

function Barber()

while not breaking

acquire(customer)

acquire(mutex)

num_waiting - 1

release(barber)

release(mutex)

Clipaway()

end while

end

QUESTION: come up with the pseudocode for the clipaway() and cutmyhair() methods so that each client pays for there haircut and the barber gives each client a customized haircut.

Any language.

thank you in advance !!!

In: Computer Science

Using C++ Many software applications use comma-separated values to store and transfer data. In this program,...

Using C++

Many software applications use comma-separated values to store and transfer data.

In this program, you are asked to implement the movie_call function that will parse a string of the above structure into the corresponding movie name, rating, and movie length.

ex: In "movie name, rating, length", the movie name is "movie name", the rating is "rating", and the length of the movie is "lenght".

This is the code:
#include <iostream>

#include <string>

using namespace std;

/*

Replace the function body with appropriate statements to movie_call

a string of movie details into its corresponding movie name, rating,

and length.

*/

void movie_call (string movie, string& name, string& rating, string& length) {

int comma, comma1;

          comma = movie.find(",");

          name = movie.substr(0, comma);

          movie = movie.substr(comma + 1);

            comma1 = movie.find(",");

            rating = movie.substr(0, comma1);

          length = movie.substr(comma1 + 1);

}

int main() {

string movie_details;

cout << "Please enter information for one movie of your choice: ";

getline(cin, movie_details);

//Add appropriate statement(s) to call the movie_call function

//and display the name, rating, and length

return 0;

}

In: Computer Science