Questions
Please use Java only. Write the class TopResult, which keeps track of the best (highest numbered...

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:

  • TopResult, a default constructor. Initially there should be no top result since no results have been seen yet.
  • newResult, which takes an object of type T, representing a new result, as a parameter, but does not return anything. This method will check whether the new result is better than the current top result, and if so, replace it, otherwise it will ignore it. If there is currently no top result (because no results had been seen yet), then the current result automatically becomes the top result.
  • getTopResult, which does not take any parameters but returns the current top result. If there is currently no top result (because no results have been seen yet), then this method should return null.
  • toString, which will return the toString value of the current top result, or a null if there have been no results yet.

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...

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...

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...

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...

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...

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...

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...

Generate a Personal Web Page:

Write a program that asks the user (you) for the following information:

  • Enter his/her name
  • Enter degree major
  • Enter your future career and a brief description of the career

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:

  • main
    • Get the information from the user
    • Create the html file for writing
    • Write the html by calling the write_html function and sending the information to write
    • Close the file
  • write_html
    • write the html tag
    • write the head element by calling the write_head function and sending the name of the html file created above
    • write the body by calling a write_body function and sending all of the information to write the body)
    • write the closing html tag
  • write_head

, the name of your web page that will show in the browser tab, and closing title tag

  • write the opening head tag
  • write the opening title tag
  • write the closing head tag
  • write_body
    • Body tags are shown below. Make sure that you replace the red placeholder text with the variable used to store the user input

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...

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...

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...

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

Java: Write a Java function to swap two integers.

  1. Java: Write a Java function to swap two integers.

In: Computer Science

​​​​​​In regards to Malware: Develop at least two open research questions and discuss why the problem...

​​​​​​In regards to Malware:

  • Develop at least two open research questions and discuss why the problem of each research question has remained unsolved and present the barriers to finding a solution. Do you find any partial solutions identified? If yes, do they work in part?
  • Discuss the goals of the research questions. Do you expect both questions to remain open over the coming few years? Why?

In: Computer Science

Should I give the Page Quality (PQ) rate of LOW or LOWEST? 1. True/False - A...

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

c++ code please show differint h files and cpp files 2.3 Task 1 You are working...

c++ code please

show differint h files and cpp files

2.3 Task 1

You are working as a programmer designing a vehicular system for the newly forced Edison Arms Company. The weapon system is a generic weapon housing that can fit a number of different weapons that are all controlled by a tank in the same way. Most importantly, is the emphasis on safety. During combat, the weapon systems cannot become unreliable or fail lest the pilots be put in unnecessary danger. The weapons generate heat which will also be a factor. Therefore you will need to provide mechanisms to combat this.

2.3.1 fireControl

This is the mounting system for the weapons. It can store a number of weapons and control them as well as handle problems. It is defined as follows:

fireControl
-weapons:weapon **
-numWeapons: int
---------------------------
+fireControl(numWeapons:int, weaponList: string *)
+~fireControl()
+accessWeapon(i:int):weapon *

The class variables are as follows:

  • weapons: A 1D array of weapon pointers. It must be able to accept any type of weapon defined in the hierarchy.

  • numWeapons: The number of weapons that are mounted into the system. The class methods are as follows:

  • fireControl: This is the constructor. It will receive a list of weapon names as a string array plus the number of weapons. It must allocate memory for the weapons variable and create a weapon based on the information provided by the string array. Create one weapon of the type indicated at each index of the array. If the name of the weapon contains missile, then a missile type weapon must be created and similarly for laser. This should not be case sensitive. For example given the string [”Laser Beam”, ”laser rifle”,”missile pod”, ”missiles”], 4 weapons would be created, the first two being of the class laser, and the last two of the class missile. The default strength for a laser weapon should be set to 5 when creating laser weapons.

  • ∼fireControl: The class destructor. It must deallocate all of the memory assigned to the class.

  • accessWeapon: This receives an int which provides an index in the weapons list. It will return the weapon that is stored at that position. If no such weapon is found there, then throw a weaponFailure exception.

    2.3.2 weaponFailure

  • This is a custom exception class used in the context of this system. It will inherit publicly from the exception class. You will need to override specifically the what method to return the statement ”Weapon System Failure!” without the quotation marks. The name of this class is weaponFailure. This exception will be used to indicate a failure of the weapon system. You will implement this exception in the fireControl class as a struct with public access. You will need to research how to specify exceptions due to the potential for a ”loose throw specifier error” and what clashes this might have with a compiler. Remember that implementations of classes and structs must be done in .cpp files.

