In Java:
Implement a program that directs a cashier how to give change. The program has two inputs: the amount due and the amount received from the customer.
Display the dollars, quarters, dimes, nickels, and pennies that the customer should receive in return. In order to avoid roundoff errors, the program user should supply both amounts in pennies (for example 274 instead of 2.74).
In: Computer Science
Please use Java only.
Write the class TopResult, which keeps track of the best (highest numbered or highest ordered) result it has seen so far. The class will be a generic type, so the type of results it sees depends on how it is declared.
TopResult Task:
There are a number of situations in which we want to keep track of the highest value we've seen so far - a highest score, a most recent entry, a name which is closest to the end (or the front) of a list, etc. We can imagine writing a simple class which will do this: a class which will let us enter new results one by one, and at any point will let us stop and ask for the highest value.
So far, so good, right? But what if we have a number of different applications for this sort of class - for example, we want to find the top (integer) score on a test, or the highest (decimal) temperature reading, or the GUI window which is closest to the top, etc. Subclassing isn't quite the way to go here, because a TopResult which holds Integers isn't an instance of a TopResult which holds Doubles, and vice versa. But simply writing a class for every possible type we may need may seem like overkill, since the structure of the code is essentially the same from class to class.
In situations such as these, generics come to our rescue. When we define a generic class, the data type we use is essentially represented as a wildcard - a generic type parameter, which we can call T for instance. We write the class assuming that we have a type T in mind, with the idea that we will fill in the type once we know what it is. This is how an ArrayList is implemented, for example. It is a dynamic array of some generic type T, and the exact type is decided (specialized) when we declare the ArrayList variable, for example ArrayList<String> a. If we write our entire class in terms of this unkown type parameter, we will be able to simply name the type later when we want to use it.
In this exercise, we will write the class TopResult. It will have a generic type parameter (you can call it T or something else). Type T must be a Comparable type (thus, the full generic type parameter would be <T extends Comparable<T>>).
A Comparable is an interface which is implemented by classes such as Integer, Double, Character, and String, which allow two members of the same type to be compared to one another to see which is larger. The interface has one method, compareTo, which returns a negative, zero, or positive result indicating whether the object is less than, equal to, or greater than the object it is being compared against:
> Integer three = 3, four = 4;
> three.compareTo(four)
-1
> four.compareTo(three)
1
> four.compareTo(four)
0
The TopResult task should implement the following public methods:
The following shows an example use of this class:
> TopResult<Integer> tr = new
TopResult<Integer>();
> tr.getTopResult() // no results seen yet, should be null
null
> tr.newResult(7);
> tr.getTopResult()
7
> tr.newResult(3);
> tr.getTopResult()
7
> tr.newResult(4);
> tr.getTopResult()
7
> tr.newResult(9);
> tr.getTopResult()
9
> tr.newResult(20);
> tr.getTopResult()
20
> tr.toString() // this will print the toString() of the current
top result
"20"
Please make sure that it passes the following: https://repl.it/@micky123/SweetEmotionalExtraction
Please be sure that the work is your own, not a duplicate of somebody else's. Thank you.
In: Computer Science
13. (6 point) when a downcast is necessary what would be the problem if the downcast was not done? Use an example in your explanation.
14. (6 point) The following code is from the ColorViews in-class example. what is the purpose of the function ? what the base class for the type the function is found in? How is it called?
override func draw(_ rect: CGRect)
{
// Get the context being draw upon
let context = UIGraphicsGetCurrentContext( )
//Create layer, if necessary
checkDrawLayer (context)
…
In: Computer Science
I have this projegt I will use asp.net wHAT PART CAN USE TO COMPLETE THE PROGET
For this project in the (Advanced Computer Networks) course, you may pick a system/language you like, design the project, implement it, and write a project report about it.
This project is related with the Readers and writers. Two types of users, Readers and Writers, can access a shared file. The file is allowed to be read by many readers simultaneously, but to be written by a single writer at a time when no reader is reading.
In this project, you are asked to solve the readers and writers problem by using the clientserver model and a kind of communication facility. Your program consists of several clients (readers and writers), a file access authorization server, and a shared file bank server. Clients may read/write different files or share a single file.
Before a client being able to access a file from the shared file bank server, it must first communicate with the authorization server to get a ticket (an encrypted permission which can be decrypted only by the shared file bank server). The file access authorization server receives requests from clients and manipulates up to N different files. The request message involves the following fields: the ID of the client, the type of the request (R/W), and the name of the file that the client wants to access. A transaction of accessing a file from a client is as follows:
• send REQ Message: request to the authorization server
• block_receive: waiting for a ticket
• send read/write (data) and ticket: request to the file bank server
• block_receive: waiting for data or ACK
• send REL Message: release to authorization server
• loop for certain times
You should test your program by different cases. For example, suppose your system manipulate five files A, B, C, D and E. One possible test case is to start with 30 clients that randomly access (with 30 percent of writers) a randomly selected file. Each client repeat 100 times. You should design at least 5 different test cases and you should use at least 3 computers to run your project.
Project Report: the report is a short report (2-4 pages) for what your project will be. It should contain a problem description and motivation, a description of the design of your solution, a description of your implementation, and an evaluation of how well your system solved the original problem.
In: Computer Science
Problem Description:
Problem Description:
Write a program that obtains the execution time of Selection sort, Insertion sort, Merge sort for input size 50000, 100,000, 150,000, 200,000, 250,000, and 300,000. Your program should create data randomly and print a table like this:
|
Array Size |
Selection sort |
Insertion sort |
Merge sort |
|
50000 |
|||
|
100000 |
|||
|
150000 |
|||
|
200000 |
|||
|
250000 |
|||
|
300000 |
|||
|
2000000 |
|||
|
3000000 |
|||
|
4000000 |
(Hint: You can use the code template below to obtain the execution time.)
long startTime = System.currentTimeMillis();
perform the task;
long endTime = System.currentTimeMillis();
long executionTime = endTime - startTime;
Analysis:
(Describe the problem including input and output in your own words.)
Coding: (Copy and Paste Source Code here. Format your code using Courier 10pts)
Name the public class Exercise18_29
Testing: (Describe how you test this program)
In: Computer Science
C#
To write a program using a stack and a program using a queue.
Code a class encapsulating a queue of foods using a circular array. A food has the following attributes: name, the number of calories per serving and the number of servings per container. Limit your queue to 20 food items. In addition to writing the enqueue, dequeue, and peek methods, you will write two more methods: a method that returns the average calories per serving of all the foods in the queue; a method that returns the food items with the highest total calories (ie: number of calories per serving * servings per container). Write a program to test your queue with all these methods
In: Computer Science
for C++
I'm trying to write a code that asks for double values and counts how many times 2 consecutive values differ by at most 1. The output on 0 should be the answer.
With inputs 1, 1.7, 0.8, -0.1, -1, 0 : it should return 4 but keeps giving me 0. This is the correct output because only 1 and 1.7 differ by at most 1 as does 1.7 and 0.8, 0.8 and -0.1, and -0.1 and -1. We do not check whether 0 is within 1 of the previous number because 0 is the input that causes us to exit.
Why is this if every time a number differs by at least one my if statement should n++?
#include <iostream>
using namespace std;
int main ()
{
double n1, n2 = 0;
int n = 0;
cout << "Enter a number." << endl;
cin >> n1;
while (n1 != 0) {
if ((n1 - n2) > -1
&& (n1 - n2) < 1) {
n++;
n1 =
n2;
}
else {
cout
<< "Enter another number or 0 to end." << endl;
cin
>> n1;
}
}
cout << n << endl;
return 0;
}
In: Computer Science
Programing assignment in C++
The following description has been adopted from Deitel & Deitel. One of the most popular games of chance is a dice game called "craps," which is played in casinos and back alleys throughout the world. The rules of the game are straightforward:
A player rolls two dice. Each die has six faces. These faces contain 1, 2, 3, 4, 5, and 6 spots. After the dice have come to rest, the sum of the spots on the two upward faces is calculated. If the sum is 7 or 11 on the first throw, the player wins. If the sum is 2, 3, or 12 on the first throw (called "craps"), the player loses (i.e. the "house" wins). If the sum is 4, 5, 6, 8, 9, or 10 on the first throw, then the sum becomes the player's "point." To win, you must continue rolling the dice until you "make your point." The player loses by rolling a 7 before making the point.
Write a program that implements a craps game according to the above rules. The game should allow for wagering. This means that you need to prompt that user for an initial bank balance from which wagers will be added or subtracted. Before each roll prompt the user for a wager. Once a game is lost or won, the bank balance should be adjusted. As the game progresses, print various messages to create some "chatter" such as, "Sorry, you busted!", or "Oh, you're going for broke, huh?", or "Aw cmon, take a chance!", or "You're up big, now's the time to cash in your chips!"
Use the below functions to help you get started! You may define more than the ones suggested if you wish!
|
(5 pts) void print_game_rules (void) — Prints out the rules of the game of "craps". |
|
|
(5 pts) double get_bank_balance (void) - Prompts the player for an initial bank balance from which wagering will be added or subtracted. The player entered bank balance (in dollars, i.e. $100.00) is returned. |
|
|
(5 pts) double get_wager_amount (void) - Prompts the player for a wager on a particular roll. The wager is returned. |
|
|
(5 pts) int check_wager_amount (double wager, double balance) - Checks to see if the wager is within the limits of the player's available balance. If the wager exceeds the player's allowable balance, then 0 is returned; otherwise 1 is returned. |
|
|
(5 pts) int roll_die (void) - Rolls one die. This function should randomly generate a value between 1 and 6, inclusively. Returns the value of the die. |
|
|
(5 pts) int calculate_sum_dice (int die1_value, int die2_value) - Sums together the values of the two dice and returns the result. Note: this result may become the player's point in future rolls. |
|
|
(10 pts) int is_win_loss_or_point (int sum_dice) - Determines the result of thefirstdice roll. If the sum is 7 or 11 on the roll, the player wins and 1 is returned. If the sum is 2, 3, or 12 on the first throw (called "craps"), the player loses (i.e. the "house" wins) and 0 is returned. If the sum is 4, 5, 6, 8, 9, or 10 on the first throw, then the sum becomes the player's "point" and -1 is returned. |
|
|
(10 pts) int is_point_loss_or_neither (int sum_dice, int point_value) - Determines the result of any successive roll after the first roll. If the sum of the roll is the point_value, then 1 is returned. If the sum of the roll is a 7, then 0 is returned. Otherwise, -1 is returned. |
|
|
(5 pts) double adjust_bank_balance (double bank_balance, double wager_amount, int add_or_subtract) - If add_or_subtract is 1, then the wager amount is added to the bank_balance. If add_or_subtract is 0, then the wager amount is subtracted from the bank_balance. Otherwise, the bank_balance remains the same. The bank_balance result is returned. |
|
|
(5 pts) void chatter_messages (int number_rolls, int win_loss_neither, double initial_bank_balance, double current_bank_balance) - Prints an appropriate message dependent on the number of rolls taken so far by the player, the current balance, and whether or not the player just won his roll. The parameter win_loss_neither indicates the result of the previous roll. |
|
|
(10 pts) Others? |
|
|
(20 pts) A main ( ) function that makes use of the above functions in order to play the game of craps as explained above. Note that you will most likely have a loop in your main ( ) function (or you could have another function that loops through the game play). |
Have a great time with this assignment! There is plenty of room for creativity! Note: I have not stated how you must display the game play! You may do as you wish!
1-Your project must contain one header file (a .h file), two C source files (which must be .c files), and project workspace.
In: Computer Science
Generate a Personal Web Page:
Write a program that asks the user (you) for the following information:
Once the user has entered the requested input, the program should create an HTML file, write the html file utilizing the tags below, and display the user entered text in the placeholder of the red text for a simple Web page.
Your program should include the following functions:
, the name of your web page that will show in the browser tab, and closing title tag
This is what I have but it is throwing errors:
def main():
print('Enter the following information to create your')
print('your personal web page')
name = input('Enter your full name: ')
major = input('Enter your degree major: ')
career = input('Describe your ideal future career: ')
f = open('profile.html', 'w')
write_html()
f.close()
def write_html():
html = '<html>\n' +\
write_head(f) +\
write_body() +\
'</html>\n'
def write_head():
head = '<head>\n' +\
print('My Personal Web Page') +\
'</head>\n'
def write_body():
body = '<body>\n' +\
'<h1>' + name + '</h1>\n' +\
'<hr />\n' +\
'<h2>' + major + '</h2>\n' +\
'<hr />\n' +\
'<hr />' + career + '</hr>\n' +\
'</body>'
main()
In: Computer Science
Please Answer with C code and I will rate! Thank you.
Problem) Write a program that reads 20 integers and stores them
in two arrays of 10 elements
each. Then, the program should check if the two arrays have common
elements, if yes,
the program should displays the value of each common element and
its position in both arrays. Otherwise,
it should display a message and that their elements are
different.
In: Computer Science
Suppose your RSA public-key factors are p = 6323 and q = 2833, and the public exponent e is 31. Suppose you were sent the Ciphertext 6627708. Write a program that takes the above parameters as input and implements the RSA Decryption function to recover the plaintext. Use C or C++ programming language.
In: Computer Science
C++ langugae only
The first phase of compilation is called scanning or lexical analysis. This phase interprets the input program as a sequence of characters and produces a sequence of tokens, which will be used by the parser.
Your job is to write (in C++) a simple scanner for source code that obeys the language described below. You may assume that the input is syntactically correct.
Your program simply needs to read each token and then print out what type it is, based on the following language rules:
keyword -> if | then | else | begin | end |
function | return identifier -> character |
character identifier
integer -> digit | digit integer
real -> integer.integer
special -> + | - | = | < | >
digit -> 0|1|2|3|4|5|6|7|8|9
character -> a|b|c ... |z|A|B|C ... |Z
In: Computer Science
In: Computer Science
In regards to Malware:
In: Computer Science
Should I give the Page Quality (PQ) rate of LOW or LOWEST?
1. True/False - A page with a mismatch between the location of the page and the rate location; for example an English (UK) page for an English (US) rating task.
I think it's false because of this statement in the general guidelines. Do not consider the country or location of the page or website for PQ rating. For example, English (US) raters should use the same PQ standards when rating pages from other English language websites (UK) as they use when rating pages from the U.S websites. In other words, English (US) raters should not lower the PQ rating because the page location (UK) does not match the task location.
2. True/False A file type other than a webpage, for example: a PDF, a Microsoft Word document, or a PNG file.
3. True/False A page that gets a Didn't Load flag.
4. True/False Pages with an obvious problem with functionality or errors in displaying content.
In: Computer Science