This homework will check your ability to declare and use classes and object, and how to use both Maps and sets in Java. The assignment will also serve as an introduction to Junit Testing.
Here is the general layout. Some more detailed instructions are also included below. Pay attention to the details and the naming conventions, since we will be running your code through testing code the grading team will develop. That code will require your method signatures to be consistent with these instructions.
Please call your project LegislatorFinder
inside your project, please have a package called LegislatorFinder
create your java files inside the LegislatorFinder package.
We will be simulating the system by which people can find who their legislators are:
There is a class called Legislator, with the following attributes: ▪ lastName ▪ firstName ▪ politicalParty ▪ Each of those attributes has getter and setter functions therefore, this class has the following methods: getLastName(), getFirstName, getPoliticalParty(), setFirstName(string), setLatName(string), setPoliticalParty(string) ▪ in addition, the class has two constructors: one with no arguments. One that takes arguments string, string, string
There is a class called LegislatorFinder ▪ this class has only one attribute, a TreeMap ▪ for methods, you should implement addLegislator(string state, Legislator l) ◦ if the state already exists in the TreeMap, it adds this legislator to the set the state maps to. ◦ If the state doe not exist in the TreeMap, it adds a new key:value pair to the map, with this legislator in the corresponding set. getLegislators(string state) ◦ returns the set of legislators from the given state. If there is no such state key in the map, returns an empty set. substituteLegislators(String state, Set newLegislators) ◦ substitutes the legislators for the indicated state with the one in newLegislators. If there was no such state key in the Map, it creates a new key:value pair. If there was a key:value pair for this state already, it substitutes the previous set of legislators with the one passed as an input parameter.
◦ Through JUnit tests, test the following operations: ▪ adding legislators, both for a state key that is already in the map, and for a state key not yet in the map. ▪ Retrieving legislators, both for a state key that is already in the map, and for a state key not yet in the map. ▪ Substituting the set of legislators for a given state for the following cases: the state was not previously being used as a key in the map. The key was being used as a key in the map.
(Need to implement a TreeMap method)
In: Computer Science
How have the events of 9/11/2001 influenced Disaster Recovery Planning (DRP)?
In: Computer Science
Design and write a Python 3.8 program that gives and grades a math quiz. The quiz will give 2 problems for each of the arithmetic operations: +, -, *, /, and %. First, two addition problems will be presented (one at a time) with random numbers between 1 and 20. Then two subtraction problems, multiplication, division and modulus. For division use // and do floor division; for example: for 10//3, the answer should be 3. For an example of the first problem: the program generates two random numbers (let's say num1 is 17 and num2 is 5), and prints out a statement of the problem as 17 + 5 =. The user will enter a correct answer or a wrong answer. If the answer is correct, a message will be printed and one will be added to the number of correct answers. Then the second addition problem is given and checked. Next, two subtraction problems will be given and checked, and so on.
Define a function for each of the 5 operations. Each function will display 2 problems (one at a time) to be solved. The call to each function should return the number of correct answers (0, 1, or 2). After calling all 5 functions in sequence, the main program will print out the total score of that quiz, and asks the user if he/she wants to take another quiz. The main program should keep calling the 5 functions in sequence as long as the user wants to take another quiz.
Insert a screenshot of the programs output
In: Computer Science
Define these 10 programming terms with their definitions related to Computer Science,
here are the ten terms to define.
IDE
syntax error
logic error
while & for looping (mention "end-of-file" looping)
algorithm
increment
decrement
accumulator
flowchart
pseudo code
In: Computer Science
In: Computer Science
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float miles; //miles traveled
float hours; //time in hours
float milesPerHour; //calculated miles per hour
cout << "Please input the Miles traveled" << endl;
cin >> miles;
cout << "Please input the hours traveled" << endl;
cin >> hours;
milesHours = miles / hours;
cout << fixed << showpoint << setprecision(2);
cout << "Your speed is " << milesPerHour << " miles per hour" << endl;
return 0;
}
1. Rewrite the above program such that function main call a return type function named findMilesPerHours to calculate the number of miles per hours. Finish function prototype, call and function definition.#include <iostream>
#include <iomanip>
// Function prototype here
……………………………………………………………………..
using namespace std;
int main()
{
float miles; //miles traveled
float hours; //time in hours
float milesPerHour; //calculated miles per hour
cout << "Please input the Miles traveled" << endl;
cin >> miles;
cout << "Please input the hours traveled" << endl;
cin >> hours;
// Function call here
……………………………………………………………………..
cout << fixed << showpoint << setprecision(2);
cout << "Your speed is " << milesPerHour << " miles per hour" << endl;
return 0;
}
// Function definition here
……………………………………………………………………..
#include <iostream>
#include <iomanip>
using namespace std;
// Function prototype here
……………………………………………………………………..
int main()
{
float miles; //miles traveled
float hours; //time in hours
float milesPerHour; //calculated miles per hour
cout << "Please input the Miles traveled" << endl;
cin >> miles;
cout << "Please input the hours traveled" << endl;
cin >> hours;
// Function call here
……………………………………………………………………..
cout << fixed << showpoint << setprecision(2);
cout << "Your speed is " << milesPerHour << " miles per hour" << endl;
return 0;
}
// Function definition here
……………………………………………………………………..
In: Computer Science
Amdahl's law: Suppose you ran an application on a single
processor in 1.5 hours. Upon careful examination of the code, you
found out that the application is in fact 90% parallelizable.
a) If you can run this application on a computer with 10
processors, what would be the execution time?
b) If you can run this application on a computer with an unlimited
number of processors, what would be the execution
time?
In: Computer Science
I was given an assignment to write three sections of Code.
1. Look up password
2. Decrypt a password.
3. What website is this password for?
Here's the base code:
import csv import sys #The password list - We start with it populated for testing purposes passwords = [["yahoo","XqffoZeo"],["google","CoIushujSetu"]] #The password file name to store the passwords to passwordFileName = "samplePasswordFile" #The encryption key for the caesar cypher encryptionKey=16 #Caesar Cypher Encryption def passwordEncrypt (unencryptedMessage, key): #We will start with an empty string as our encryptedMessage encryptedMessage = '' #For each symbol in the unencryptedMessage we will add an encrypted symbol into the encryptedMessage for symbol in unencryptedMessage: if symbol.isalpha(): num = ord(symbol) num += key if symbol.isupper(): if num > ord('Z'): num -= 26 elif num < ord('A'): num += 26 elif symbol.islower(): if num > ord('z'): num -= 26 elif num < ord('a'): num += 26 encryptedMessage += chr(num) else: encryptedMessage += symbol return encryptedMessage def loadPasswordFile(fileName): with open(fileName, newline='') as csvfile: passwordreader = csv.reader(csvfile) passwordList = list(passwordreader) return passwordList def savePasswordFile(passwordList, fileName): with open(fileName, 'w+', newline='') as csvfile: passwordwriter = csv.writer(csvfile) passwordwriter.writerows(passwordList) while True: print("What would you like to do:") print(" 1. Open password file") print(" 2. Lookup a password") print(" 3. Add a password") print(" 4. Save password file") print(" 5. Print the encrypted password list (for testing)") print(" 6. Quit program") print("Please enter a number (1-4)") choice = input() if(choice == '1'): #Load the password list from a file passwords = loadPasswordFile(passwordFileName) if(choice == '2'): #Lookup at password print("Which website do you want to lookup the password for?") for keyvalue in passwords: print(keyvalue[0]) passwordToLookup = input() ####### YOUR CODE HERE ###### #You will need to find the password that matches the website #You will then need to decrypt the password # #1. Create a loop that goes through each item in the password list # You can consult the reading on lists in Week 5 for ways to loop through a list # #2. Check if the name is found. To index a list of lists you use 2 square backet sets # So passwords[0][1] would mean for the first item in the list get it's 2nd item (remember, lists start at 0) # So this would be 'XqffoZeo' in the password list given what is predefined at the top of the page. # If you created a loop using the syntax described in step 1, then i is your 'iterator' in the list so you # will want to use i in your first set of brackets. # #3. If the name is found then decrypt it. Decrypting is that exact reverse operation from encrypting. Take a look at the # caesar cypher lecture as a reference. You do not need to write your own decryption function, you can reuse passwordEncrypt # # Write the above one step at a time. By this I mean, write step 1... but in your loop print out every item in the list # for testing purposes. Then write step 2, and print out the password but not decrypted. Then write step 3. This way # you can test easily along the way. # ####### YOUR CODE HERE ###### if(choice == '3'): print("What website is this password for?") website = input() print("What is the password?") unencryptedPassword = input() ####### YOUR CODE HERE ###### #You will need to encrypt the password and store it in the list of passwords #The encryption function is already written for you #Step 1: You can say encryptedPassword = passwordEncrypt(unencryptedPassword,encryptionKey)] #the encryptionKey variable is defined already as 16, don't change this #Step 2: create a list of size 2, first item the website name and the second item the password. #Step 3: append the list from Step 2 to the password list ####### YOUR CODE HERE ###### if(choice == '4'): #Save the passwords to a file savePasswordFile(passwords,passwordFileName) if(choice == '5'): #print out the password list for keyvalue in passwords: print(', '.join(keyvalue)) if(choice == '6'): #quit our program sys.exit() print() print()
In: Computer Science
USE R TO WRITE THE CODES!
# 2. More Coin Tosses
Experiment: A coin toss has outcomes {H, T}, with P(H) = .6.
We do independent tosses of the coin until we get a head.
Recall that we computed the sample space for this experiment in class, it has infinite number of outcomes.
Define a random variable "tosses_till_heads" that counts the
number of tosses until we get a heads.
```{r}
```
Use the replicate function, to run 100000 simulations of this
random variable.
```{r}
```
Use these simulations to estimate the probability of getting a head
after 15 tosses. Compare this with the theoretical value computed
in the lectures.
```{r}
```
Compute the probability of getting a head after 50 tosses. What do
you notice?
```{r}
In: Computer Science
Write a C ++ program
that asks the user for the speed of a vehicle (in miles per hour)
and how many hours it has traveled. The program should then use a
loop to display the distance the vehicle has traveled for each hour
of that time period. Here is an example of the output:
What is the speed of the vehicle in mph? 40
How many hours has it traveled? 3
Hour Distance Traveled
--------------------------------
1
40
2
80
3
120
Input Validation: Do not accept a negative number for speed and do
not accept any value less than 1 for time traveled.
Distance
Traveled
The distance a vehicle travels can be calculated as follows:
distance = speed * time
For example, if a train travels 40 miles per hour for 3 hours, the
distance traveled is 120 miles.
In: Computer Science
1. The functional dependencies for the ProAudio relation:
c_id -> f_name, l_name, address, city, state, zip
item_id -> title, price
ord_no -> c_id, order_date
ord_no + item_id -> shipped
zip -> city, state
Original ProAudio relation:
c_id | f_name | I_name | address | city | state | zip | ord_no | item_id | title | price | order_date | shipped |
01 | Jane | Doe | 123 Elm St | Ely | NV | 11111 | 1-1 | 12-31 | More Blues | 8.99 | 12-2-00 | no |
02 | Fred | Fish | 321 Oak St | Ely | NV | 11111 | 2-1 | 21-12 | Jazz Songs | 9.99 | 11-9-00 | yes |
01 | Jane | Doe | 123 Elm St | Ely | NV | 11111 | 1-2 | 12-21 | The Blues | 8.99 | 12-2-00 | yes |
determining functional dependencies for ProAudio database
Normalization is a set of rules that ensures the proper design of a database. In theory, the higher the normal form, the stronger the design of the database.
Use the file for Functional Dependencies Above to answer the following questions:
Now that you are familiar with the mission statement and the entities and attributes the for ProAudio:
In: Computer Science
After reading the Biography in Context database entries on Bill Gates and Steve Jobs, briefly compare and contrast these two leaders of industry. Considering that while both are quite different, observe some unifying qualities.
In: Computer Science
How would you write the following recursively? This is in Java.
public static String allTrim(String str) {
int j = 0;
int count = 0; // Number of extra spaces
int lspaces = 0;// Number of left spaces
char ch[] = str.toCharArray();
int len = str.length();
StringBuffer bchar = new StringBuffer();
if (ch[0] == ' ') {
while (ch[j] == ' ') {
lspaces++;
j++;
}
}
for (int i = lspaces; i < len; i++) {
if (ch[i] != ' ') {
if (count > 1 || count == 1) {
bchar.append(' ');
count = 0;
}
bchar.append(ch[i]);
} else if (ch[i] == ' ') {
count++;
}
}
return bchar.toString();
}
In: Computer Science
Any ideas?
You work in the IT group of a department store and the
latest analytics shows there is a bug that
allows customers to go over their credit limit. The company's
president has asked you to develop a
new algorithm to solve this problem.
Create your algorithm using pseudocode that determines if a
department store customer has
exceeded their credit limit. Be sure you gather the following
inputs from the user:
• Account number
• Balance of the account
• Total cost of all the products the customer is looking to
purchase
• Allowed credit limit
After you gather the inputs, make sure your algorithm calculates if
the user can purchase the
products and provides a message to the user indicating if the
purchase is approved or declined.
In: Computer Science
Write a single, complete If-else-if segment of code based on a variable called ‘Average’ which will process the following task:
Variable=average;
If (average >=95);
{
messagebox.show(“you made the deans list”);
}
(B) Display "You made the Optimate Society” if Average >= 90
Else if (average>=90);
}
Messagebox.show(“you made the Optimate Society”);
}
(C) Otherwise Display "You need a 90 to make an honors list"
Else if (average <=89);
{
Messagebox.show(“you need a 90 to make an honors list”);
In: Computer Science