Questions
1 Objective The purpose of this assignment is to test your familiarity with Java I/O, and...

1 Objective The purpose of this assignment is to test your familiarity with Java I/O, and if-else statements. Please submit your file as ”Shipping.java”

2 The Backstory Amazon.com wants to try out it’s new ‘Delivery by Drone” service and has recruited you to write a Java console application to calculate the shipping cost. They are going to charge the customer based on various criteria, as shown below:

Weight (in kg) Rate per 50 miles

2 or less

Over 2 Kg, up through 6 Kg

Over 6 Kg, up through 10 Kg

Over 10 Kg, up through 20 Kg

$5.10

$10.18

$22.43

$40.60

Amazon Prime members get a 10% discount.

3 Specifications

• First, ask for the weight of the package (in kilograms). The user can enter this as a decimal number, so use type double. Values of 0 or less are invalid (i.e. a package has to weigh something). Do not accept weights of more than 20 Kg either, as this is the maximum weight the company will ship).

• If the user enters an invalid choice, print an appropriate error message and abort the program. (See sample outputs for error messages).

• Now ask the user to enter the distance to ship the package (in miles). This will be entered as an integer. 0 miles or less is considered invalid (must be a positive distance to ship). Also, do not accept distances of more than 3000 miles - consider 3000 miles to be the company’s maximum shipping distance.

• If the user enters an invalid choice, print an appropriate error message and abort the program. (See sample outputs for error messages).

• For a valid weight and distance, compute the shipping charges according to the chart above, noting that ”rate per 50 miles shipped” means that anything up to 50 miles is at the 50 mile rate, anything above 50 up to 100 miles is at the 100 mile rate, and so on.

• Ask if the user is an Amazon Prime member. If the user says Yes, give them a 10% discount.

• Print out the following results: – The package weight (default format), in kilograms. – The shipping rate for this package, to 2 decimal places, (money format). – The number of miles chosen. – The calculated shipping cost, to 2 decimal places (money format).

• See the Sample Runs below for expected output messages and numerical output formats.

• Also note: The System library has a method called exit(), which will cause a program to terminate immediately. It requires a parameter - usually, it is sufficient to just pass in the value 0

4 Sample Runs

Sample Run 1:

Welcome to Amazon Shipping Calculator

Please enter the weight of the package, in Kg: 19.4

Please enter the distance to be shipped (in miles): 2318 Are you an Amazon Prime member? (Yes/No): No

Package weight = 19.4 Kg Shipping rate = $40.60 per 50 miles Number of miles = 2318

Total shipping charges = $ 1908.20

Goodbye

Sample Run 2:

Welcome to Amazon Shipping Calculator

Please enter the weight of the package, in Kg: 8.4 Please enter the distance to be shipped (in miles): 134

Are you an Amazon Prime member? (Yes/No): Yes

Package weight = 8.4 Kg Shipping rate = $22.43 per 50 miles Number of miles = 134

Total shipping charges = $ 60.56

Goodbye

Sample Run 3 (error case): Welcome to Amazon Shipping Calculator

Please enter the weight of the package, in Kg: -5 Invalid package weight. Program aborted

Sample Run 4 (error case): Welcome to Amazon Shipping Calculator

Please enter the weight of the package, in Kg: 21.8 Cannot accept packages over 20 Kg. Program aborted

In: Computer Science

examples of decision characteristics at Strategic, Managerial and Operational level.

examples of decision characteristics at Strategic, Managerial and Operational level.

In: Computer Science

