Questions
Registry Java Programming 2) Interface Comparator: The method for comparing two objects is written outside of...

Registry Java Programming

2) Interface Comparator:

The method for comparing two objects is written outside of the class of the objects to be sorted. Several methods can be written for comparing the objects according to different criteria. Specifically, write three classes, DescriptionComparator, FirstOccComparator,
and LastOccComparator that implement the interface java.util.Comparator.

  • DescriptionComparator implements the interface Comparator. The
    method compare compares the description of two objects. It returns a negative value if the description of the first object comes before the description of the second object in the lexicographic order, 0 if both descriptions are logically the same, and a positive number if the description of the first object comes after the description of the second object in the lexicographic order;

  • FirstOccComparator implements the interface Comparator. It compares the start time of two events. It returns a negative value if the start time of the first event is before that of the second event, 0 if both start times are logically the same, and a positive number if the start time of the first event is after the start time of the second event;

LastOccComparator implements the interface Comparator. It compares the dates of the last recurrences of two events. It returns a negative value if the date of the last recurrence of the first event is before that of the last recurrence of the second event, 0 if the date of the last recurrence of both events is logically the same, and a positive number if the date the last recurrence of the first event is after the date of the last recurrence of the second event.

In: Computer Science

Create a void function named swap that accepts two int parameters and swaps their values. Provide...

Create a void function named swap that accepts two int parameters and swaps their values. Provide a main function demonstrating a call to the swap function. Document the dataflow of the function.

In: Computer Science

use c++ /* The following function receives the class marks for all student in a course...

use c++

/*
The following function receives the class marks for all student in a course and compute standard deviation. Standard deviation is the average of the sum of square of difference of a mark and the average of the marks. For example for marks={25, 16, 22}, then average=(25+16+22)/3=21. Then standard deviation = ((25-21)^2 + (16-21)^2+(22-21)^2)/3.
Implement the function bellow as described above. Then write a test console app to use the function for computing the standard deviation of a list of marks that user inputs as floats in the range of 0.f to 100.f. User signals end of the list by entering -1 as final mark. Make sure to verify user input marks are valid and in the range, before processing them.

*/

float ComputeMarksStandardDeviation(std::array<float> marks)
{
}

In: Computer Science

Consider the following code: import java.util.Scanner; public class Main {    public static void main(String[] args)...

Consider the following code:

import java.util.Scanner;

public class Main {

   public static void main(String[] args) {

   Scanner in = new Scanner(System.in);

String input = "";

System.out.println("Enter the first number: ");
  
input = in.nextLine();
int a = 0;
int b = 0;
  
a = Integer.parseInt(input);
  
System.out.println("Enter the second number: ");
input = in.nextLine();
  
b = Integer.parseInt(input);
  
int result = 0;

result = a/b;
  
System.out.println("a/b : " + result);

   }


Copy the code to your Main.java file and run it with the following inputs:
34 and 0;
‘Thirty-four’ as the first input.

What prevented the program from running successfully?

Update the code, so that it can handle cases a) and b).

Please note the following:
You have to use try-catch to handle exceptions.
To determine exception classes, that you need to catch, use error message from the respective case (a) and b)). Hint: to handle String-to-integer conversion, use NumberFormatException;
Exceptions should be caught so that:
Code never crashes due to non-numeric input (both for first and second values);
Code never crashes due to division by zero;
If non-numeric value is entered for a or b, program should output "Error: entered value is not an integer number. Exiting..." and exit (use System.exit(0); to exit);
If zero value is entered for b, program should output " Error: cannot divide by zero. Exiting..." and exit (use System.exit(0); to exit);
Hints: Use 3 try-catch blocks in total. Try block should only contain the command, that can throw an exception.

In: Computer Science

Please make a Python program where the computer chooses a number and the player guesses the...

Please make a Python program where the computer chooses a number and the player guesses the number.

You need an input, a random number, if statement, and a while loop.

Please reference these when doing the code:

((random reference))

•>>> import random

•>>> random.randint(1, 100)

