You will write a PHP program to calculate the payment
receipt for renting a number of movies, using a
conditional structure.
Suppose that the rental rate depends on the number of movies rented
by a customer at a time. There is a limit of renting a maximum of
20 movies at a time.
Conditions: For the first 2 movies rented, the rate is $5.50/movie.
For the next 2 movies rented, the rate is $4.25/movie. For the next
3 movies rented, the rate is $3.00/movie. For any more movies
rented (no more than 20), the rate is $2.00/movie.
Hence, if a customer rents 5 movies, two of those will be rented at
$5.50, two for $4.25 and one for $3.00, for a total of (2*$5.50) +
(2*$4.25) + $3.00 = $22.50.
1) Create a form that asks the customer for his/her name and the
number of movies he/she would like to rent. On submit, display the
total amount due (shown to 2 decimal places) on the same page. (15
points) 2) Save the customer’s submitted name in a flat file called
“visitor.txt”. You should overwrite this name every time someone
submits a name to the form. (10 points)
Give appropriate error or warning messages for both 1) and
2).
In: Computer Science
Problem 1:
You have two sorted lists of integers, L1 and L2. You know the lengths of each list, L1 has length N1 and L2 has length N2.
Design a linear running time complexity algorithm (ONLY PSEUDOCODE) to output a sorted list L1 ∧ L2 (the intersection of L1 and L2).
Important Notes:
For this problem, you don’t need to submit any implementation in Java. Only the pseudocode of your algorithm is required.
Pseudocode is a simple way of writing programming code in English. It uses short phrases to write code for programs before you actually create it in a specific language.
• Example of pseudocode:
Set total to zero
Set grade counter to one
While grade counter is less than or equal to ten
Input the next grade
Add the grade into the total
Set the class average to the total divided by ten
Print the class average.
Please make sure answer is given in pseudocode
In: Computer Science
Here is an interaction in a tic-tac-toe game, with user input in bold:
>> gm = Game.new('andy', 'mike')
=> #<Game:0x2e91d78 @players=[Andy, Mike]>
>> gm.play_game('mike') Mike, enter your next O O--
---
---
Andy, enter your next X
O-X
---
---
Mike, enter your next O
O-X
-O-
---
Andy, enter your next X move
Bad move dude! You go again.
O-X
-O-
---
Andy, enter your next X move
O-X
-OX
---
Mike, enter your next O move
O-X
-OX
--O
Mike, you won!
=> nil
>> gm.play_game('karen')
I don't know that player. Please try again. => nil
>> gm.play_game('andy')
Andy, enter your next O move (1-9): 5 ---
-O-
---
When a new game is created, two players register with it by name (the arguments to Game.new). The play_game message is called with one of the player’s names and starts a new game where that player plays first using the O marker. (A game can be sent repeated play_game messages so the same pair of players can play multiple games). In each iteration, the current player is prompted for the position of her move and then she enters the move number, where the nine squares are numbered in row-major order from 1 through 9. If a move is illegal (i.e., already occupied), the current player is scolded and prompted again for a move. After each move, the board is redrawn. A game ends when either one of the players forms a horizontal, vertical, or diagonal row of her three markers (in the usual way), or the board is full indicating a tie.
The assignment is not to implement this game in Ruby. Rather, the assignment is to develop sequence diagrams to discover the objects, their responsibilities, and the messages they respond to. Specifically, focus on these two scenarios:
Where the current game is not over, the current player is prompted for a legal move which she supplies and then the move is made and the updated game board is displayed.
A new game is started and then play iterates between the two players until one of the players wins.
Note that the first scenario is lower level than and fits into the second scenario.
In: Computer Science
LINUX/UNIX
Create a script named favcolor.sh.
Take 2 parameters, 1. Username, 2. Favorite color.
Print any sentence on console using these 2 parameters.
In: Computer Science
write a c++ program
. Ask the user to enter a number less than 100. Test the input to make sure it is correct, and use a while loop to continuously ask the user for correct input value if they don't follow the input rule. After receiving the correct input, test the number to see if it is even or odd. If it is odd, use a while loop to do the following: Output to the monitor all odd numbers from 1 to your input value. If the number is even, use a while loop to output to the monitor all the even numbers from 0 to your input value.
In: Computer Science
In: Computer Science
In: Computer Science
In: Computer Science
Compare the algorithms and determine which is the fairest for the next process in the queue. Explain why this algorithm will always be the fairest disk-scheduling algorithm.
Describe an example of circumstances where fairness would be an important goal. Describe a scenario where it would be important that the operating system be unfair. Minimum 250 words.
In: Computer Science
Write a function that tells whether a hailstone sequence contains a number that is greater than 1000.
Write a contract, then an implementation, of a function that takes exactly one parameter, an integer n, and returns true if the hailstone sequence starting with n contains a number that is greater than 1000, and returns false otherwise. The heading must be as follows.
bool bigHailstone(int n)
This function must not read or write anything.
Your algorithm for bigHailstone must be a search algorithm. As soon as it sees a number that is greater than 1000, bigHailstone must return true without looking at any more numbers in the hailstone sequence starting with n.
Modify your main function so that it also shows whether there is a number that is greater than 1000.
In: Computer Science
1D List Practice
Could you write the code to solve the following problem that uses 1D lists?
You have been tasked with writing a Python program that will assist the CAU Registrar’s Office with determining the following:
Your program will contain at least three (3) functions - main, getInfo, and compute - that complete the following tasks:
Note: To test/run your program, you will need to generate a file named freshmen.txt that contains 450 GPAs (each on its own line) that have been randomly generated, ranging from 1.0 to 4.0
In: Computer Science
Write a program that prints and calls two methods.
1. Compute and return the future value of an account based on the present value of the account, the interest rate, and the number of years.
future value = p * (1 + r / 100) y
Your method should have the following characteristics:
• It should have three double parameters:
• present value
• interest rate
• number of years
• It should return a double, the future value.
• It should use Math.pow in the calculation.
• It should not have any print statements. The main method should do all the printing.
2. Compute and return the future value of an annuity based on the payment per year, the interest rate, and the number of years.
For each method, the main method needs to obtain input from the user, call the method with the input values, save the result of the method in a local variable, and print the inputs and the result.
future value = p *( (1 + r/100)eY - 1) / r/100
Your method should have the following characteristics:
• It should have three double parameters:
• yearly payment
• interest rate
• number of years
• It should return a double, the future value.
• It should use Math.pow in the calculation.
• It should not have any print statements. The main method should do all the printing.
[ USE JAVA TO WORK ON THIS PROBLEM PLEASE]
_____________________________________________________________________________________________________________________________________________________
# This is my work so far:
import java.util.*;
public class Lab3 {
public static void main(String[] args) {
System.out.println("Lab 3 written by Tesfalem Tekie.");
Scanner input = new Scanner(System.in);
System.out.print(" ");// will work on the prompt
double Value = input.nextdouble();
double Rate = input.nextdouble();
double Years = input.nextdouble();
double futureValue = account(Value, Rate, Years);
System.out.println(" ");// keep working
double AnnFutureValue = annuity(Value, Rate, Years);
System.out.println(" ");// keep working
}//end main method
public static double account(double preValue, double intRate,
double numOfYears ) {
double result = Math.sqrt(p*(1 + r/100)eY);// keep working
return result;
}
public static double annuity(double yearly_pay, double int_rate,
double num_of_years) {
double outcome = Math.sqrt(p* ((1 + r/100)eY - 1)/r/100);// keep
working
return outcome;
}
}//end class method
In: Computer Science
java
You are creating an array where each element is an (age, name)
pair representing guests at a dinner Party.
You have been asked to print each guest at the party in ascending
order of their ages, but if more than one
guests have the same age, only the one who appears first in the
array should be printed.
Example input:
(23, Matt)(2000, jack)(50, Sal)(47, Mark)(23, will)(83200,
Andrew)(23, Lee)(47, Andy)(47, Sam)(150, Dayton)
Example output:
(23, Matt) (47, Mark) (50, Sal (150, Dayton) (2000, Jack) (83200, Andrew)
Read all your party goers from a file. That is passed through the command line.
In your readme:
Describe a solution that takes O (1) space in addition to the
provided input array. Your algorithm may modify the input
array.
This party has some very old guests and your solution should still
work correctly for parties that have even older guests, so your
algorithm can’t assume the maximum age of the partygoers.
Give the worst-case tight-O time complexity of your solution.
I have been working on this problem but have been struggling
with reading the file and
not getting errors such as no element found.
In: Computer Science
PLEASE DONT FORGET TO SOLVE THE ASSIGNMENT QUESTION MOST IMP:
Ex1) Download the code from the theory section, you will find zipped file contains the code of Singly linked list and Doubly linked list, in addition to a class Student.
In Class SignlyLinkedList,
1. There is a method display, what does this method do?
2. In class Test, and in main method, create a singly linked list objet, test the methods of the list.
3. To class Singly linked list, add the following methods:
a- Method get(int n), it returns the elements in the node number n, assume the first node number is 1. You need to check that n is within the range of nodes in the list, otherwise method get returns null.
What is the complexity of your method? Test the method in main.
b- Method insertAfter(int n, E e), its return type is void, it inserts element e in a new node after the node number n, assume the first node number is 1. You need to check that n is within the range of nodes in the list, otherwise through an exception.
What is the complexity of your method?
Test the method in main.
c- Method remove(int n): it removes the node number n, and returns the element in that node, assuming the first node number is 1. You need to check that n is within the range of nodes in the list, otherwise method get returns null.
What is the complexity of your method?
Test the method in main.
d- Method reverse( ): it has void return type. It reverse the order of the elements in the singlylinked list.
What is the complexity of your method?
Test the method in main.
Ex2) In Class DoublyLinkedList
1. There are two methods printForward, printBackward, what do they do?
2. In class Test, and in main method, create a doubly linked list objet, test the methods of the list.
4. To class Doubly linked list, add the following methods:
e- Method get(int n), it returns the elements in the node number n, assume the first node number is 1. You need to check that n is within the range of nodes in the list, otherwise method get returns null.
To make your code more efficient, you should start from the end (header or trailer) that is closer to the target node.
What is the complexity of your method?
Test the method in main.
f- Method insertAfter(int n, E e), its return type is void, it inserts element e in a new node after the node number n, assume the first node number is 1. You need to check that n is within the range of nodes in the list, otherwise through an exception. . To make your code more efficient, you should start from the end (header or trailer) that is closer to the target node.
What is the complexity of your method?
Test the method in main.
g- Method remove(int n): it removes the node number n, and returns the element in that node, assuming the first node number is 1. You need to check that n is within the range of nodes in the list, otherwise method get returns null. To make your code more efficient, you should start from the end (header or trailer) that is closer to the target node.
What is the complexity of your method?
Test the method in main.
Assignment:
To class DoublyLinedList, add method remove(E e) which removes all nodes that has data e. This method has void return type.
doubly package:
doublylinkedlist class:
package doubly;
public class DoublyLinkedList <E>{
private Node<E> header;
private Node<E> trailer;
private int size=0;
public DoublyLinkedList() {
header=new
Node<>(null,null,null);
trailer=new
Node<>(null,header,null);
header.setNext(trailer);
}
public int size() { return size;}
public boolean isEmpty() {return size==0;}
public E first()
{
if (isEmpty()) return null;
return
header.getNext().getData();
}
public E last()
{
if (isEmpty()) return null;
return
trailer.getPrev().getData();
}
private void addBetween(E e, Node<E>
predecessor, Node<E> successor)
{
Node<E> newest=new
Node<>(e,predecessor,successor);
predecessor.setNext(newest);
successor.setPrev(newest);
size++;
}
private E remove(Node<E> node)
{
Node<E>
predecessor=node.getPrev();
Node<E>
successor=node.getNext();
predecessor.setNext(successor);
successor.setPrev(predecessor);
size--;
return node.getData();
}
public void addFirst(E e){
addBetween(e,header,header.getNext());
}
public void addLast(E e){
addBetween(e,trailer.getPrev(),trailer);
}
public E removeFirst(){
if(isEmpty()) return null;
return
remove(header.getNext());
}
public E removeLast()
{
if(isEmpty()) return null;
return remove(trailer.getPrev());
}
public void printForward()
{
for (Node<E>
tmp=header.getNext();tmp!=trailer;tmp=tmp.getNext())
System.out.println(tmp.getData());
}
public void printBackward()
{
for (Node<E>
tmp=trailer.getPrev();tmp!=header;tmp=tmp.getPrev())
System.out.println(tmp.getData());
}
}
node class:
package doubly;
public class Node <E>{
private E data;
private Node<E> prev;
private Node<E> next;
public Node(E d, Node<E> p,Node<E>
n)
{
data=d;
prev=p;
next=n;
}
public E getData() { return data; }
public Node<E> getNext(){ return next; }
public Node<E> getPrev(){ return prev; }
public void setNext(Node<E> n) { next=n;}
public void setPrev(Node<E> p) { prev=p;}
}
student class:
package doubly;
public class Student {
private int id;
private String name;
public Student(int id, String name) {
super();
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "[id=" + id + ", name=" + name + "]";
}
}
test class:
package doubly;
public class Test {
public static void main(String arg[])
{
DoublyLinkedList<Student> myList=new
DoublyLinkedList<>();
myList.addFirst(new Student(1,"Ahmed"));
myList.addFirst(new Student(2,"Khaled"));
myList.addLast(new Student(3,"Ali"));
myList.removeLast();
myList.printForward();
}
}
singly package:
node class:
package Singly;
public class Node <E>{
private E data;
private Node<E> next;
public Node(E d, Node<E> n)
{
data=d;
next=n;
}
public E getData() { return data; }
public Node<E> getNext(){ return next; }
public void setNext(Node<E> n) { next=n;}
}
SinglyLinkedList class:
package Singly;
public class SinglyLinkedList <E>{
private Node<E> head=null;
private Node<E> tail=null;
private int size=0;
public SinglyLinkedList() { }
public int size() { return size;}
public boolean isEmpty() {return size==0;}
public E first()
{
if (isEmpty()) return null;
return head.getData();
}
public E last()
{
if (isEmpty()) return null;
return
tail.getData();
}
public void addFirst(E e)
{
head=new Node<>(e,head);
if(size==0)
tail=head;
size++;
}
public void addLast(E e)
{
Node<E> newest=new Node<>(e,null);
if(isEmpty())
head=newest;
else
tail.setNext(newest);
tail=newest;
size++;
}
public E removeFirst()
{
if(isEmpty()) return null;
E answer=head.getData();
head=head.getNext();
size--;
if (size==0)
tail=null;
return answer;
}
public E removeLast()
{
if(isEmpty()) return null;
E answer=tail.getData();
if (head==tail)
head=tail=null;
else
{
Node<E> tmp=head;
while (tmp.getNext()!=tail)
tmp=tmp.getNext();
tmp.setNext(null);
tail=tmp;
}
size--;
return answer;
}
public void display() {
for (Node<E>
tmp=head;tmp!=null;tmp=tmp.getNext())
System.out.println(tmp.getData());
}
}
Student class:
package Singly;
public class Student {
private int id;
private String name;
public Student(int id, String name) {
super();
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "[id=" + id + ", name=" + name + "]";
}
}
test class:
package Singly;
public class Test {
public static void main(String arg[])
{
SinglyLinkedList<Student> myList=new
SinglyLinkedList<>();
myList.addFirst(new Student(1,"Ahmed"));
myList.addFirst(new Student(2,"Khaled"));
myList.addLast(new Student(3,"Ali"));
Student x=myList.removeLast();
myList.display();
System.out.println(myList.size());
}
}
In: Computer Science
Customer is saying website is running slow when his end clients are trying to access the site. Say for example this is a "Web Server" running "Apache" and "Tomcat" at the backend. It’s the Web Server that the customer is trying to access. They are trying to place an order, but the application is very slow to load. The server is responding slowly to a user request. How would you troubleshoot this scenario?
In: Computer Science