Consider the two languages below: L1 = {w | w є {0,1,2}* and is of the...

Consider the two languages below:
L1 = {w | w є {0,1,2}* and is of the form 0i1j2k where i, j and k ≥ 0 and i = j or j = k}
L2 = {w | w є {0,1,2}* and is of the form 0i1j2k where i, j and k ≥ 0}
One of the languages in the above problem is regular. Which one? Prove it.
Prove that the OTHER one is not regular.
Is the non-regular one context free? Prove it

In: Computer Science

Replace <missing code> with your answer. Your code should approximate the value of π (~3.141592653589793). You...

Replace <missing code> with your answer. Your code should approximate the value of π (~3.141592653589793). You can approximate pi using the following formula:

π = 4 * (1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + 1/13 - 1/15 + …)

For this problem, let n be the number of terms to add in the series. For example, if n = 5, your code should compute the following: 4 * (1 - 1/3 + 1/5 - 1/7 + 1/9). If n = 3, your code should compute 4 * (1 - 1/3 + 1/5)

public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();

int piApprox = <missing value>;

<missing code>

System.out.println("piApprox = " + piApprox);

}

In: Computer Science

What is a good website that uses visual organization and a very bad one. explain how...

What is a good website that uses visual organization and a very bad one. explain how each of the 4 principles (proximity, alignment, consistency, contrast) of visual organization are applied well or not applied.

In: Computer Science

Create a Java Program to calculate compound interest. This can all be done in the main()...

Create a Java Program to calculate compound interest.

This can all be done in the main() method.

  1. Create a double variable named currentBalance.
  2. Create a double variable named newBalance.
  3. Create a final double variable named INTEREST_RATE and assign 1.05 to it.
  4. Create a int variable named yearCount.
  5. Prompt for the "Number of years to invest" and store the input into the yearCount variable.
  6. Prompt for the "Amount to Invest" and store this in the currentBalance variable.
  7. Assign currentBalance to newBalance.
  8. Using a 'FOR' loop, create and display the balance for each year. Additional variables may be required ( such as for the current year being displayed)
    1. newBalance= newBalance * INTEREST_RATE;
    2. Review the FOR loop example in Chapter 6 -Section 6.3 page 92
    3. Format the displayed balance to show 2 decimal places only.

Example:

Number of years to invest:5
Amount to Invest:1000

Year 1 balance =  1050.00
Year 2 balance =  1102.50
Year 3 balance =  1157.63
Year 4 balance =  1215.51
Year 5 balance =  1276.28


   Display the message "You have doubled your investment" and terminate the loop if/when you have more than doubled your initial investment.

In: Computer Science

please describe below technology used, benefit, issue and conclusion in your words Technology Used Encryption was...

please describe below technology used, benefit, issue and conclusion in your words

Technology Used

Encryption was almost exclusively used only by governments and large enterprises until the late 1970s when the Diffie-Hellman key exchange and RSA algorithms were first published -- and the first personal computers were introduced. By the mid-1990s, both public key and private key encryption were being routinely deployed in web browsers and servers to protect sensitive data.

Devices like modems, set-top boxes, smartcards and SIM cards all use encryption or rely on protocols like SSH, S/MIME, and SSL/TLS to encrypt sensitive data. Encryption is used to protect data in transit sent from all sorts of devices across all sorts of networks, not just the internet; every time someone uses an ATM or buys something online with a smartphone, makes a mobile phone call or presses a key fob to unlock a car, encryption is used to protect the information being relayed. Digital rights management systems which prevent unauthorized use or reproduction of copyrighted material, are yet another example of encryption protecting data. Cryptographic hash functions.

Encryption is usually a two-way function, meaning the same algorithm can be used to encrypt plaintext and decrypt ciphertext. A cryptographic hash function can be viewed as a type of one-way function for encryption, meaning the function output cannot easily be reversed to recover the original input. Hash functions are commonly used in many aspects of security to generate digital signatures and data integrity checks. They take an electronic file, message or block of data and generate a short digital fingerprint of the content called a message digest or hash value. The key properties of a secure cryptographic hash function are:Output length is small compared to input o Computation is fast and efficient for any input or Any change to input affects lots of output bits o One-way value -> the input cannot be determined from the output of Strong collision resistance -> two different inputs can't create the same output

The ciphers in hash functions are optimized for hashing: They use large keys and blocks, can efficiently change keys every block and have been designed and vetted for resistance to related-key attacks. General-purpose ciphers used for encryption tend to have different design goals. For example, the symmetric-key block cipher AES could also be used for generating hash values, but its key and block sizes make it nontrivial and inefficient.

