I am implementing a generic List class and not getting the expected output.
My current output is: [0, 1, null]
Expected Output in a separate test class:
List list = new SparseList<>(); list.add("0"); list.add("1"); list.add(4, "4");
will result in the following list of size 5: [0, 1, null, null, 4].
list.add(3, "Three");
will result in the following list of size 6: [0, 1, null, Three, null, 4].
list.set(3, "Three");
is going to produce a list of size 5 (unchanged): [0, 1, null, Three, 4].
When removing an element from the list above, via list.remove(1); the result should be the following list of size 4: [0, null, Three, 4]
import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.ListIterator; public class SparseList<E> implements List<E>{ private int endIndex = 0; private HashMap<Integer,E> list; public SparseList() { list = new HashMap<>(); } public SparseList(E[] arr) { list = new HashMap<>(); for(int i = 0; i <arr.length; i++) { list.put(i, arr[i]); } endIndex = arr.length - 1; } @Override public boolean add(E e) { list.put(endIndex, e); endIndex++; return true; } @Override public void add(int index, E element) { list.put(index, element); } @Override public E remove(int index) { return list.remove(index); } @Override public E get(int index) { return list.get(index); } @Override public E set(int index, E element) { E previous = list.get(index); list.put(index, element); return previous; } @Override public int size() { return endIndex + 1; } @Override public void clear() { list.clear(); } @Override public boolean isEmpty() { return list.isEmpty(); } @Override public String toString() { String s = ""; for(int i = 0; i < list.size(); i++) { if(list.get(i) == null) { s += "null, "; }else { s += list.get(i).toString() + ", "; } } return "[" + s + "]"; } @Override public boolean contains(Object o) { throw new UnsupportedOperationException(); } @Override public Iterator<E> iterator() { throw new UnsupportedOperationException(); } @Override public Object[] toArray() { throw new UnsupportedOperationException(); } @Override public <T> T[] toArray(T[] a) { throw new UnsupportedOperationException(); } @Override public boolean containsAll(Collection<?> c) { throw new UnsupportedOperationException(); } @Override public boolean addAll(Collection<? extends E> c) { throw new UnsupportedOperationException(); } @Override public boolean addAll(int index, Collection<? extends E> c) { throw new UnsupportedOperationException(); } @Override public boolean removeAll(Collection<?> c) { throw new UnsupportedOperationException(); } @Override public boolean retainAll(Collection<?> c) { throw new UnsupportedOperationException(); } @Override public boolean remove(Object o) { throw new UnsupportedOperationException(); } @Override public int indexOf(Object o) { throw new UnsupportedOperationException(); } @Override public int lastIndexOf(Object o) { throw new UnsupportedOperationException(); } @Override public ListIterator<E> listIterator() { throw new UnsupportedOperationException(); } @Override public ListIterator<E> listIterator(int index) { throw new UnsupportedOperationException(); } @Override public List<E> subList(int fromIndex, int toIndex) { throw new UnsupportedOperationException(); } }
In: Computer Science
1. FTP requires confirmation that a file was successfully transmitted to a client, but it has no built-in mechanism to track this information for itself. What protocol does FTP rely on at the Transport layer of the TCP/IP model to ensure delivery is complete?
Group of answer choices
UDP
HTTP
SSH
TCP
2. Which of the following tools can be used to determine if a network cable is good? Choose all that apply.
Group of answer choices multiple choice
Cable tester
Crimper
Loopback plug
Network multimeter
3. A hub transmits all incoming messages to all of its ports except the port where the messages came in. A switch usually sends messages only to the destination computer. What information does a switch collect from messages crossing its interfaces so it knows where to send data in future transmissions?
Group of answer choices
IP address
MAC address
Port number
FQDN
4. Which two of the following hosts on a corporate intranet are on the same subnet?
Group of answer choices/
multiple choice
192.168.2.143 // 255.255.255.0
172.54.98.3 // 255.255.0.0
192.168.5.57 // 255.255.255.0
172.54.72.89 // 255.255.0.0
5. Your SOHO router has failed and you have installed a new router. The old router’s static IP address on the network is 192.168.0.1. The new router has a static IP address of 10.0.0.1. You go to a computer to configure the new router and enter 10.0.0.1 in the browser address box. The router does not respond. You open a command prompt window and try to ping the router, which does not work. Next, you verify that the router has connectivity and you see that its local connection light is blinking, indicating connectivity. What is the most likely problem and its best solution?
Group of answer choices
The computer you are using to configure the router has a corrupted TCP/IP configuration. Restart the computer.
The router is defective. Return it for a full refund.
The computer and the router are not in the same subnet. Release and renew the IP address of the computer.
The computer and the router are not in the same subnet. Change the subnet mask assigned to the computer.
Question 6
The Telnet protocol encrypts transmitted data, which therefore cannot be read by others on the network.
Group of answer choices
True
False
Question 7
You are configuring email on a customer’s computer. Which port should you configure for pop.companymail.com? For smtp.companymail.com?
Group of answer choices
143, 25
110, 143
110, 25
25, 110
Question 8
Your boss asks you to transmit a small file that includes sensitive personnel data to a server on the network. The server is running a Telnet server and an FTPS server. Why is it not a good idea to use Telnet to reach the remote computer?
Group of answer choices
Telnet transmissions are not encrypted.
Telnet is not reliable and the file might arrive corrupted.
FTP is faster than Telnet.
FTP running on the same computer as Telnet causes Telnet not to work.
Question 9
What two standards have been established for wiring twisted-pair cabling and RJ-45 connectors?
Group of answer choices
Multiple choice
T568A
T568B
TIA/EIA 586
T568C
Question 10
If you are experiencing issues reaching a target destination network, and you need to to display each hop to the destination, what command should you use?
Group of answer choices
ipconfig
ifconfig
tracert
nslookup
Question 11
A punchdown tool is used to wire twisted-pair cabling to a keystone jack.
Group of answer choices
True
False
Question 12
What type of network device keeps a table of the MAC addresses of the devices connected to it?
Group of answer choices
hub
router
NIC
switch
Question 13
What TCP port is utilized by an SSH server listening for connections?
Group of answer choices
20
21
22
23
Question 14
What two protocols are used to deliver mail messages?
Group of answer choices
multiple choice
POP3
SNMP
SMTP
IMAP4
Question 15
Your customer recently installed a new router in her dance studio, as shown in the diagram in Figure 8-56. She then ran Ethernet cables through the drop ceiling to computers in various offices. Without any further testing, which computers do you suspect are experiencing connection problems? Choose all that apply.
Group of answer choices
Computer A
Computer B
Computer C
None of the above
Question 16
Phone cords are a type of twisted-pair cable and use an RJ-45 connector.
Group of answer choices
True
False
Question 17
Which of the following is true about cable Internet?
Group of answer choices
you share the cable infrastructure with your neighbors
you need filters on every phone jack
fiber optic cabling is required
provides up to 2.3 Mbps of bandwidth
Question 18
What two terms describe the type of network cable that is used for connecting a computer to a switch or other network device?
Group of answer choices
MULTIPLE CHOICE
crossover cable
power over Ethernet cable
straight-through cable
patch cable
Question 19
What version of Ethernet utilizes a fiber-optic cable and has a transmission speed of 100 Mbps?
Group of answer choices
100BaseTX
100BaseFX
1000BaseFX
100BaseCX
Question 20
You’re setting up a secure email server on your local network that you want clients to be able to access from the Internet using IMAP4 and SMTP. Which ports should you open in your firewall?
Group of answer choices
25 and 143
587 and 993
80 and 443
25 and 110
In: Computer Science
In 1-3 sentences, describe how you would "Find a path from lab to Del Taco using only sidewalks on an island", Recursively using C++
In: Computer Science
use quick sort to sort the following array. show each pass and what the pivot is during the pass. please explain why you are swapping positions. do not use a compiler.
30 5 40 11 20 9 15 2 60 25 80 3 73 35 4 75 20 6
In: Computer Science
Consider the design of a processor, with a max instruction length of 600 ps. The propagation delay to load a register is 25 ps
What is the minimum clock cycle time, the instruction latency and CPU throughput using serial execution?
What is the minimum clock cycle time, the instruction latency and CPU throughput using a pipelined execution with 8 equal stages?
Consider a design which used n equal stages. What is the minimum clock cycle time, the instruction latency and CPU throughput expressed as a function of n? (You may wish to check that your generalization agrees with your results from parts (a) and (b), i.e., by substituting n = 1, 8.)
In: Computer Science
P(CA) = probability of experiencing a cybersecurity attack
P(V) = probability of finding a vulnerability on your webservers
P(A) = probability of an attack on your webservers
P(CA|A) |
13% |
P(CA|~A) |
6% |
P(V) |
10% |
P(A|V) |
18% |
P(A|~V) |
7% |
Estimates for Company A
Each question is 5 points. You need to do the following questions in order.
2.a. What is the probability of an attack on the webservers in Company A?
P(A) = ?
2.b. What is the probability of Company A experiencing cybersecurity attack?
P(CA) = ?
2.c. What is the probability of an attack on the webservers, given the company experience a cybersecurity attack?
P(A|CA) = ?
In: Computer Science
Write an application that allows a user to enter the names and birthdates of up to 10 friends. Continue to prompt the user for names and birthdates until the user enters the sentinel value ZZZ for a name or has entered 10 names, whichever comes first. When the user is finished entering names, produce a count of how many names were entered, and then display the names. In a loop, continuously ask the user to type one of the names and display the corresponding birthdate or an error message if the name has not been previously entered. The loop continues until the user enters ZZZ for a name. Save the application as BirthdayReminder.java.
My issue in this is the loop portion. I am not sure if I have done it properly. I also need help trying to comment this code so I can explain it better. Could someone help analyze my code so that I can properly do this JAVA assignment? Please include comments as well inside the code.
Here is what I have so far:
import java.util.*;
public class BirthdayReminder{
public static void main(String[] args)
{
final int NUM_NAMES = 10;
String sentinal = "ZZZ";
int count = 0;
String name = null;
String birthdate = null;
String[] names = new String[NUM_NAMES];
String[] birthdates = new String[NUM_NAMES];
Scanner input = new Scanner(System.in);
System.out.println("Enter a name or " + sentinal + " to quit > ");
name = input.nextLine();
while(name.compareTo(sentinal)!=0 && count < NUM_NAMES)
{
System.out.println("Enter birthdate (mm/dd) > ");
birthdate = input.nextLine();
names[count] = name.trim();
birthdates[count] = birthdate.trim();
System.out.println("Enter a name or " + sentinal + " to quit > ");
name = input.nextLine();
++ count;
}
System.out.println("\nCount of names is " + count);
System.out.println("\nNames are:" + count);
for(int x = 0; x < count; ++x)
System.out.println(names[x]) ;
boolean repeat = true;
boolean found;
while(repeat)
{
found=false;
System.out.println("\nEnter a name or " + sentinal + " to quit > ");
name = input.nextLine().trim();
if(name.compareTo(sentinal)==0)
repeat = false;
else
{
for(int x = 0; x < count; ++x)
{
if(names[x].compareTo(name)==0)
{
found =true;
birthdate = birthdates[x];
break;
}
}
if(found)
System.out.println("Birthdate of " + name + " is " + birthdate);
else
System.out.println("Birthdate of " + name + " is not found");
}
}
}
}
In: Computer Science
List 4 desired scheduled algorithm characteristics
In: Computer Science
write an essay about J2EE Security? 200 words
what is sql injection in 200 words?
In: Computer Science
In Java please
Cipher.java:
/* * Fix me */ import java.util.Scanner; import java.io.PrintWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; public class Cipher { public static final int NUM_LETTERS = 26; public static final int ENCODE = 1; public static final int DECODE = 2; public static void main(String[] args) /* FIX ME */ throws Exception { // letters String alphabet = "abcdefghijklmnopqrstuvwxyz"; // Check args length, if error, print usage message and exit if (args.length != 3) { System.out.println("Usage:\n"); System.out.println("java Cipher <filename> <cipher-key> <digit>\n"); System.out.println("Options:\n"); System.out.println("filename\tThe filename of the text file to open"); System.out.println("cipher-key\tThe cipher key for encryption/decryption"); System.out.println("digit\t\t1 to encode or 2 to decode"); System.exit(1); } // Extract input args to variables String inputFilename = args[0]; String key = args[1]; int action = Integer.parseInt(args[2]); if(action != 1 && action != 2) { System.out.println("Option " + action + " is not valid"); System.exit(1); } String outputFilename = getOutputFilename(inputFilename, action); Scanner input = openInput(inputFilename); PrintWriter output = openOutput(outputFilename); // Read in data and output to file // Convert all letters to lowercase for output StringBuilder message = new StringBuilder(input.useDelimiter("\\Z").next()); for(int i = 0; i < message.length(); ++i) { int offset = key.charAt(i % key.length()) - 'a'; if(action == 1) { message.setCharAt(i, shiftUpByK(message.charAt(i), offset)); } else { message.setCharAt(i, shiftDownByK(message.charAt(i), offset)); } } output.println(message.toString().toLowerCase()); // Close streams input.close(); output.close(); } /** * Open input for reading * * @param filename * @return Scanner * @throws FileNotFoundException */ public static Scanner openInput(String filename) throws FileNotFoundException { return new Scanner(new File(filename)); } /** * Open output for writing * * @param filename * @return PrintWriter * @throws FileNotFoundException */ static PrintWriter openOutput(String filename) throws FileNotFoundException { return new PrintWriter(new File(filename)); } /** * Encode letter by some offset d * * @param c input character * @param offset amount to shift character value * @return char encoded character */ public static char shiftUpByK(char c, int offset) { if ('a' <= c && c <= 'z') return (char) ('a' + (c - 'a' + offset) % NUM_LETTERS); if ('A' <= c && c <= 'Z') return (char) ('A' + (c - 'A' + offset) % NUM_LETTERS); return c; // don't encrypt if not an ic character } /** * Decode letter by some offset d * * @param c input character * @param offset amount to shift character value * @return char decoded character */ public static char shiftDownByK(char c, int offset) { if ('a' <= c && c <= 'z') return (char) ('a' + (((c - 'a' - offset) % NUM_LETTERS) + NUM_LETTERS ) % NUM_LETTERS); if ('A' <= c && c <= 'Z') return (char) ('A' + (((c - 'A' - offset) % NUM_LETTERS) + NUM_LETTERS ) % NUM_LETTERS); return c; // don't decrypt if not an ic character } /** * Changes file extension to ".coded" or ".decoded" * * @param filename * @return String new filename or null if action is illegal */ public static String getOutputFilename(String filename, int action) { int indexOfExtension = filename.indexOf("."); String fileNameWithoutExtension; if(indexOfExtension != -1) { fileNameWithoutExtension = filename.substring(0, indexOfExtension); } else { fileNameWithoutExtension = filename; } if(action == 1) { return fileNameWithoutExtension + ".coded"; } else { return fileNameWithoutExtension + ".decoded"; } } public String getInfo() { return "Program 3, Student's name here"; } }
20.23 Program 5b: CipherEx catch exception
Instructor note:
The key is expected to be converted to lowercase before encoding/decoding.
Objectives
Program Description
This program is identical to Cipher.java with these exceptions (no pun intended):
Output
Test case 5 will display an error message:
Error opening file badFilename
Test case 6 will display an error message:
Usage: Cipher inputFileName cipherKey (1)encode (2)decode
The other test cases will be the same as the Cipher class.
In: Computer Science
Consider a company that has an intrusion detection system in half of its systems (50%), has bring your own device (BYOD) for 30% of its employees, and uses three systems (computers 40%, smartphones 25%, and cloud 35%).
The probability of a breach is 11%.
The probability of a breach given there is an intrusion detection is 15%
The probability of a breach given there is no intrusion detection 25%
The probability of a breach given employees’ use their own devices 43%
The probability of a breach given employees use company devices 13%
The probability of a breach given computer systems is 7%
The probability of a breach given smartphone systems is 27%
The probability of a breach given cloud system is 17%
3.a. What is the probability of a breach of company computer systems that have no intrusion detection?
3.b. What are the conditions that result in the highest risk of an attack?
In: Computer Science
Write a program that prompts the user for an even number from 2 to 100 until the number 90 is encountered. Not including the 90, calculate the minimum value.
In case you know what this means: DO NOT USE LISTS! We will look into the use of lists later.
This has to be done in the python program.
Here's what I have so far:
inp = 0
min = 0
while inp != 90:
inp = int(input("Please enter an even number from 2 to 100 (90 to stop): "))
print(inp)
if ((inp>= 2 and inp <= 100) and inp != 90):
min = inp
else:
print("No minimum value")
print("the minimum value is", min)
In: Computer Science
1.encode the following message 'I love New York in June how about you' first apply the vigenere cipher with the key 'june' then apply the permutation (3,2,4,0,1). You can do this with the functions below in 1 line of code.
2.Consider the plain text 'Mom please don't tell dad I crashed the car I'll get it fixed before he even knows'. Using the Vigenere cipher I get the following cipher text: ''PFUKPJAKXGFVJXYEDEGRLDGWAKAHUBCIHAJBZZTGKJTAMIZFZHGEXHUVPZIAEFDQFEN'. What key did I use?
3.How can frequency analysis of words and characters help an attacker crack substitution ciphers?
4.Similar to the previous problem, make a python dictionary that counts the number of times each letter occures in the the book below (meditations by marcus Arelious)
In: Computer Science
](Currency Exchange) You are given the exchange rate from Canadian to US dollars. You are asked to convert an amount either from Canadian to US or vice versa based on the user's request. Write a C++ program that prompts the user to enter: a. the exchange rate from currency in Canadian dollars to US dollars b. either 0 to convert from Canadian to US or 1 to convert from US to Canadian (the program displays a message for invalid input) c. either the amount in Canadian or US dollars according to the request The program then calculates and displays the amount in either Canadian or US dollars according to the request. Here are sample runs: Rate from CAD to USD: 0.747 0 for CAD to USD or 1 vice versa: 0 CAD amount: 100 100 CAD is 74.7 US Rate from CAD to USD: 0.75 0 for CAD to USD or 1 vice versa: 1 US amount: 100 100 US is 133.33 CAD Rate from CAD to USD: 0.754 0 for CAD to USD or 1 vice versa: 5 Invalid input
In: Computer Science
Download the AllEqual.java file, and open it in jGrasp (or a text editor of your choice). This program takes a number of command line arguments, converts them to integers, and then determines if they all have the same value. An example run of the program is below, using the command-line arguments 1 2 3:
Are equal: false
A further example is shown below, with the command-line arguments 2 2:
Are equal: true
In the event that the program is given no arguments or only one argument, it should consider all the elements equal to each other.
public class AllEqual { // You must define the allEqual method, which will return // true if either: // 1.) The given array contains fewer than two elements, or... // 2.) All elements of the array are equal to each other. // As a hint, you only need to compare the first element // to all subsequent elements for this check. // // TODO - define your code below this comment // // DO NOT MODIFY parseStrings! public static int[] parseStrings(String[] strings) { int[] retval = new int[strings.length]; for (int x = 0; x < strings.length; x++) { retval[x] = Integer.parseInt(strings[x]); } return retval; } // DO NOT MODIFY main! public static void main(String[] args) { int[] argsAsInts = parseStrings(args); boolean areEqual = allEqual(argsAsInts); System.out.println("Are equal: " + areEqual); } }
In: Computer Science