Objective
This assignment is to review what you should have learned in CSC 142 and learn how I want you to do pseudocode and commenting for 143. Here’s the highlights this assignment will focus on:
Indefinite Loops
File Processing
Arrays
Classes
Description
You will choose a subject that’s familiar to you and create a program to read an inventory of items. You will create a java Class to hold the items, store them into an array of that class, and print a filtered set of them using a fencepost loop.
As an example, I created an inventory of fly fishing rods. Here’s a sample input file and console output:
Manufacturer Type Weight Length
Sage Standard 5 108
Sage Spey 9 132
TFO Standard 8 108
Orvis Standard 4 96
Which Field to filter on? Manufacturer
Enter the string: sage
Rod [Manufacturer=Sage, Type=Standard, Weight=5, Length=108]
Rod [Manufacturer=Sage, Type=Spey, Weight=9, Length=132]
Which Field to filter on? type
Enter the string: spey
Rod [Manufacturer=Sage, Type=Spey, Weight=9, Length=132]
Which Field to filter on? w
Enter the value: 5
Rod [Manufacturer=Sage, Type=Standard, Weight=5, Length=108]
Which Field to filter on? l
Enter the value: 108
Rod [Manufacturer=Sage, Type=Standard, Weight=5, Length=108]
Rod [Manufacturer=TFO, Type=Standard, Weight=8, Length=108]
Requirements
Your inventory must have the following:
At least 10 items
At least 4 fields with 2 different data types
The names of the fields should start with different letters to make it easier to code
Phase 1 - Pseudocode
You will write some brief pseudocode for your code so I can give you feedback your project before you go through writing the code.
Start by identifying a subject you’re familiar with which has a list of items you can put together. Then create the design for a Java Class to hold those items.
See the “What is Pseudocode” page for information on how to write pseudocode and “Simple Guidelines” for what is correct pseudocode.
Phase 2 - Coding
You will write the complete code for your project and submit both the code, output, and debugging.
Code Requirements
Name the client class with main “Inventory” with matching case. This is extremely important or your code won’t run in my test environment.
Put all classes into one file by omitting the “public” from all but the first
Javadoc function headers with explanations of the function purpose, inputs, and returns
Comments above each code block, blank lines separating blocks that carry out one purpose, but none within the block
Do not comment each line, or lines which are obvious (e.g. print a blank line)
Data must be encapsulated as best as you can
Your main() should be a small as possible
All the real work should be in several very methods with clear purposes.
Ignores upper and lowercase
Accepts any input with the correct first letter in upper or lowercase
In: Computer Science
java programming question: "Write a program that displays a page on a topic of interest to you (e.g., a sport, a city). Include at least one image and one shape (which can be text). " I wanted to do a soccer page but I don't know how to put pictures from the internet on Java. As for my object, I wanted to make a soccer ball. My professor has been really confusing in explaining graphics so any help is appreciated!
In: Computer Science
Create JAVA PROGRAM, and write comment for codes also.
4) Prompt the user for how much stuff a truck can carry, in pounds. Then ask them for the weight of each thing they add until they stop. Don't forget to be safe.
In: Computer Science
Create JAVA PROGRAM, and write comment for codes also.
2) Every extra 3500 calories means gaining a pound. Falling short by 3500 means losing a pound. Get the base amount of calories the person needs in a day (BMR). Then have the user enter in calorie totals for each day and display their weight every week. They might eat more than once in a day.
In: Computer Science
Create JAVA PROGRAM, and write comment for codes also.
3) You want to keep track of your progress towards running a 10K. There are two kinds of races - 5K and 10K. The program needs to ask what race was run and what the time was in seconds until the user quits. When they quit, display the average and best time for each type of race in minutes.
In: Computer Science
1.C++ uses the_______________symbol to represent the AND operator.
2.The switch statement uses the value of a(n) _____________expression to determine which group of statements to branch through.
3.C++ allows the programmer to compare numeric values using ________________________
4.The local t-shirt shop sells shirts that retail for $12. Quantity dis-counts are given as follow:
Number of Shirts Discount
5–10 10%
11–20 15%
21–30 20%
31 or more 25%
Write a program that prompts the user for the number of shirts required and then computes the total price. Make sure the program accepts only nonnegative input.
Use the following sample runs to guide you:
Sample Run 1:
How many shirts would you like ?
4
The cost per shirt is $12 and the total cost is $48
Sample Run 2:
How many shirts would you like ?
0 The cost per shirt is $12 and the total cost is $0
In: Computer Science
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