Encryption helps protect business data. The technology comes in many forms, with key size and strength generally being the biggest differences in one variety from the next.

1. Triple DES:

Triple DES was designed to replace the original Data Encryption Standard (DES) algorithm, which hackers eventually learned to defeat with relative ease. At one time, Triple DES was the recommended standard and the most widely used symmetric algorithm in the industry.

Triple DES uses three individual keys with 56 bits each. The total key length adds up to 168 bits, but experts would argue that 112bits in key strength is more like it.

Despite slowly being phased out, Triple DES still manages to make a dependable hardware encryption solution for financial services and other industries.

2. RSA:

RSA is a public-key encryption algorithm. It also happens to be one of the methods used in our PGP and GPG programs.

Unlike Triple DES, RSA is considered an asymmetric algorithm due to its use of a pair of keys. You’ve got your public key, which is what we use to encrypt our message, and a private key to decrypt it. The result of RSA encryption is a huge that takes attackers quite a bit of time and processing power to break.

3. Blowfish:

Blowfish is another algorithm designed to replace DES. This symmetric cipher splits messages into blocks of 64 bits and encrypts them individually. Blowfish is known for both its speed and effectiveness as many claim that it has never been defeated. Vendors have taken full advantage of its free availability in the public domain. Blowfish can be found in software categories ranging from e-commerce platforms for securing payments to password management tools, where it used to protect passwords. It’s definitely one of the more flexible encryption methods available.

4. Twofish:

Keys used in this algorithm may be up to 256 bits in length and as a symmetric technique, only one key is needed. Twofish is regarded as one of the fastest of its kind, and ideal for use in both hardware and software environments. Like Blowfish, Twofish is freely available to anyone who wants to use it. Encryption programs such as PhotoEncrypt, GPG, and the popular open source software TrueCrypt are there.

5. AES:

The Advanced Encryption Standard is the algorithm trusted as the standard by the U.S. Government and numerous organizations. Although it is extremely efficient in 128-bit form, AES also uses keys of 192 and 256 bits for heavy duty encryption purposes. AES is largely considered impervious to all attacks, with the exception of brute force, which attempts to decipher messages using all possible combinations in the 128, 192, or 256bit cipher. Still, security experts believe that AES will eventually be hailed the de facto standard for encrypting data in the private sector.

                                                       

                                                    


                                                   Benefits of Encryption

The primary purpose of encryption is to protect the confidentiality of digital data stored on computer systems or transmitted via the internet or any other computer network. A number of organizations either recommend or require sensitive data to be encrypted in order to prevent unauthorized third parties or threat actors from accessing the data. For example, the Payment Card Industry Data Security Standard requires merchants to encrypt customers' payment card data when it is both stored at rest and transmitted across public networks.

Modern encryption algorithms also play a vital role in the security assurance of IT systems and communications as they can provide not only confidentiality, but also the following key elements of security:

  • Authentication: the origin of a message can be verified.

  • Integrity: proof that the contents of a message have not been changed since it was sent.

  • Non repudiation: the sender of a message cannot deny sending the message.

                                             

                                                                Encryption Issues

Although it seems like common sense to use data encryption in business and other entities for security, many organizations are opposed to encrypting data because of some of the obstacles involved with doing so.

Like everything else, data encryption has its pros and cons and businesses must look at all of the considerations to make an informed decision about encryption.

Data Encryption :

  • Encryption Keys: Without a doubt, data encryption is a monumental task for an IT specialist. The more data encryption keys there are the more difficult IT administrative tasks for maintaining all of the keys can be. If you lose the key to the encryption, you have lost the data associated with it.

  • Expense: Data encryption can prove to be quite costly because the systems that maintain data encryption must have capacity and upgrades to perform such tasks. Without capable systems, the reduction of systems operations can be significantly compromised.

  • Unrealistic Requirements: If an organization does not understand some of the restraints imposed by data encryption technology, it is easy to set unrealistic standards and requirement which could jeopardize data encryption security.

  • Compatibility: Data encryption technology can be tricky when you are layering it with existing programs and applications. This can negatively impact routine operations within the system.