As a hint, all of the exception structs in this practical will have three functions:

• A constructor
• a virtual destructor with a throw() specifier
• a const what function which returns a const char* with a throw() specifier.

2.3.3 ammoOut

This is a custom exception class used in the context of this system. It will inherit publicly from the exception class. You will need to override specifically the what method to return the statement ”Ammo Depleted!” without the quotation marks. The name of this class is ammoOut. This exception will be used to indicate a depletion of ammunition for a weapon. You will implement this exception in the weapon class as a struct with public access. You will need to research how to specify exceptions due to the potential for a ”loose throw specifier error” and what clashes this might have with a compiler. Remember that implementations of classes and structs must be done in .cpp files.

2.3.4 Weapon Parent Class
This is the parent class of laser and missile. Both of these classes inherit publicly from

it. It is defined according to the following UML diagram:

weapon
-ammo:int
-type:string
-name: string
-------------------
+weapon()
+weapon(a:int, t:string, n:string)
+getAmmo():int
+setAmmo(a:int):void
+getType():string
+setType(s:string):void
+getName():string
+setName(s:string):void
+ventWeapon(heat:T):void

+∼weapon()
+fire()=0:string
The class variables are as follows:

• ammo: The amount of ammo stored in the weapon. As it is fired, this will deplete. • type: The type of the weapon as a string which relates to its class.

The class methods are as follows:

  • weapon: The default class constructor.

  • weapon(a:int, t:string, n:string): The constructor. It will take three arguments and instantiate the class variables accordingly with name being the last variable set.

  • getAmmo/setAmmo: The getter and setter for the ammo.

  • getType/setType: The getter and setter for the type.

  • getName/setName: The getter and setter for the name.

  • ∼weapon: The destructor for the class. It is virtual.

  • fire: This is the method that will fire each of the weapons and produce a string of the outcome. It is virtual here.

  • ventWeapon: This is a template function. It will receive a generic parameter rep- resenting some amount of heat. When called the function should determine the number of cooling cycles needed for the weapon to cool based on the amount of heat that is passed in. For every 10 units of heat, 1 cycle will be needed. You need to display a number of lines of output (with new lines at the end) to represent this. For example, if there’s 50.83 heat passed or 50 heat passed in, the output should be:

         Heat Cycle 1
         Heat Cycle 2
         Heat Cycle 3
         Heat Cycle 4
         Heat Cycle 5
    

    Pay attention to the format of the output messages. If the heat is less than 10, then display with a newline at the end:

         Insufficient heat to vent
    

    2.3.5 laser

    The ionCannon is defined as follows:

    laser
    -strength:int
    ------------------------------
    +laser(s:int)
    +~laser()
    +setStrength(s:int):void
    +getStrength():int
    +fire():string
    

The class variables are as follows:
• strength: The strength of the laser. Lasers get stronger the longer they are fired.

The class methods are as follows:

  • laser: The class constructor. This receives an initial strength for the laser.

  • ∼laser: This is the destructor for the laser. It prints out ”X Uninstalled!” without the quotation marks and a new line at the end when the class is deallocated. X refers to the name of the weapon. For example:

         Tri Laser Cannon Uninstalled!
    
  • fire: If the laser still has ammo, it must decrease the ammo by 1. It will also increase the strength by 1. It will return the following string: ”X fired at strength: Y” where Y represents the strength before firing and X, the name of the weapon. Do not add quotation marks. If ammo is not available, instead throw the ammoOut exception.

  • getStrength/setStrength: The getter and setter for the strength variable. 2.3.6 missile

    The missile is defined as follows:

    missile
    ------------------------------
    +missile()
    +~missile()
    +fire():string
    

    The class methods are as follows:

    • missile: This is the constructor for the class.

    • ∼missile: This is the destructor for the missile. It prints out ”X Uninstalled!” without the quotation marks and a new line at the end when the class is deallocated. X refers to the name of the weapon. For example:

           Missile Rack Uninstalled!
      
    • fire: If the rifle still has ammo, it must decrease the ammo by 1. It will return the following string: ”X fired!”. X refers to the name of the weapon. Do not add quotation marks. If ammo is not available, instead throw the ammoOut exception.

      You should use the following libraries for each of the classes:
      • fireControl: iostream, string, sstream, algorithm, cstring, exception • weapon: string, iostream, exception, sstream

      Your submission must contain fire- Control.h, fireControl.cpp, laser.h, laser.cpp, missile.h, missile.cpp, weapon.h, weapon.cpp,main.cpp.

In: Computer Science