Old version
This is the CS 112 site as it appeared on December 31, 2020.
Problem Set 2
due by 11:59 p.m. on Sunday, September 27, 2020
Preliminaries
In your work on this assignment, make sure to abide by the collaboration policies of the course.
Using folders
We strongly encourage you to create a separate folder for each
assignment, so that you can more easily keep track of your
work. For example, you could create a folder called ps2
for your
work on this assignment, and put all of the files for PS 2 in
that folder.
If you have questions while working on this assignment, please come to office hours, post them on Piazza, or email instructor.
Make sure to submit your work on Gradescope, following the procedures found at the end of the specification.
Part I
35 points total
This part of the assignment consists of a series of short-answer questions. You will be able to check your answers to at least some of these questions by writing your own programs, but we encourage you to try answering them on your own and convincing yourself of the correctness of your answers before you attempt to test them in programmatically. These questions are similar to ones that could appear on the midterms and final exam, which you will have to take without the use of a computer!
Creating the necessary file
Problems in Part I will be completed in a single PDF file. To create it, you should do the following:
-
Open the template that we have created for these problems in Google Docs: ps2_partI
-
Select File->Make a copy..., and save the copy to your Google Drive using the name
ps2_partI
. -
Add your work to this file.
-
Once you have completed all of these problems, choose File->Download as->PDF document, and save the PDF file on your machine. The resulting PDF file (
ps2_partI.pdf
) is the one that you will submit. See the submission guidelines at this specification.
Important: Put your responses to each of the following problems
in the appropriate section of the ps2PartI
template that you created on Google Drive.
Problem 1: Memory management and arrays
17 points; individual-only
In this problem, you will draw a series of diagrams that illustrate the execution of a simple program that operates on arrays. We will work on a similar problem in Lab 4, and you may find it helpful to review our solutions to that problem before submitting your answers.
Consider the following Java program:
public class ArrayTest { public static void foo(int[] a, int[] b) { // part 2: what does memory look like when we get here? int[] c = {3, 5, 7, 9}; a = c; for (int i = 0; i < b.length; i++) { b[i] = a[i]; } // part 3: what does memory look like when we get here? } public static void main(String[] args) { int[] a = {2, 4, 6, 8}; int[] b = new int[a.length]; int[] c = b; // part 1: what does memory look like when we get here? foo(a, b); // part 4: what does memory look like when we get here? System.out.println(a[2] + " " + b[2] + " " + c[2]); } }
-
(3.5 points) Construct a single memory diagram that shows what things look like in memory just before the call to
foo()
. Include both the stack and the heap in your diagram. Begin by copying the following template into your text file, and then use text characters to complete the diagram.stack | heap +------------+ | main | | +----+ | +---+---+---+---+ | a | --|---+--------->| 2 | 4 | 6 | 8 | | +----+ | +---+---+---+---+ | | | +----+ | | b | | | | +----+ | | | | +----+ | | c | | | | +----+ | +------------+
-
(4 points) Construct a single memory diagram that shows what things look like in memory at the start of the execution of
foo()
– just before its first statement is executed. Include both the stack and the heap in your diagram. -
(6 points) Construct a single memory diagram that shows what things look like in memory at the end of the execution of
foo()
– just before it returns. Include both the stack and the heap in your diagram. -
(3.5 points) Construct a single memory diagram that shows what things look like in memory after the call to
foo()
has returned – just before theprint
statement executes inmain()
.
Problem 2: Understanding code that uses an array
8 points total; individual-only
-
(3 points) What is the output of the following lines of code?
int[] a = {3, 6, 9, 12, 15}; int[] b = {3, 6, 9, 12, 15}; int[] c = b; c[3] = 10; System.out.println(a[3] + " " + b[3] + " " + c[3]);
After giving the output, explain briefly the role that references/pointers play in producing this output..
-
(3 points) Consider the following static method, which operates on an array of integers:
public static void mystery(int[] arr) { for (int i = 0; i < arr.length / 2; i++) { int n = arr.length - 1 - i; int val = arr[n]; arr[n] = arr[i]; arr[i] = val; // What values do the variables have here, // for each value of the loop variable `i`? } }
Consider the following code fragment, which calls this method:
int[] values = {0, 1, 2, 3, 4, 5, 6, 7}; mystery(values);
Copy the table shown below into your text file for this problem, and complete it to illustrate the execution of the above method call.
mystery's variables i | n | val | arr ------------------------------------------- - | - | - | {0, 1, 2, 3, 4, 5, 6, 7} 0 | | |
We have started the table for you. The first row shows what the array looks like before the start of the
for
loop. For each value of the loop variablei
, include a row in the table that shows the values of the other variables at the end of the iteration of the loop for that value ofi
. Note that you should write the value ofarr
as an array literal that shows the current contents of the array, even though the variable itself actually holds a reference to the array. -
(2 points) After running the code fragment from part 2, we then execute the following statement:
System.out.println(Arrays.toString(values));
Do we see the original array, or do we see the changes made by the call to the
mystery()
method? Explain briefly why your answer makes sense.(Note: If you want to check your answer, you’ll need to import the
java.util
package so that you can use theArrays.toString()
method.)
Problem 3: Two-dimensional arrays
10 points total; pair-optional
This is one of only two problems in this assignment that you may complete with a partner. See the rules for working with a partner on pair-optional problems for details about how this type of collaboration must be structured.
Overview
Two-dimensional arrays in Java are extremely similar to
two-dimensional lists in Python.
In Python, a 2-D list is a list of lists:
grid = [ [2, 4], [5, 7], [8, 1] ]
In the same way, a 2-D array in Java is an array of arrays:
int[][] grid = { {2, 4}, {5, 7}, {8, 1} };
(Note: When we declare a variable for a 2-D array, the type of the
elements is followed by two pairs of square brackets: int[][]
)
Here is a comparison of other key operations for 2-D sequences:
operation |
in Python |
in Java |
---|---|---|
determining the number of rows |
|
|
determining the number of elements in row r |
|
|
determining the number of columns in a rectangular grid/matrix (in which all rows have the same length) |
|
|
accessing the element at row r, column c |
|
|
Problems
Assume that you have a variable twoD
that refers to a
two-dimensional array of integers. Here is another example of such
an array:
int[][] twoD = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };
In your answers below, you may assume that the array is rectangular – i.e., that all rows have the same number of elements.
-
(2 points) Write an assignment statement that replaces the value of 6 in the above array with a value of 12.
-
(3 points) Write a code fragment that prints the values in the leftmost column of the array to which
twoD
refers. Print each value on its own line. For the array above, the following values would be printed:1 4 7
Make your code general enough to work on any two-dimensional array named
twoD
that has at least one value in each row. -
(5 points) Write a code fragment that prints the values in the anti-diagonal of the array to which
twoD
refers – i.e., the values along a diagonal line from the bottom-left corner to the upper-right corner. Print each value on its own line. For the array above, the following values would be printed:7 5 3
Make your code general enough to work on any two-dimensional array in which the dimensions are equal – i.e., the number of rows is the same as the number of columns.
Important guidelines:
-
This is a paper and pencil assignment - similar to coding questions you will have to answer on an exam.
-
Work through your logic on paper until you are convinced it works, then verify it by encoding it and testing it out programmatically.
-
I recommend that you write a method for each code fragment. Note that each method should accept a two-dimensional array as an argument to the method.
-
Write a main method that declares and initializes the two-dimensional array (as shown above). Each method you have written should then be called from within the main method to test out your logic.
-
If your logic works, you are done. If it does not, work out why. This process will make you more comfortable answering similar questions on an exam and high-light any Java related issues you may have so you are not reliant on Eclipse to do so.
-
Copy your working code into the specified texfile. You can copy the entire method (or the code fragment).
Part II Programming Problems
65 points total
Important guidelines:
-
Your methods must have the exact headers that we have specified, or we won’t be able to test them. Note in particular that the case of the letters matters.
-
If you are asked to write a method that returns a value, make sure that it returns the specified value, rather than printing it.
-
You should not use any Java classes that we have not covered in the lecture notes.
-
Each of your methods should be preceded by a comment that explains what your methods does and what its inputs are. You should also include a comment at the top of the file, similar to the one that we included in
Methods.java
. -
More generally, use good programming style. Use appropriate indentation, select descriptive variable names, insert blank lines between logical parts of your program, and add comments as necessary to explain what your code does. See the coding conventions for more detail.
Problem 4: Practice with static methods, part I
9 points total; pair-optional
This is the second of only two problems of this assignment that you may complete with a partner. See the rules for working with a partner on pair-optional problems for details about how this type of collaboration must be structured.
This problem asks you to write a series of static methods.
Begin by downloading the following file: Methods.java
Open (copy/paste) it in your IDE, and add your methods to the class that we’ve given you in that file.
Here are the methods you should implement:
-
a static method called
printVertical
that takes aString
as its parameter and prints the characters of the string vertically — with one character per line. For example, a call ofprintVertical("method")
should produce the following output:m e t h o d
We have given you this example method in the starter file.
Important:
To help you test your methods, we have provided a main
method in
Methods.java
that you can use to make appropriate test calls, and
we have included a sample test call for printVertical
.
-
a static method called
printWithSpaces
that takes aString
as its parameter and prints the characters of the string separated by spaces. For example, a call ofprintWithSpaces("method")
should produce the following output:m e t h o d
You should have a single space after the last character. This method should not return a value.
Hint: Use
printVertical
as a model. -
a static method called
middleChar
that takes aString
object as a parameter and returns the character (a value of typechar
) in the “middle” of the string.-
If the string has an odd number of characters, the method should return the actual middle character. For example, a call of
middleChar("clock")
should return the char'o'
. -
If the string has an even number of characters, there are two characters that could both be considered middle characters, and your method should return the first of these characters (the one closer to the beginning of the string). For example, a call of
middleChar("Boston")
should return the char's'
.
This method should not do any printing; rather, it should extract the appropriate character and return it.
Hints:
-
You should perform a computation to determine the index of the character that you need to extract, and you should be able to perform the same computation regardless of whether the string has an odd or even number of characters.
-
Because this method returns a value and doesn’t print anything, you’ll need to perform the necessary printing yourself when you test it. For example:
char middle = middleChar("clock"); System.out.println("the middle of clock is: " + middle);
Also, don’t forget that when you print a string or char, you won’t see the surrounding quotes.
-
-
a static method called
moveToEnd
that takes as its two parameters a stringstr
and an indexi
and returns a new string created by “moving” the firsti
characters ofstr
to the end of the string, after the other characters instr
. If the stringstr
hasi
or fewer characters, the method should simply return the original string. For example:-
moveToEnd("Boston", 4)
should return the string"onBost"
-
moveToEnd("Terriers", 2)
should return the string"rriersTe"
-
moveToEnd("Boston", 8)
should return the string"Boston"
You may assume that the value of
i
is positive. This method should not do any printing; rather, it should return the appropriate string. Hint: You will need to use conditional execution to allow your method to check for the case in which the stringstr
hasi
or fewer characters. -
Additional testing
Once you have completed all of these methods, you should run a
separate test program that we’ve created. This is an important step as
it will help to identify any issues in your methods that might prevent
us from grading them.
Here’s how to use the test program:
-
Download the following file: TestMethods.java
Put it in the same folder as your
Methods.java
file. -
Open
TestMethods.java
in your IDE and compile it. Don’t try to do this until all of your methods have been written. If you are not yet done with all of the methods, you should closeTestMethods.java
and reopen it later. -
If
TestMethods.java
doesn’t compile, that probably means that one or more of your methods does not have the correct header — i.e., either the name, the return type, or the parameters are incorrect. Make whatever changes are needed to your methods to getTestMethods.java
to compile. -
Once
TestMethods.java
does compile, you should run it and check the results that it produces; the correct results are given in the descriptions of the methods above. -
We encourage you to add additional test cases to the ones that we’ve provided.
Problem 5: Practice with static methods, part II
16 points total; individual-only
In a class named MyMethods
, implement each of the methods described
below.
-
a static method called
printDecreasing
that takes aString
as its parameter and prints decreasing substrings of the original string. For example, the callprintDecreasing("method")
should produce the following output:method metho meth met me m
This method should not return a value. Hint: You may find it helpful to use a
for
loop with a header that does not match one of the usual templates.Note: We strongly encourage you to add a
main
method for testing as we did in the previous problem. -
a static method called
firstAndLast
that takes a stringstr
as its parameter and returns a new string formed by combining the first and last characters ofstr
. If the string has only one character, the method should just return the original string. For example:-
firstAndLast("Boston")
should return the string"Bn"
-
firstAndLast("University")
should return the string"Uy"
-
firstAndLast("a")
should return the string"a"
You may assume that
str
has at least one character. This method should not do any printing. Rather, it should return the appropriate string. Hint: You will need to use conditional execution. -
-
a static method called
lastIndexOf
that takes as its two parameters a stringstr
and a characterch
and returns the index of the last occurrence ofch
instr
. Ifch
does not appear instr
at all, the method should return -1. For example:-
lastIndexOf("Boston", 'o')
should return4
-
lastIndexOf("banana", 'a')
should return 5 -
lastIndexOf("banana", 'b')
should return 0 -
lastIndexOf("banana", 'x')
should return -1
This method should not do any printing; rather, it should return the appropriate integer.
Important: You may not use the built-in
lastIndexOf
methods!Hints:
-
One way to solve this problem is to use a
for
loop that examines at one character at time, starting at the end of the string and working backwards towards the beginning of the string. As soon as you find an occurrence of the character you must somehow signal for the loop to stop (think through the conditional expression that controls the loop) or you can use the break statement. -
You will need to use conditional execution.
-
-
a static method called
repeat
that takes as its two parameters a stringstr
and an integern
and returns a new string consisting ofn
copies ofstr
. You may assume thatn
is positive. For example:-
repeat("Java", 3)
should return the string"JavaJavaJava"
-
repeat("oh!", 7)
should return the string"oh!oh!oh!oh!oh!oh!oh!"
This method should not do any printing; rather, it should construct and return the appropriate string.
Hints:
-
You will need to gradually build up the return value using string concatenation. To do so, we recommend that you use a variable for your return value and that you give it the empty string as its initial value:
String result = "";
This will allow you to gradually add to the result by using statements that look like the following:
result = result + expr;
where
expr
is replaced by an appropriate expression. -
You will need to use a
for
loop as part of your implementation of this method.
-
Additional testing
Once you have completed all of these methods, you should use the
following test program to test them:
TestMyMethods.java
Problem 6: Palindrome
15 points total; individual-only
For this problem, we will continue to explore using Java to do input and output, and in particular focus on using Strings. String reference is a simple reference on Strings. Googling “Java String library” or “Java Character library” will produce many references with explanations about these libraries For full details, the canonical reference on these libraries is the Oracle online Java page, which contains every detail you need to know: String, Character.
Begin by downloading StringTest.java. Execute the program as is; you will see that it inputs a sequence of strings and simply prints them out between double quotes. The program will continue to do this until you enter “quit” or if force quit by entering Control-d [hold down the Control key and hit the letter “d”] if you are running your program in a control terminal.
Using the program StringTest.java
as a guide, write a new program
PalindromeTest.java
. The file should contain the two methods as
specified below.
-
Write the method
isPalindrome
which should have the following signature:public static boolean isPalindrome( String s ) { boolean isPal = false; // assume that it is not // code to determine if the string s is a palindrome // If the default (as above) assumes the string is not a palindrome, // the logic here should determine if it is and reassign the return // variable isPal appropriately, or vice verse. return( isPal ); }
-
Encode the logic of the method:
-
Convert the string
s
to all lower case. -
Remove any character from the string which is neither a letter nor a digit. Hint: use replace(....) to replace any non-letter non-digit by the empty String “”.
-
Check if the string
s
is a palindrome by checking to see if each letter is the same as the letter in its “mirror image” position; for example “Taco Cat” and “Toot!” are palindromes:but honor is not.
-
NOTE: There are multiple ways that you can solve this problem, but you are to follow the steps outlined. For example, you may NOT form the solution to the problem by converting the String to a char array first OR reverse the String and then compare if they are equal.
- Write the method
inputStringPalindrome
which should have the following signature:public static int[] inputStringPalindrome()
This method should prompt the user to enter a string, invoke the
isPalindrome
method you have written and output whether or
not the string entered is or is not a palindrome.
The method should run continuously until the user signals
that
they are done. When end of input is signalled, the method
should simply output a goodbye message and return an array. The
retunred array should contain data on how many times the
isPalindrome
method was called,
and how many of the strings input were palindromes. Specifically, the
first element of the array should reflect how many times the method was
called, and the second element of the array should reflect how many
of the input strings, if any, were palindromes.
Test your code on at least the following palindromes:
A man, a plan, a canal, Panama! Go hang a salami, I'm a lasagna hog! Campus Motto: Bottoms up, Mac! 7/1/17 // A palindrome date! Are we not pure "No sir!" Panama's moody Noriega brags. It is garbage! Irony dooms a man; a prisoner up to new era.
Note that the last quote may cause a problem because there are various kinds of “smart quotes” which are different from the simple ASCII double quotes; if all the others work and this one doesn’t, don’t worry about it!
Also test your code on a non-palindrome example – such as the word “palindrome” itself, or this sentence!
Important guidelines:
-
You may not use recursion to solve this problem.
-
Your methods must follow the exact signature stated above.
-
Follow the
StringTest.java
example as a guide for yourinputStringPalindrome
method as this is how we will test it. Your method should continue to prompt for and accept user input until the wordquit
is entered.
Problem 7: Word Palindrome
10 points total; individual-only
For this problem consider a different kind of palindrome – instead of having mirror images of characters in a string, a Word Palindrome has mirror images of words in a sentence; often these are given as Palindrome Poems or Mirror Poems:
Spoken Breath Creating flesh and spirit Spirit and flesh creating Breath spoken.
The need to create a new program that is similar, but not exact, in nature to an existing program is a typical paradigm in computer science. What do you do when you do not want to lose the existing program but you need to modify it to accomplish some related purpose.
One option, and the one to use in this case, is to copy the solution of the first problem to a new file, and modify the new file. We will be talking about this paradigm and other ways of addressing it in the coming lectures!
Write a program WordPalindromeTest.java
which includes a method
named isWordPalindrome
to test whether your input String
is a word palindrome.
-
Write the method
isWordPalindrome
which should have the following signature:public static boolean isWordPalindrome( String s )
-
Encode the logic of this method:
-
The method should begin by converting the passed string to all lower-case and then also remove any character which is: not a digit, not a letter, and not white space (note we need to keep the white space to do the split in the next step)
-
Convert the string into an array of Strings (i.e. each entry in the array is a single word of the original string).
-
Adapt your algorithm from
isPalindrome
to work with this method.
-
-
Return
true
orfalse
accordingly.You may want to output the contents of the array of words to help you with debugging.
-
Demonstrate your code on the poem shown above:
Note: You will have to enter this poem in a single line to avoid the newlines. In eclipse you can also do so as follows using backslashes, a typical way of indicating line breaks in a poem when putting it all in one line:
Spoken Breath / Creating flesh and spirit / Spirit and flesh creating / Breath spoken.
Also test your program on the following sentence:
This is not a word palindrome!
Another Word Palindrome:
Life- imitates nature, always moving, traveling continuously. Continuously traveling, moving always, nature imitates life.
Important
- For this problem we will only be testing the method
isWordpalindrome
. You do not need to write an input method specifically for this problem, however, it will help you test your method if you do.
Problem 8: Array-processing methods
15 points total individual-only
In a class named ArrayMethods
, implement each of the methods
described below.
Important guidelines:
-
Your methods must have the exact headers that we have specified, or we won’t be able to test them. Note in particular that the case of the letters matters.
-
If you are asked to write a method that returns a value, make sure that it returns the specified value, rather than printing it.
-
You should not use any Java classes that we have not covered in the lecture notes.
-
Each of your methods should be preceded by a comment that explains what your methods does and what its inputs are. You should also include a comment at the top of the file, similar to the one that we included in
Methods.java
. -
More generally, use good programming style. Use appropriate indentation, select descriptive variable names, insert blank lines between logical parts of your program, and add comments as necessary to explain what your code does. See the coding conventions for more detail.
-
Include the following class declaration at the beginning of your class:
public static final String[] DAYS = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday, "Friday", "Saturday"};
This array, declared at the class level, is a static final array of strings. Each element of this array reprsents a day of the week. Declaring this array static means it has class level scope and can be accessed by any method written in this class. We will only be using it in one of the methods. Declaring this array to be final means it is read only and cannot be modified.
By convention, variables declared to be constant variables (i.e. final) are typically always in upper case. This way when you are looking through code and see a variable in all upper case, you should be able to assume that the variable is read only.
-
Write a method with the header
public static void swapAdjacent(int[] values)
that takes a reference to an array of integers
values
and swaps adjacent pairs of elements:values[0]
withvalues[1]
,values[2]
withvalues[3]
, etc.For example, after implementing this method and compiling your
ArrayMethods
class, you should see the following when you test the method programmatically:int[] a1 = {0, 2, 4, 6, 8, 10}; ArrayMethods.swapAdjacent(a1); System.out.println( Arrays.toString(a1) );
should output:
[2, 0, 6, 4, 10, 8]
In an odd-length array, the last element should not be moved:
int[] a2 = {1, 2, 3, 4, 5, 6, 7}; ArrayMethods.swapAdjacent(a2); System.out.println( Arrays.toString(a2) );
should output:
[2, 1, 4, 3, 6, 5, 7]
Special case: If the parameter is
null
, the method should throw anIllegalArgumentException
. -
Write a method with the header
public static int[] copyReplace(int[] values, int oldVal, int newVal)
that takes a reference to an array of integers
values
and two integersoldVal
andnewVal
, and that creates and returns a new array that is a copy of the original array, but in which all occurrences of the valueoldVal
are replaced with the valuenewVal
.Important:
-
You may not use any of the built-in methods for copying an array.
-
Your method must not modify the original array.
Examples:
int[] a1 = {2, 5, 4, 2, 7, 4, 2}; int[] a2 = ArrayMethods.copyReplace(a1, 4, 0); System.out.println( Arrays.toString(a2) );
should output:
[2, 5, 0, 2, 7, 0, 2]
and,
int[] a3 = ArrayMethods.copyReplace(a1, 2, -1); System.out.println( Arrays.toString(a3) );
should output:
[-1, 5, 4, -1, 7, 4, -1]
while,
System.out.println( Arrays.toString(a1) );
should output:
[2, 5, 4, 2, 7, 4, 2]
Special case: If the parameter is
null
, the method should throw anIllegalArgumentException
. -
-
Write a method with the header
public static int maxSorted(int[] values)
that takes a reference to an array of integers and returns the length of the longest sorted sequence of integers in the array. For example:
int[] a1 = {3, 8, 6, 14, -3, 0, 14, 207, 98, 12}; System.out.println( ArrayMethods.maxSorted(a1) );
should output:
4
The above call should return
4
, because the longest sorted sequence in the array has four values in it (the sequence-3, 0, 14, 207
). Note that the sorted sequence could contain duplicates. For example:int[] a2 = {17, 42, 3, 5, 5, 5, 8, 4, 6, 1, 19}; System.out.println( ArrayMethods.maxSorted(a2) );
should output:
5
This call should return
5
for the length of the sequence3, 5, 5, 5, 8
.Special cases:
-
If the parameter is
null
, the method should throw anIllegalArgumentException
. -
Your method should return
0
if passed an empty array (i.e., an array of length 0). -
Your method should return
1
if passed an array with one element or an array in which all of the elements are in decreasing order. It should be possible to get a return value of 1 for these cases without needing to explicitly check for them.
-
-
Write a method with the header
public static int getIndexOfDay(String day)
that takes a reference to a string and returns the index of that string in the class array
DAYS
. For example:System.out.println( ArrayMethods.getIndexOfDay("Monday") );
should output:
1
The above call should return
1
, because the string “Monday” is found at position1
of the array.Special cases:
-
If the parameter is
null
, or the string is not found in the array the method should return-1
. -
The method should work correctly regardless of case. The Strings
Monday
andmonday
should produce the same output.
-
-
Write a method with the header
public static int[] reverseInterchange( int[] arr1, int [] arr2 )
that takes references to two
integer
arrays and returns a referene to a thirdinteger
array. Your method should copy the elements from the two arrays passed to the array that will be returned, but interchanged from a forward and reverse direction.int a1[] = {1,2,3,4,5,6}; int a2[] = {10,11,12,13}; System.out.println( Arrays.toString( ArrayMethods.reverseInterchange(a1, a2) ) );
should output:
[1,13,2,12,3,11,4,10]
Special cases:
-
If either argument (i.e. parameter) is
null
, the method should throw anIllegalArgumentException
. -
If the length of the two arrays passed to the method are different, only interchange as many elements as are in the smallest of the two arrays. See above example.
-
Submitting Your Work
Submission Checklist:
- You have read the Java Style Guide (linked on Course page)and followed all guidelines regarding format, layout, spaces, blank lines, and comments;
- You have removed or changed all comments inherited from my templates which do not relate to your solution;
- ensured that the signature of the methods specified in the assignment have not been changed.
- You have verified that your programs satisfy all the performance tests in the templates;
Submitting your work for Part I
Submit your ps2_partI.pdf
file using these steps:
-
If you still need to create a PDF file, open your file on Google Drive, choose File->Download as->PDF document, and save the PDF file on your machine.
-
Click on the name of the assignment in the list of assignments on Gradescope. You should see a pop-up window labeled Submit Assignment. (If you don’t see it, click the Submit or Resubmit button at the bottom of the page.)
-
Choose the Submit PDF option, and then click the Select PDF button and find the PDF file that you created. Then click the Upload PDF button.
-
You should see a question outline along with thumbnails of the pages from your uploaded PDF. For each question in the outline:
- Click the title of the question.
- Click the page(s) on which your work for that question can be found.
As you do so, click on the magnifying glass icon for each page and doublecheck that the pages that you see contain the work that you want us to grade.
-
Once you have assigned pages to all of the questions in the question outline, click the Submit button in the lower-right corner of the window. You should see a box saying that your submission was successful.
Submitting your work for Part II:
You should submit only the following files:
- Methods.java
- MyMethods.java
- PalindromeTest.java
- WordPalindromeTest.java
- ArrayMethods.java
Here are the steps:
-
Click on the name of the assignment in the list of assignments. You should see a pop-up window with a box labeled DRAG & DROP. (If you don’t see it, click the Submit or Resubmit button at the bottom of the page.)
-
Add your files to the box labeled DRAG & DROP. You can either drag and drop the files from their folder into the box, or you can click on the box itself and browse for the files.
-
Click the Upload button.
-
You should see a box saying that your submission was successful. Click the
(x)
button to close that box. -
The autograder will perform some tests on your files. Once it is done, check the results to ensure that the tests were passed. If one or more of the tests did not pass, the name of that test will be in red, and there should be a message describing the failure. Based on those messages, make any necessary changes. Feel free to ask a staff member for help.
Note: You will not see a complete Autograder score when you submit. That is because additional tests for at least some of the problems will be run later, after the final deadline for the submission has passed. For such problems, it is important to realize that passing all of the initial tests does not necessarily mean that you will ultimately get full credit on the problem. You should always run your own tests to convince yourself that the logic of your solutions is correct.
-
If needed, use the Resubmit button at the bottom of the page to resubmit your work. Important: Every time that you make a submission, you should submit all of the files for that Gradescope assignment, even if some of them have not changed since your last submission.
-
Near the top of the page, click on the box labeled Code. Then click on the name of each file to view its contents. Check to make sure that the files contain the code that you want us to grade.
Important
-
It is your responsibility to ensure that the correct version of every file is on Gradescope before the final deadline. We will not accept any file after the submission window for a given assignment has closed, so please check your submissions carefully using the steps outlined above.
-
Make sure to use these exact file names as specified or we will not be able to find your files and grade them.
-
Make sure that you do not try to submit a
.class
file or a file with a~
character at the end of its name. -
If you make any last-minute changes to one of your Java files (e.g., adding additional comments), you should compile and run the file after you make the changes to ensure that it still runs correctly. Even seemingly minor changes can cause your code to become unrunnable.
-
If we are not able to compile your program, you will not receive any credit for that problem submission.