For any cipher, the most basic method of attack is brute force; trying each key until the right one is found. The length of the key determines the number of possible keys, hence the feasibility of this type of attack. Encryption strength is directly tied to key size, but as the key size increases so, too, do the resources required to perform the computation.

Alternative methods of breaking a cipher include side-channel attacks, which don't attack the actual cipher but the physical side effects of its implementation. An error in system design or execution can allow such attacks to succeed.

Attackers may also attempt to break a targeted cipher through cryptanalysis, the process of attempting to find a weakness in the cipher that can be exploited with a complexity less than a brute-force attack. The challenge of successfully attacking a cipher is easier if the cipher has any flaw. For example, there have been suspicions that interference from the National Security Agency (NSA) weakened the Data Encryption Standard algorithm, and following revelations from former NSA analyst and contractor Edward Snowden, many believe the NSA has attempted to subvert other cryptography standards and weaken encryption products.

                                                           Conclusion

Thus, network security is one of the most important factors to consider while working over the internet, Local Area Network or other method. It doesn't matter how small or big businesses. It is said that there is no network that is immune to all attacks, a stable, fast and efficient network security system is essential to protecting data. A good network security system helps reduce the risk of data theft and sabotage. This analysis shows that AES is the better algorithm and AES does not have any well known weak points so far.

In: Computer Science

Dealing Cards Write a program that deals a deck of card into 4 hands – Each...

Dealing Cards

Write a program that deals a deck of card into 4 hands – Each hand having 13 cards.

  • Your program should do the followings
    • use an array to randomly select 52 cards and deal it into 4 hands.
    • Print each hand unsorted
    • Identify the face value of each hand and display it.
    • You should create a class called Card, and all the methods should be defined within the card class.

Hints – Import below java utility to use the random function.

import java.util.*;

Random rand = new Random();

int r = rand.nextInt(52); // this will generate random numbers between 0-52

to get a value between 1-13, use the mod function and get the remainder

if your number is 15, 15%13 has a remainder of 2. 2 is your face card.

---------------------------------------------------------------------------

11 = jack

12= Queen

13= King

Card is a CLUB - If your generated number is between (1-13)

Card is a Diamond - If your generated number is between (14-26)

Card is a Spade - If your generated number is between (27-39)

Card is a Heart - If your generated number is between (40-52)

Your program output should look like this below

----------------------------------------------------------------------------------------------------------------------------------

Deck of cards shuffled into 4 hands

8 1 7 18 43 26 31 2 12 3 40 22 4

29 9 10 11 5 35 47 36 25 14 17 39 23

21 52 6 46 38 48 24 16 27 32 13 45 42

49 44 50 20 37 34 51 15 28 30 19 33 41

Face of cards in each Hand

Hand 1:

       Clubs: 8 1 7 2 Q 3 4

       Diamonds: 5 K 9

       Spades: 5

       Heart: 4 1

Hand 2:

       Clubs: 4 9 10 J 5

       Diamonds: Q 1 4

       Spades: 3 9 10 K

       Heart: 8

Hand 3:

       Clubs: 6 K

       Diamonds: 10 8 J 3

       Spades: K Q 1 6

       Heart: K 7 9

Hand 4:

       Clubs: K

       Diamonds: 7 2

       Spades: J 8 2 4

Heart: 6 3 10 5 J Q

In: Computer Science

how to implement h / k sqrt(n) in c h being a constant k being the...

how to implement h / k sqrt(n) in c
h being a constant
k being the students k(k < 10^9)
n is the two mid points in a ternary search

in c programing

In: Computer Science

Consider the below database schema for company ABC: Employee(empNo, givename, famname, gender, DOB) Supervises(super_empNo*, empNo*, description)...

Consider the below database schema for company ABC:

Employee(empNo, givename, famname, gender, DOB)

Supervises(super_empNo*, empNo*, description)

