Assignments are designed to strengthen your problem-solving
skills and build independence.
While the module exercises are small variations of explained module examples,
a single assignment
will have multiple problems, all of which are intended to be
more challenging than the module exercises,
and will feature less detailed guidance. This is a good
thing because, ultimately, you'll have to solve problems
on your own. Facing and overcoming challenging
problems cheerfully is the key to building problem-solving
skill.
A1.0 Audio:
We will start by demonstrating some problem-solving. Consider this
problem. Suppose we want to print out a large arrowhead like this:
And suppose we want to use for-loops to achieve this. How do we go
about solving this problem?
A1.1 Exercise:
At this point do not write any code. Try to sketch out a solution.
A1.2 Video:
And now, on to your assignment. Good luck!
Assignment problems
Identify, by reading carefully, the four errors in this program:
public Class SillyProgram {
public static void main (String argv)
{
System.out.Print ("Cowabunga,");
System.out.println ("dude!")
}
}
Write your response in assignment1.pdf.
Identify, by reading carefully, the errors in this program:
public class Second_SillyProgram {
public static void main (String[] argv)
{
2ndgreeting ();
}
public static void 2ndgreeting
{
system.out.println ("Aloha!");
}
}
Write your response in assignment1.pdf.
The following program wants to print out all the multiples
of 3 between 3 and 30, one per line, as in this output:
3
6
9
12
15
18
21
24
27
30
However, the program has both syntax and logical errors. Find
and fix them:
public class EveryThird {
public static Main (String[] argv)
{
for (int i=3; i<30; i+=3) {
System.out.print (i);
}
}
}
Describe the errors in assignment1.pdf
and write the corrected program in
EveryThird.java.
Read the following program:
public class MethodTracing {
public static void main (String[] argv)
{
printA ();
printB ();
printC ();
printD ();
System.out.println ("OK, that's enough");
}
public static void printA ()
{
printB ();
System.out.println ("A");
printC ();
}
public static void printB ()
{
printC ();
System.out.println ("B");
printD ();
}
public static void printC ()
{
printD ();
System.out.println ("C");
printD ();
}
public static void printD ()
{
System.out.println ("D");
}
}
First, without writing up the program, figure out what it prints out.
Then, implement to check your answer.
Describe the resulting output in assignment1.pdf
Download MakeSquares.java
and add code to this program.
The output needs to be exactly this:
Of course, we know you can write a bunch of
System.out.println's.
So, to make it a little more interesting:
In your code, you may NOT call System.out.print
or System.out.println. In fact, to print, all
you are allowed to do is to call one of the three
methods already provided: printSixStars, printSixSpaces,
or newLine. Or you can call a method of your
own making that does not have printing in it.
You can create methods of your own making to help
reduce redundancy, as you did with the "MOO" example
in class.
What is the total number of method invocations in your
program? Can you write a program with the fewest possible
method invocations, i.e., a program as compact as possible by
cleverly using for-loops?
Download
DrawTool.java
and
FaceDrawing.java.
Then compile and execute. You'll see that the code in
FaceDrawing.java uses methods in DrawTool
to draw a very simple (if creepy) face. For now, you can ignore the text-input and
"enter" button.
For this assignment, create your own, more elaborate drawing. It can be
anything you like, and should make at least 15
different method invocations to methods in DrawTool.
There will be points for originality, humor and drawing
quality. You can do this part of Post-3 in steps:
First, play around with the numbers in methods like
drawOval so you get a sense of how it works.
Then, sketch out your drawing on paper.
After that, you build your picture piece-by-piece.
A smart thing to do: don't write up all your drawing's code
in one shot. Instead, test out smaller parts as you proceed.
Here are some examples of methods you can use in your code:
The first one draws a point at coordinates (1,2). The second
one draws a line from the (1,2) to (3,4). The third draws
a rectangle whose top left corner is at (7,8) and has width 2 and
height 3.
Write a program called Diagonal.java
with a nested for-loop to print this output:
5
4
3
2
1
Note: there is a space before 1.
Write a program called TouchingTriangles.java
that uses for-loops to print this output:
For this question, you will merely write plain text
in assignment1.pdf.
Look up the term augmented reality. Then find a TED talk on
augmented reality and view it. Write up a few paragraphs on
augmented reality in assignment1.pdf
with the following:
What does augmented reality mean?
Describe an application you would like to see in
the future that uses augmented reality and why you think it's a
good idea.
Is there a downside to augmented reality? Should society be
concerned about uses of augmented reality or its
unconstrained rapid growth?
How to submit:
Write all your code and assignment1.pdf
in a directory called assignment1.