Exercise 1
Modify the List<T> class of Figure 21.3 in the textbook to include a method that recursively searches a linked-list for a specified value. Ensure that the name of your method includes your last name. The method must return a reference to the value if it is found; otherwise, it must return null. Use your method in a test program that creates a list of integers. The program must prompt the user for a value to locate in the list.
I need the code modified in java to pull out the correct input below is my code, but when ran the only out I get is "Enter integers(-1 to stop):" and nothing else
PLEASE HELP
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static <T> T search_mylastname(List<T> list, T
value, int index){//function name can be updated in all places to
the lastname if needed
if(list == null || index == list.size())
return null;
if(value.equals(list.get(index)))
return list.get(index);
return search_mylastname(list, value, index+1);
}
public static void main(String[] args) {
List<Integer> list = new ArrayList<>();
System.out.println("Enter integers(-1 to stop): "
+ "2, "
+ "4, "
+ "6, "
+ "8, "
+ "10");
int num;
Scanner sc = new Scanner(System.in);
while(true){
num = sc.nextInt();
if(num == -1)
break;
list.add(num);
}
System.out.print("Enter integer to search: ");
int key = sc.nextInt();
Integer res = search_mylastname(list, key, 0);
if(res == null)
System.out.println(key+" is not in list");
else
System.out.println(key+" is available in list");
}
}
In: Computer Science
1
1 2 1
1 2 4 2 1
1 2 4 8 4 2 1
1 2 4 8 16 8 4 2 1
1 2 4 8 16 32 16 8 4 2 1
1 2 4 8 16 32 64 32 16 8 4 2 1
1 2 4 8 16 32 64 128 64 32 16 8 4 2 1
from part a: Write a program that prompts the user to enter an integer from 1 to 15 and displays a pyramid, as shown in the following sample run:
Enter the number of lines: 7
1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
6 5 4 3 2 1 2 3 4 5 6
7 6 5 4 3 2 1 2 3 4 5 6 7
In: Computer Science
What are the three types of database design situations?
In: Computer Science
Python: Implement a grid-maze solving program that uses depth-first search to solve grids. The agent’s actions are moving in one of four directions: up, down, left, and right.
A grid is formatted like below where 1’s represent locations the agent cannot traverse:
1 1 1 1 1 1 1 1
1 0 0 0 1 1 1 1
1 0 0 0 0 0 0 1
1 1 1 0 0 1 0 1
1 0 1 0 0 1 0 1
1 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1
The final path can be displayed with ‘S’ for the initial state, ‘G’ for the goal state, and ‘*’ symbols for the path:
1 1 1 1 1 1 1 1
1 S 0 0 1 1 1 1
1 * * * 0 0 0 1
1 1 1 * 0 1 0 1
1 0 1 * G 1 0 1
1 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1
In: Computer Science
Ive been stuck on this problem for a while. any advice would be appreciated.
Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an int to represent the day.
Ex: If the input is: April 11
the output is: Spring
In addition, check if the string and int are valid (an actual month and day).
Ex: If the input is: Blue 65
The dates for each season are:
Spring: March 20 - June 20
Summer: June 21 - September 21
Autumn: September 22 - December 20
Winter: December 21 - March 19
this is what i have so far, its LONG but ive gone through this with a fine toothed comb and nothing works for me.
import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String inputMonth = sc.next();
int inputDay = sc.nextInt();
{
if (inputMonth.equals("December") && inputDay >= 21 && inputDay <= 31){
System.out.println("Winter");}
else if (inputMonth.equals("January") && inputDay >= 1 && inputDay <= 31){
System.out.println("Winter");}
else if (inputMonth.equals("February") && inputDay >= 1 && inputDay <= 29)
System.out.println("Winter");
else if (inputMonth.equals("March") && inputDay >= 1 && inputDay <= 19)
System.out.println("Winter");
else if (inputMonth.equals("March") && inputDay >= 20 && inputDay <= 31)
System.out.println("Spring");
else if (inputMonth.equals("April") && inputDay >= 1 && inputDay <= 30)
System.out.println("Spring");
else if (inputMonth.equals("May") && inputDay >= 1 && inputDay <= 29)
System.out.println("Spring");
else if (inputMonth.equals("June") && inputDay >= 1 && inputDay <= 20)
System.out.println("Summer");
else if (inputMonth.equals("June") && inputDay >= 21 && inputDay <= 30)
System.out.println("Summer");
else if (inputMonth.equals("july") && inputDay >= 1 && inputDay <= 29)
System.out.println("Summer");
else if (inputMonth.equals("August") && inputDay >= 1 && inputDay <= 29)
System.out.println("Summer");
else if (inputMonth.equals("September") && inputDay >= 1 && inputDay <= 21)
System.out.println("Summer");
else if (inputMonth.equals("September") && inputDay >= 21 && inputDay <= 29)
System.out.println("Autumn");
else if (inputMonth.equals("October") && inputDay >= 1 && inputDay <= 31)
System.out.println("Autumn");
else if (inputMonth.equals("November") && inputDay >= 1 && inputDay <= 29)
System.out.println("Autumn");
else if (inputMonth.equals("December") && inputDay >= 1 && inputDay <= 20)
System.out.println("Autumn");
}
else{
System.out.println("Invalid");
{
thank you.
In: Computer Science
I. Create the class Item with the following members:
1. id, a protected variable of type int
2. name, a protected variable of type string
3. price, a protected variable of type double
4. a public non-default constructor which accepts three
parameters to initialize the variables above
II. Create the class Chair. The class publicly inherits from Item
and has the following members
1. numLegs, a private variable of type int
2. a non-default constructor to initialize numLegs, id,
name, and price
3. accessors and mutators for numLegs
4. an int conversion constructor to convert from an int
to a type of class Chair.
5. a string conversion operator which returns a string
consisting of the values of id, name, price, and int with spaces
between the values
6. overloaded output stream operator
7. overloaded input stream operator
III. Write test code to create an instance of type Chair and test
all members
In: Computer Science
Pell's sequence is the following infinite sequence: 0,
1, 2, 5, 12, 29, 70, 169, 408, 985, 2378 ...
first element is 0, the second is 1 and each remaining element is
the sum of twice the previous element plus
the element before the previous one.
(a) Write a function that receives an integer and return the Pell
number in that position. By
For example, if the input is 2, the output must be 1, if the input
is 5, the output must be 12. Present proof of
desktop and its respective PrtScr for inputs: 1, 2 and 7.
(b) Write a function that receives a number and returns the Pell
number closest to the value entered.
For example, if the input is 20 the output must be 12, if the input
is 21 the output must be 29, if the input is 20.5
the output must be 12. Present desktop tests and their respective
PrtScr for inputs: 49.4, 49.5, 49.6.
PHYTON
In: Computer Science
Open selfmodifying.asm in MARS. Before running the code, predict: what will be the result in register $s0when this program is finished running? Now when you run the program, you will see an error: “Cannot read directly from text segment!”. To allow code to read and write the text segment, check Settings | “Self-modifying code”. Now click run again.
a) Explain the result in register $s0when this program is finished running. In order to understand what is going on, we suggest...
•Step through the program line by line, paying careful attention to the Text Segment and registers.
•Work it out on paper
b) Why would an operating system, which is in charge of running the user’s programs, need to be able to modify the Text Segment?
c) While operating systems can modify the Text Segment, for security purposes they disallow user programs from modifying the Text Segment. Explain.
selfmodifying.asm:
la $t2, wow
lw $t1, 0($t2)
addiu $t1, $t1, 0xFED
sw $t1, 0($t2)
wow: addiu $s0, $zero, 1
In: Computer Science
Write a function in Python 3 (v. 6175+) called
multiplicity00794. The function should receive alimit number and
return:
• how many multiples of 3 or 5 or 7 there are that are less than or
equal to the specified limit.
• the sum of the multiples of 3 or 5 or 7 that are less than or
equal to the specified limit.
• the product of the multiples of 3 or 5 or 7 that are less than or
equal to the specified limit.
For example, if the function is invoked with 15 it should return 9
(because there are 9 multiples of 3, 5 or 7 less than or equal
to
than 15: 3, 5, 6, 7, 9, 10, 12, 14 and 15), 81 (because 3 + 5 + 6 +
7 + 9 + 10 + 12 + 14 + 15 = 81) and 142884000 (because
3 * 5 * 6 * 7 * 9 * 10 * 12 * 14 * 15 = 142884000).
In: Computer Science
Bibi loves to go shopping. One day, one of her favorite stores is offering a discount. Bibi becomes very interested and decided to shop there. If Bibi’s current total is N Rupiah before X% discount and Y % tax, how much should Bibi pay to the cashier?
Format Input :
A single line with three integers N , X and Y .
Format Output :
A single line of the amount of money Bibi has to pay in two decimal places.
Constraints :
Sample Input 1 :
10000 10 10
Sample Output 1 :
9900.00
Sample Input 2 :
90000 5 15
Sample Output 2 :
98325.00
Sample Input 3 :
43250 7 10
Sample Output 3 :
44244.75
Explanation :
On the first sample, the price of the item after a 10% discount is 9000.00. After discounting the price, we apply a 10% tax on top of it so Bibi owes the cashier 9900.00.
NOTES :
IN C LANGUAGE
In: Computer Science
Write a java program that simulates thousands of games and then calculate the probabilities from the simulation results. Specifically in the game, throw two dice, the possible summations of the results are: 2, 3, ..., 12. You need to use arrays to count the occurrence and store the probabilities of all possible summations. Try to simulate rolling two dice 100, 1000, 10,0000 times, or more if needed. Choose one simulation number so that the probabilities you calculated is within 1% absolute error compared with the theoretical probability. For example, the theoretical probability for summation result 2 is approximately 2.78%, then your calculated probability based on simulations should be between 2.28% and 3.28%. The following is required:
• Use an array of ints of length 11 to keep count of the difference occurrences. When an int or double array is created, its values are initialized to 0 by default.
• In the simulation loop, throw the two dice, add the values, and then increase the corresponding array element by 1.
• Turn the occurrence counts into probabilities after the simulation loop is done.
In: Computer Science
1)Given that main memory is composed of only three page frames for public use and that a seven-page program (with pages a, b, c, d, e, f, g) that requests pages in the following order: a, b, c, b, d, a, e, f, b, e, d, f a)Using the FIFO page removal algorithm, indicate the movement of the pages into and out of the available page frames (called a page trace analysis) indicating each page fault with an asterisk (*). Then compute the failure ratio and success ratio. b)Using FIFO again, increase the size of memory so it contains four page frames for public use. Using the same page requests as above, do another page trace analysis and compute the failure and success ratios.
2)Given the following Segment Map Tables for two jobs:
SMT for Job 1 Segment Number |
Memory Location |
0 |
4096 |
1 |
6144 |
2 |
9216 |
3 |
2048 |
4 |
7168 |
SMT for Job 2 Segment Number |
Memory Location |
0 |
2048 |
1 |
6144 |
2 |
9216 |
a. Which segments, if any, are shared between the two jobs?
b. If the segment now located at 7168 is swapped out and later reloaded at 8192, and the segment now at 2048 is swapped out and reloaded at 1024, what would the new segment tables look like?
In: Computer Science
Please create a Risk Mitigation Plan for this scenario.
Scenario: You are an information technology (IT) intern working for Health Network, Inc. (Health Network), a fictitious health services organization headquartered in Minneapolis, Minnesota. Health Network has over 600 employees throughout the organization and generates $500 million USD in annual revenue. The company has two additional locations in Portland, Oregon and Arlington, Virginia, which support a mix of corporate operations. Each corporate facility is located near a colocation data center, where production systems are located and managed by third-party data center hosting vendors.
Company Products Health Network has three main products: HNetExchange, HNetPay, and HNetConnect.
HNetExchange is the primary source of revenue for the company. The service handles secure electronic medical messages that originate from its customers, such as large hospitals, which are then routed to receiving customers such as clinics.
HNetPay is a Web portal used by many of the company’s HNetExchange customers to support the management of secure payments and billing. The HNetPay Web portal, hosted at Health Network production sites, accepts various forms of payments and interacts with credit-card processing organizations much like a Web commerce shopping cart.
HNetConnect is an online directory that lists doctors, clinics, and other medical facilities to allow Health Network customers to find the right type of care at the right locations. It contains doctors’ personal information, work addresses, medical certifications, and types of services that the doctors and clinics offer. Doctors are given credentials and are able to update the information in their profile. Health Network customers, which are the hospitals and clinics, connect to all three of the company’s products using HTTPS connections. Doctors and potential patients are able to make payments and update their profiles using Internet-accessible HTTPS Web sites.
Information Technology Infrastructure Overview
Health Network operates in three production data centers that provide high availability across the company’s products. The data centers host about 1,000 production servers, and Health Network maintains 650 corporate laptops and company-issued mobile devices for its employees. Threats Identified Upon review of the current risk management plan, the following threats were identified:
? Loss of company data due to hardware being removed from production systems ? Loss of company information on lost or stolen company-owned assets, such as mobile devices and laptops
? Loss of customers due to production outages caused by various events, such as natural disasters, change management, unstable software, and so on
? Internet threats due to company products being accessible on the Internet
? Insider threats
? Changes in regulatory landscape that may impact operations Management Request
Senior management at Health Network has determined that the existing risk management plan for the organization is out of date and a new risk management plan must be developed. Because of the importance of risk management to the organization, senior management is committed to and supportive of the project to develop a new plan. You have been assigned to develop this new plan.
Additional threats other than those described previously may be discovered when re-evaluating the current threat landscape during the risk assessment phase.
The budget for this project has not been defined due to senior management’s desire to react to any and all material risks that are identified within the new plan. Given the company’s annual revenue, reasonable expectations can be determined.
Please create a Risk Mitigation Plan
Senior management at Health Network allocated funds to support a risk mitigation plan, and have requested that the risk manager and team create a plan in response to the deliverables produced within the earlier phases of the project. The risk mitigation plan should address the identified threats described in the scenario for this project, as well as any new threats that may have been discovered during the risk assessment. You have been assigned to develop this new plan.
In: Computer Science
Homework – Zeller’s Algorithm Pt2
Zeller’s algorithm computes the day of the week on which a given date will fall (or fell). You are provided this algorithm in CANVAS. In this task, you must transform the provided solution to a “Defined Function”
Function Name
zelleralg
Input Parameters |
• month • day |
Return Values |
The result from the algorithm. This is a number (0-6) that corresponds to the day of the week, where 0 represents Sunday, 1 is Monday, . . ., 6 is Saturday. |
Information collected from the input NONE (all user inputs from
MAIN script) command
Output to the screen NONE (all outputs printed from MAIN
script)
On the main script, welcome the user, ask for his/her name, and DOB (date of birth). Then call the “defined function” and print-out a formatted output.
USER INPUT
USER INPUT
FORMATTED OUTPUT
Finally ask if the user if he/she wants to RERUN. If yes, loop your code all-over. If not, just display a goodbye message.
]
(Below is the solution for the code. you just have to develop the user defined function and the rest of the instructions are above. when finished it should look like the larger text)
clear
clc
% Welcome message
fprintf('Welcome. This program uses the Zeller''s algorithm to compute\n')
fprintf('the day of the week for a given date. Outputs are given as\n')
fprintf('numbers between 0 - 6:\n')
fprintf('(0) - Sun \t(1)- Mon \t(2)- Tue \t(3)- Wed \t(4)- Thu \t(5)- Fri')
fprintf('\t(6)- Sat\n')
fprintf('\nINPUT THE DATE:\n')
% Input section
Month = input('Month: ');
Day = input('Day: ');
Year = input('Year: ');
% A = 1 plus the remainder of (the month number plus 9) divided by 12
A = 1+mod(Month+9,12);
% B = the day of the month
B = Day;
% C = the year of the century PLUS the ROUND DOWN from the equation: (0.09*Month-
0.27).
C = (mod( Year , 1000 ))+floor(0.09*Month-0.27);
%D = the century
D = floor( Year / 100 );
% Additional integers necessary for the calculation
W = floor((13*A-1)/5);
X = floor(C/4);
Y = floor(D/4);
Z = W+X+Y+B+C-2*D;
% R is the day of the week, where 0 represents Sunday, 1 is Monday, . . ., 6 is
Saturday
R = mod( Z, 7 );
fprintf('\nOUTPUT:\n')
fprintf('%d/%d/%d = %d\n', Month, Day, Year, R );
In: Computer Science
In: Computer Science