Department(deptNo, name, manager_empNo*)

Dependent(empNo*, name, relationship)

Project(projNo, description, deptNo*)

The relations Employee, Supervises, Department, Dependent and Project keep data for employees, supervision, departments, dependents of employees and projects of ABC.

For the database, primary keys, and parent and child relations for foreign keys are annotated. The meaning of most attributes is self-explanatory. Answer questions below.

Your answer to each question must be according to the given database schema and instance.

1.1. (2 points) Does the primary key of Supervises (super_empNo, empNo) ensure that each supervisor supervises a different employee? Explain your answer.

1.2. (5 points) Is it possible that a project has no department? Explain why/why not. If possible, identify any data integrity constraints that can be placed on the Project table to prevent this? Can a project have many departments? Explain using the data integrity constraints on the Project table.

1.3. (2 points) Is it possible that a supervisor does not supervise any employees? Explain your answer using the data constraints on the Supervises table.

1.4 (3 point) Assuming that every department is working on at least one project (and the Department table contains a record with department number 8), can the SQL statement below be successfully executed? Explain your answer. DELETE FROM Department WHERE deptNo = 8;

In: Computer Science

You are to draw the AVL trees that result after inserting each of the following keys...

You are to draw the AVL trees that result after inserting each of the following keys in the order given: TCG, TAC, AAC, TGg, TTC, ACC, GGC. You will draw a total of 7 trees, one after each insertion

In: Computer Science

Create the following tables. The underlined bold column names are the primary keys. Make sure to...

Create the following tables. The underlined bold column names are the primary keys. Make sure to specify the primary and foreign key constraints in your create table statements.

  1. customer: (cus_code:integer, cus_lname:varchar(20), cus_fname:varchar(20), cus_initial:char, cus_areacode:integer,cus_phone:integer).

  1. invoice: (inv_number:integer, cus_code:integer, inv_date:date,

                  foreign key cus_code references customer(cus_code))

  1. vendor:(vend_code:integer,vend_name:varchar(30),vend_contact:varchar(30),vend_areacode:integer,vend_phone:integer)
  1. product:(prod_code:integer, prod_desc:varchar(50), prod_price:integer, prod_quant:integer,vend_code:integer,

foreign key (vend_code) referenecs Vendor(vend_code))

  1. line: (inv_number:integer, prod_code:integer ,line_units:integer,

foreign key (inv_number) references Invoice(inv_number),

foreign key (prod_code) references Product (prod_code) )

In: Computer Science

Given the following data, illustrate Selection Sort. index 1 2 3 4 5 6 data 11...

  1. Given the following data, illustrate Selection Sort.

index

1

2

3

4

5

6

data

11

10

21

3

7

5

In: Computer Science

I need Java Code for both questions....thx Question 1 Consider the sequence of integers defined as...

I need Java Code for both questions....thx

Question 1

Consider the sequence of integers defined as follows:

  • The first term is any positive integer.

  • For each term n in the sequence, the next term is computed like this: If n is even, the next term is n/2. If n is odd, the next term is 3n+1.

  • Stop once the sequence reaches 1.
    Here are a few examples of this sequence for different values of the first term:

    • 8,4,2,1
    • 12,6,3,10,5,16,8,4,2,1
    • 19,58,29,88,44,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1

    Note that all three of these eventually do reach 1. In fact, it is believed (but not known) that the sequence will always reach 1, regardless of the first term chosen. This is known as the Collatz conjecture. Despite its apparent simplicity, it has so far eluded all attempts at a proof. Mathematician Jeffrey Lagarias at the University of Michigan has claimed that “this is an extraordinarily difficult problem, completely out of reach of present day mathematics.”

    We might not be able to prove the Collatz conjecture here, but we can experiment computationally with it! Within your Lab4HW folder, write a program named Collatz.java that allows the user to enter any positive integer. The program should then compute and list all the terms of the sequence until it reaches 1. At the end, show how many terms it took to get to 1 (including 1 itself).

1

