1.
Write a class Rectangles which manages an array of Rectangle objects.
The constructor of the Rectangles takes an array of Rectangle objects. You can assume the array is filled
Provide these methods
Provide javadoc
Tester File:
RectanglesTester.java
import java.awt.Rectangle; public class RectanglesTester { public static void main(String[] args) { Rectangle[] recs = { new Rectangle(30, 50, 5, 20), new Rectangle(20, 40, 50, 40), new Rectangle(10, 10, 20, 10), new Rectangle(50, 10, 2, 8) }; Rectangles processor = new Rectangles(recs); System.out.printf("Aveage: %.2f\n", processor.averageArea()); System.out.println("Expected: 579.00"); processor.swapMaxAndMin(); System.out.println(processor.toString()); System.out.println("Expected: [java.awt.Rectangle[x=30,y=50,width=5,height=20], java.awt.Rectangle[x=50,y=10,width=2,height=8], java.awt.Rectangle[x=10,y=10,width=20,height=10], java.awt.Rectangle[x=20,y=40,width=50,height=40]]"); Rectangle[] recs2 = { new Rectangle(30, 50, 5, 20), new Rectangle(20, 40, 50, 40), new Rectangle(10, 10, 20, 10), }; Rectangles processor2 = new Rectangles(recs2); System.out.printf("Aveage: %.2f\n", processor2.averageArea()); System.out.println("Expected: 766.67"); processor2.swapMaxAndMin(); System.out.println(processor2.toString()); System.out.println("Expected: [java.awt.Rectangle[x=20,y=40,width=50,height=40], java.awt.Rectangle[x=30,y=50,width=5,height=20], java.awt.Rectangle[x=10,y=10,width=20,height=10]]"); } }
In: Computer Science
: Give a baby $5,000! Did you know that, over the last century, the stock market has returned an average of 10%? You may not care, but you’d better pay attention to this one. If you were to give a newborn baby $5000, put that money in the stock market and NOT add any additional money per year, that money would grow to over $2.9 million by the time that baby is ready for retirement (67 years)! Don’t believe us? Check out the compound interest calculator from MoneyChimp and plug in the numbers!
To keep things simple, we’ll calculate interest in a simple way. You take the original amount (called the principle) and add back in a percentage rate of growth (called the interest rate) at the end of the year. For example, if we had $1,000 as our principle and had a 10% rate of growth, the next year we would have $1,100. The year after that, we would have $1,210 (or $1,100 plus 10% of $1,100). However, we usually add in additional money each year which, for simplicity, is included before calculating the interest.
Your task is to design (pseudocode) and implement (source) for a program that 1) reads in the principle, additional annual money, years to grow, and interest rate from the user, and 2) print out how much money they have each year. Task 3: think about when you earn the most money!
Lesson learned: whether it’s your code or your money, save early and save often…
Sample run 1:
Enter the principle: 2000
Enter the annual addition: 300
Enter the number of years to grow: 10
Enter the interest rate as a percentage: 10
Year 0: $2000
Year 1: $2530
Year 2: $3113
Year 3: $3754.3
Year 4: $4459.73
Year 5: $5235.7
Year 6: $6089.27
Year 7: $7028.2
Year 8: $8061.02
Year 9: $9197.12
Year 10: $10446.8
Sample run 2 (yeah, that’s $9.4MM):
Enter the principle: 5000
Enter the annual addition: 1000
Enter the number of years to grow: 67
Enter the interest rate as a percentage: 10
Year 0: $5000
Year 1: $6600
Year 2: $8360
Year 3: $10296
Year 4: $12425.6
Year 5: $14768.2
.
.
Year 59: $4.41782e+06
Year 60: $4.86071e+06
Year 61: $5.34788e+06
Year 62: $5.88376e+06
Year 63: $6.47324e+06
Year 64: $7.12167e+06
Year 65: $7.83493e+06
Year 66: $8.61952e+06
Year 67: $9.48258e+06
In: Computer Science
Write a C++ program that reads integers from standard input until end of file.
Print out the largest integer that you read in, on a line by itself.
Any erroneous input (something that is not an integer) should be detected and ignored.
In the case where no integers are provided at all, print NO INTEGERS and stop
Remember, try not to do the entire job all at once! First try input of a single number and make sure it works. Make sure that you detect eof correctly. Then add the error checks. Then add the loop...
In: Computer Science
Explain the concept of Key Logging:
a/ Why do Key Loggers exist? What good things are they useful for?
b/ Why do software and hardware key loggers useful for?
c/ Are there ethical reasons to use a key logger?
In: Computer Science
Given the following Scheme definition:
(define x '(define (fac n) (if (= n 0) 1 (* n (fac (- n 1))))))
(This does not define the factorial function fac, but the variable x.)
Write Scheme expressions in terms of x that would have the effect of extracting the following expressions:
E.g., the expression (car x) would extract define.
In: Computer Science
Consider the following Scheme function foo:
(define (foo x) (cond ((null? x) 0) ((not (list? (car x))) (cond ((eq? x '()) (foo (car x))) (else (+ 1 (foo (cdr x)))))) (else (+ (foo (car x)) (foo (cdr x))))))
(8 pts)
Explain what the function computes and how. Don’t just restate the function definition in English — explain the algorithm. Hint: not all the code in this function does something useful.
(2 pts)
Show the result of executing the expression
(foo '(((a (b c) d) (((d) e) f) g)))
In: Computer Science
Given an array ? of numbers and a window size ?, the sliding
window ending at index ? is the subarray ?[? − ? + 1],⋯,?[?] if ? ≥
? − 1, and ?[0],⋯,?[?] otherwise. For example, if ? = [0,2,4,6,8]
and ? = 3, then the sliding windows ending at indices 0, 1, 2, 3
and 4 are respectively [0], [0,2], [0,2,4], [2,4,6], and [4,6,8].
Write a method, movingAverage, that given as input an array ? of
numbers and a window size ?, returns an array ? with the same
length as ?, such that for every index ?, ?[?] is the average of
the numbers in the sliding window ending at index ?. The skeleton
for the method is provided in the file MovingAverage.java.
The following is a sample run.
Input: ? = [0,2,4,6,8], ? = 3 Return: [0,1,2,4,6] Explanation: As
explained above, the sliding windows at indices 0, 1, 2, 3 and 4
are respectively [0], [0,2], [0,2,4], [2,4,6], and [4,6,8]. The
average of the numbers in these sliding windows are respectively =
0, = 1, = 2, = 4, and = 6.
Your method must have time complexity ?(?), where ? is the length
of the input array ?.
Hint: You may find a queue useful.
public class MovingAverage {
/**
* Given an array of integers and a window size,
computes the average of the integers in
* the sliding window ending at each index.
*
* Time Complexity: O(n), where n is the length of the
input array
*
* @param A an array of integers
* @param w a window size
* @return an array of doubles with the same length as
A, whose element at index i is the
* average of the integers in the sliding window ending
at index i in the input array A
*/
public double[] movingAverage(int[] A, int w) {
//Replace this line with your
return statement
return null;
}
}
In: Computer Science
By definition, each relational database table must contain exactly one candidate key.
Select one:
a. True
b. False
Values appearing in a key column must always be unique, regardless of the type of key.
Select one:
a. True
b. False
Which of the following statements about well-formed relations is FALSE?
Select one:
a. A relation is well-formed if it is in third normal form (3NF)
b. Every determinant in a well-formed relation is also a candidate key
c. Any table that meets all of the necessary criteria to be classified as a relation can be considered well-formed
d. Well-formed relations are generally not susceptible to modification anomalies
Each table in a relational database must be related to at least ________ other table(s).
Select one:
a. Zero
b. One
c. Two
d. Three
Data contained within a relational database are stored in two-dimensional ________.
Select one:
a. Folders
b. Lists
c. Catalogs
d. Tables
In: Computer Science
a) Design in pseudocode an algorithm that gets as input an integer k, and a list of k integers N1, .., Nk, as well as a special value SUM. Your algorithm must locate a pair of values in the list that sum to the value SUM. For example, if your list of values is 3, 8, 13, 2, 17, 18, 10, and the value of SUM is 20, then your algorithm should output "either" the two values 2 and 18, "or" the two values 3 and 17. If your algorithm cannot find any pair of values that sum to the value SUM, then it should print out the message "sorry, there is no such pair of values".
b) What is the number of comparisons performed by your algorithm in the Best case? In the Worst case?
c) Express these numbers in the theta (θ) notation.
In: Computer Science
Name the project pa3 [Method 1] In the Main class, write a static void method to print the following text by making use of a loop. Solutions without a loop will receive no credit. 1: All work and no play makes Jack a dull boy. 2: All work and no play makes Jack a dull boy. 3: All work and no play makes Jack a dull boy. 4: All work and no play makes Jack a dull boy. [Method 2] In the Main class, write a static method that accepts an array of floating point parameters. The three elements in the array can be labeled as a, b, and c from first to last. The method computes and returns the results of the quadratic equation in a separate two-element array given by the following equation: −b ± √( b^2 − 4 · a · c) / (2 · a), as long as the discriminant (b^2 − 4 · a · c) is non-negative. Otherwise, return a reference to an array object with zeros in both elements. [Method 3] In the Main class, write a static void method that receives three Strings and prints them in reverse dictionary order, Z to A. Tips: Should the result of the following example be positive: callingString.compareTo(otherString), callingString will appear after otherString in the dictionary. There are six possible orderings of 3 items, so you should not need more than 5 nested if statements. Another option is to place the Strings into an array, use the Arrays.sort static method, and traverse the array backwards. [Method 4] In the Main class, write a static method that receives a String parameter named option. The method then returns one of the following String literals based on the return value of option’s length() function. When option has fewer than 10 characters, return “too small”. When option has more than 10 characters, return “too big”. When option has exactly 10 characters, return “just right”. In the main method, write the Java code to receive the needed actual parameters from the user for each method and call each method. For instance, the three numbers required for Method 2 should be read from the user. Also include the appropriate prompts instructing the user what to enter. Requirements 1) A reference variable and instance object of class java.util.Scanner must be used to read the input from the user. 2) Identifiers must be descriptive (i.e., must self document). 3) Indention of all code blocks (compound statements, code inside braces), including single statements following selection or while statements, is required.
In: Computer Science
(Programming Language: Python)
Complete the function remove number such that given a list of
integers and an integer n, the function removes every instance
of
n from the list. Remember that this function needs to modify the
list, not return a new list.
# DO NOT ADD ANY OTHER IMPORTS from typing import List
def remove_number(lst: List[int], number: int) -> None:
"""
Remove every instance of number in lst. Do this *in-place*, i.e. *modify* the list. Do NOT return a new list.
>>> lst = [1, 2, 3]
>>> remove_number(lst, 3)
>>> lst
[1, 2]
"""
pass
In: Computer Science
Write an implementation of the ADT stack that uses a resizeable array to represent the stack items. Anytime the stack becomes full, double the size of the array. Maintain the stack's top entry at the beginning of the array.
Use c++ to write this code.
In: Computer Science
In: Computer Science
Information Technology (IT) is an application of computers and telecommunications which stores, retrieves, transmits and manipulates data. It also encompasses other information technologies of a ubiquitous nature.
Describe using appropriate examples the ubiquitous nature of IT in the following cases. Clearly explain the input-output mechanism.
1. Wearable Computer
2. In the New Metro Express Project
In: Computer Science
Data must possess some key characteristics. Using example of a wearable computer, elaborate on the following: RELIABLE, TIMELY, And COMPLETE
In: Computer Science