•67

((While & if referefence))

•>>> cnum = 3

•>>>while true

•>>> if cnum == 3:

•>>> print(‘correct’)

•>>> break

•>>> elif cnum == 2:

•>>> print(‘incorrect’)

Please prepare a Word document that has the Python code and the screen shot of your output.

Here is a sample output screen.

What is your guess? 97

Too high

What is your guess? 6

Too low

What is your guess? 82

Too high

What is your guess? 23

Too low

What is your guess? 64

Too high

What is your guess? 46

Too high

What is your guess? 35

Too low

What is your guess? 40

Too high

What is your guess? 37

Too low

What is your guess? 39

Too high

What is your guess? 38

Correct !

>>>

In: Computer Science

C Programming Number output lines of a text file as it prints to the terminal Do...

C Programming

Number output lines of a text file as it prints to the terminal

Do not use fgets or fopen

It is possible to open file without fopen using SyS commands such as open and RDONLY

Example

1 Line 1

2 Line2

In: Computer Science

Create a variable named specChars and assign it the values of all the punctuation items available...

Create a variable named specChars and assign it the values of all the punctuation items available on the top row of the keyboard, starting with the value above the number 1 through the value above the number 0. For example: !@#........ Prompt the user to enter a number between 1 and 10. For the number of times given by the user, randomly select one of the punctuation items in the specChars variable using the random.choice() function. Print the value that is chosen.

In: Computer Science

2. Implement a main method that does the following: Use Java (a) Creates a binary search...

2. Implement a main method that does the following: Use Java

(a) Creates a binary search tree to hold sports scores as data for a sport of your own choice

(b) Adds between 5 and 8 scores to the tree using standard tree operations Try insert

(c) Choose one of the tree traversals, preorder or postorder, and use it to print out all elements of the tree

(d) Delete one score from the tree using standard tree operations (suppose the score was found to be illegitimate) (e) Use an iterator to get a list for an inorder traversal for the tree (so that you can process each element from the tree), and print out a message about the sports score, including the sport and other informative information you can come up wit

In: Computer Science

The following flow chart is a bubble sort. Write the code for this sort. Make sure...

The following flow chart is a bubble sort. Write the code for this sort. Make sure you display each pass and comparison. Include comments.

In: Computer Science

i'm working on this assignment where we must simulate a bank account. I am having a...

i'm working on this assignment where we must simulate a bank account. I am having a few issues. The first issue is that for menu option 1 i am struggling to make the program so that I can add the name and balance of the account all at once. For example I would type "mike 350" and it would update the dictionary with a new account and balance, right now i have to open the account then deposit a balance separately using two different menu functions. The second issue i am having is that every account name in the dictionary has the same balance, I need to have each person have a separate balance. The third and last issue I am having is with menu option #6, i am not sure how to list the account names and balances with a number of each account to the left, the professor wants the output to look like this for option 6

No Customer Name   Balance

== =============   =======

1 joe 10

2 jim 20

3 eric 30

I have made it this far.

def main():
  
print("1. Open an account")
print("2. Close an Account")
print("3. Deposit money")
print("4. Withdrawal money")
print("5. Enquire about balance")
print("6. Print a list of customers and balances")
print("7. Quit")


accounts = {}
balance = 0
main()

while True:
menu_choice = int(input("Type in a menu choice: "))

#menu choice 1
if menu_choice == 1:
number = input("Enter name of the new customer and \nthe amount of money to be deposited \n into the new account (Ex. 'Mike 350'):")
if number in accounts:
print('This customer already exists!')
  
else:
accounts[number]=balance
print ("Account name", number, "opened.")

#menu choice 2
elif menu_choice == 2:
number = input("Account name:")
  
if number not in accounts:
print('Enter the customer/account name to be deleted: ')
if number in accounts:
if balance>0:
print('Can not close an account with balance greater than zero')
else:
del accounts[number]
print ("Account number", number, "is closed.")