Here are some examples of what your completed program might look like when you run it. Underlined parts indicate what you type in as the program is running.

Example 1

Enter starting value (must be a positive integer): 5
5
16
8
4
2
1
Number of terms: 6

Example 2

Enter starting value (must be a positive integer): 12
12
6
3
10
5
16
8
4
2
1
Number of terms: 10

Example 3

Enter starting value (must be a positive integer): 1
1
Number of terms: 1

Question 2

Credit card numbers are not completely random sequences; they follow certain rules depending on the card issuer. A MasterCard number must meet these criteria:

• Begin with 51, 52, 53, 54, 55, or something in the range 222100-272099
• 16 digits in length
• Satisfy the Luhn formula, created by IBM scientist Hans Peter Luhn in the 1950s

Here’s how the Luhn formula works:

  • Double every other digit going backwards, starting from the next-to-last digit.

  • For each of the doubled values that exceed 9, subtract 9.

  • Add up all the doubled values, along with the digits that were not doubled.

  • If the result is a multiple of 10, the number satisfies the Luhn formula. If the result is not a multiple of 10, the number does not satisfy the Luhn formula.

    For example, 2221008763790559 is a valid MasterCard number. (Don’t worry, this was randomly gener- ated and most likely doesn’t actually belong to anyone :) You can easily verify that the number begins with 222100 and is 16 digits long. To check whether it satisfies the Luhn formula:

    Original number:

    2221008763790559

    Double every other digit going left, starting from the next-to-last digit:

      4  2  4  1  0  0 16  7 12  3 14  9  0  5 10  9
    

    For every doubled value that exceeds 9, subtract 9:

    4241007733590519

    Finally,addupallthemodifieddigits: 4+2+4+1+0+0+7+7+3+3+5+9+0+5+1+9=60, which is indeed a multiple of 10.

    Within your Lab4HW folder, write a program named MasterCardValidator.java that allows the user to enter a credit card number. The program should then determine and print whether that number is a valid MasterCard number according to the criteria above. You can use the randomly generated MasterCard numbers from https://www.freeformatter.com/credit-card-number-generator-validator.html to help you test.

  • Hint: There are several ways you can read the number from the user, but I recommend reading it as a string. You can then use strName.charAt(i) to get the individual digits. However, these are treated as char values rather than int values. To convert to int, you can use one of the following:

    • For a single digit: Integer.parseInt("" + strName.charAt(i)), or strName.charAt(i) - ’0’

    • For multiple digits: Integer.parseInt(strName.substring(startIndex, endIndex))
    Here are some examples of what your completed program might look like when you run it. Underlined

    parts indicate what you type in as the program is running.

    Example 1

    Enter a card number for validation: 2221008763790559
    Valid
    

    Example 2

    Enter a card number for validation: 2221018763790559
    Invalid
    

    Example 3

    Enter a card number for validation: 55
    Invalid
    

In: Computer Science

Insert the following data in the tables using insert into statements: 1. customer: 10010, Johnson, Alfred,...

Insert the following data in the tables using

insert into

statements:

1.

customer:

10010, Johnson, Alfred, A, 615, 8442573

10011, Dunne, Leona, K, 713, 8941238

10012, Smith, Walter, W, 615, 8942285

10013, Roberts, Paul, F, 615, 2221672

10014, Orlando, Myla, NULL, 615, 2971228

2.

invoice:

1001, 10011, 2008-08-03

1002, 10014, 2008-08-04

1003, 10012, 2008-03-20

1004, 10014, 2008-09-23

3.

vendor:

232, Bryson, Smith, 615, 2233234

235, Walls, Anderson, 615, 2158995

236, Jason, Schmidt, 651, 2468850

4.

product:

12321, hammer, 189 ,20, 232

65781, chain, 12, 45, 235

34256, tape, 35, 60, 236

12333, hanger, 200 ,10, 232

5.

line:

1001, 12321, 1

1001, 65781, 3

1002, 34256, 6

1003, 12321, 5

1002, 12321, 6

In: Computer Science