CSE 11 Programming Assignment 5
Due Date: Thursday, August 25, 10:00PM Pacific Time
Learning Goals
- This PA will give you an opportunity to reflect on how you work through programs.
Collaboration
Different assignments in this course have different collaboration policies. On this assignment, you cannnot collaborate with anyone. Your submission must be your own work and you cannot share or post code from your submission anywhere other than to hand in the assignment.
The starter code is available at:
https://github.com/ucsd-cse11-su222/cse11-pa6-starter
Submission checklist
[ ]
PDF to Gradescope assignmentpa6-notes
[ ]
Two code files for completed tasks topa6-code
(just two of four programs need to be completed)
Task
Make a copy of this Doc. You will fill it in as you work.
Your task is to complete two of the following programs of your choice, and also complete a reflection while you are working.
When you’re ready to start programming, set a timer for 30 minutes – work on these tasks for that much time. Then, take a screenshot or copy/paste (a) your code and (b) the output of the most recent time you ran the program. It’s totally fine if running your code is producing errors at this point, the idea is just to take notes on progress.
Put that output into the Google Doc at the 30 minute mark, and write down a few sentences about your thought process at this point. Also note if you got distracted by another browser tab, your phone, etc during that 30 minutes. You don’t have to tell us how, just say yes/no and how many minutes you think you were distracted for.
When you work again, set another 30 minute timer and work for that time, then repeat taking notes. Then do this one more time, for a total of three 30 minute sessions each followed by note-taking.
If you don’t finish the task, still stop after the three sessions and put the notes for the reflection in place (it’s not expected that you must finish in 90 minutes, though you do have to finish, see below). If you finish early, note the time you finished.
The tasks, which you should complete two of, are here:
-
In a file called
AveragePositives.java
, write a class with amain
method that expects all the command-line arguments to be appropriate inputs toDouble.parseDouble
. It should print the average (mean) of the command-line arguments that, when parsed as doubles, are strictly greater than 0. If there are no numbers in the array that are greater than 0, it should produce 0.Try out at least six different uses of
AveragePositives
at the command line with different lists of numbers that convince you it works for all of the important cases. -
In a file called
PairSelect.java
, add a classPair
with fieldsa
andb
of typeint
(add a constructor to initalize those fields). In a class calledPairSelect
, write a methodgetAs
that takes an array ofPair
and returns an array ofint
that contains thea
field of all thePair
s in the array given as an argument. Write at least 4checkExpect
tests for it to cover interesting cases. -
In a file called
LongStrings.java
, write a method calledlongStrings
that takes an array ofString
and an integern
and produces a new array ofString
s that are just the strings in the array that have lengthn
or greater (the returned array might be shorter than the input array). Write at least 4checkExpect
tests for it to cover interesting cases. -
Copy the
Point
class from the regions code in lecture into a new file calledClosestPoints.java
. Write a class calledClosestPoints
with amain
method that expects to get six command line arguments, representing the x and y coordinates of three points. For example:$ java ClosestPoints 0 0 3 4 3 900
Would represent the points (0, 0), (3, 4), and (3, 900). Your program should print out the pair of points that are closest to one another out of the three points, using the format below:
$ java ClosestPoints 0 0 3 4 3 900 The closest points are (0, 0) and (3, 4) at distance 5.0
Reflection
After you’re done with all three sessions (not necessarily the whole assignment), reflect on the following:
- Where did you spend the most time? You might have different descriptions,
some I can think of that I spend a lot of time on are below; you might have
others.
- Thinking about a particular part of the program
- Understanding an error message
- Figuring out why a particular test wasn’t working
- Typing
- What could you do to reduce the time taken in the future?
- How did this process compare to how you usually complete PAs?
- Overall, what did you learn from this experience about your programming workflow, if anything?
Some comments on this process: this may not be the ideal way for you to work. Sometimes I get a lot of “programming” done while walking my dog, and sometimes setting a problem down for a while and coming back to it is the best thing. You might be working on a day where other urgent obligations interrupt you every 5 minutes. Sometimes you may need to focus really hard for several hours to make any progress. So I don’t expect that you can or should always follow this process. However, doing it once might give you a useful scaffolding strategy, and it does help you understand how your time management and focus works while you’re programming, where you got stuck, etc. So for that reason I think this is a really useful exercise.
Finishing
You must still finish these programs as part of the assignment. There is no autograder for them released while the assignment is out; we will grade them manually after the deadline. Come ask for help in tutor hours (help sessions) if you need help finishing them! We do ask that you spend at least one 30-minute session with notes before coming to help sessions on PA6, and we might ask to see your notes for a sense of your progress when you come.
Submission
Export your notes document as a PDF using Google Docs (under the File menu).
You’ll hand it in under the pa6-notes
assignment on Gradescope.
You’ll hand in the two .java
files with your completed tasks to the
pa6-code
assignment on Gradescope.
Challenges and Extra Practice
If you want more practice or an extra challenge, try writing the programs below. These are not for credit, but feel free to ask us about them on Piazza if you found them interesting!
- Make
ClosestPoints
work for any number of points input on the command line. - Write a method
zip
that takes two arrays ofint
that have the same length and produces an array ofPair
where thePair
’sa
andb
fields are the values in the corresponding index in the first and second providedint
array. - Write a method
unzip
that takes an array ofPair
and returns two arrays, one containing thea
elements and one containing theb
elements. Decide how to represent the return value yourself.
FAQ
-
You only need to finish/submit 2 of the 4 tasks, and pa6-code assignment on Gradescope is due on the same day as pa6-notes (August 25th).
-
Q: In
AveragePositives.java
, is the number of values that we average over all the numbers passed as command line arguments or just the positive numbers?- A: We are only considering positive numbers. So for both the total and the count they should only be of the positive numbers.