#menu choice 3
elif menu_choice == 3:
print ("Enter the customer name for deposit: ")
number = input("Account name: ")
if number in accounts:
deposit = float(input("Enter the amount to be deposited: "))
  
balance += deposit
print ("your balance is:", balance-deposit, "before deposit")
print ("Your balance is:", balance, "after deposit")
else:
print ("This customer doesn't exist!")

#menu choice 4   
elif menu_choice == 4:
number = input("Enter the customer name for withdrawl: ")
if number not in accounts:
print('This customer doesnt exist!')
  
if number in accounts:
withdraw = float(input("Enter the amount to be withdrawn: "))
if withdraw <=balance:
balance -=withdraw
print ('your balance is:', balance+withdraw, 'before withdrawal')
print ("Your balance is:", balance, 'after withdrawal')
if withdraw >balance:
print ('your balance is:', balance, 'before withdrawal')
print ('You dont have enough balance to cover the withdrawal')

#menu choice 5
elif menu_choice == 5:
number = input('Enter the customer name for balance enquiry: ')
if number not in accounts:
print('This customer doesnt exist!')

if number in accounts:
print('your balance is:', balance)
  
#menu choice 6
elif menu_choice == 6:
print ("Accounts")
for x in accounts.keys():
print ('No Customer Name Balance')
print ('============================')
print (x , balance\n)

#menu choice 7
elif menu_choice == 7:
print ("Quit.")
break
else:
print ("Please enter a menu choice between 1 and 6.")

main()

In: Computer Science

All along we have been discussing processing similar kind of data in a MapReduce job. In...

All along we have been discussing processing similar kind of data in a MapReduce job. In other words lots of data of same kind. But sometimes, you have to process two different kinds of data sets together, join them and produce a joined output. This is called joins. We take joins for granted in RDBMS, but it takes an effort to implement in MapReduce. Research various Join techniques/algorithms available for MapReduce. In your opinion, what are the pros and cons of the various MapReduce join options. Please keep it to your own words rater than paraphrasing sentences from websites.

In: Computer Science

Create a program called DualPivotQuickSort.java that implements the QuickSort algorithm using Yaroslavskiy’s algorithm. The program should...

Create a program called DualPivotQuickSort.java that implements the QuickSort algorithm using Yaroslavskiy’s algorithm. The program should be able to do the following: accepts one command line parameter. The parameter specifies the path to a text file containing the integers to be sorted. The structure of the file is as follows: There will be multiple lines in the file (number of lines unknown). Each line will contain multiple integers, separated by a single whitespace. reads the integers from the text file in part a into an array of integers. sort the integers in descending order using DualPivotQuickSort, and then prints out a sorted version of these integers on a single line, separated by white spaces. The implementation should follow the given the pseudo code/algorithm description. DUALPIVOTQUICKSORTYAROSLAVSKIY(A, left, right) // Sort the array A in index range left, ... , right 1 if right left 1 p= A[le Show transcribed image text

In: Computer Science

Create a MIPS assembly program to calculate x^y using a recursive subprogram. You may assume that...

Create a MIPS assembly program to calculate x^y using a recursive subprogram. You may assume that y is not negative.

In: Computer Science

What is the function of a replacement algorithm?  Do you need a replacement algorithm for direct mapping?  ...

  1. What is the function of a replacement algorithm?  Do you need a replacement algorithm for direct mapping?  
  2. Define the two write policies in about ten sentences total. Discuss the relative merits of the policies.  
  3. Describe a simple way of implementing an LRU replacement algorithm in a 4-way set associative cache.
  4. What is the impact of the design decision of line size on hit ratio?  Discuss the various approaches of cache coherency in a multiprocessor system (in about 10 sentences).  Discuss the relative merits of unified vs. split (code/data) cache design.    

In: Computer Science

SpriteKit is Apple’s built in 2D Gaming API, but there are others out there. What other...

SpriteKit is Apple’s built in 2D Gaming API, but there are others out there. What other libraries exist for developing 2D games? What are the advantages or disadvantages with using SpriteKit vs these other libraries?

In: Computer Science