CS46A Spring 19
2A
Spring Break starts April 1, 2019 (No fooling)
Write a program DaysUntilPrinter which will calculate how many days from today (whatever day the program is run) until Spring Break.
Chapter 2 Worked Example 1 from your text gives you a Day class and discusses how to use it. A copy of the Day class itself is at the Codecheck URL below. You need to copy the class into a Bluej project along with the starter code.
Lesson 2 of the Horstmann videos also discusses the Day object. Section 19: How Many Days gives an example of working with the Day object in code.
Do the following:
- Create a Day object representing the current day. Use the constructor that does not take any parameters, like this. new Day(). That way, you will get the current date no matter what day the program is run.
(Note: you will get the date on the server where Codecheck us running. That may be one day later than the date in San Jose)
- Assign that Day object to a variable called today. There is already a statement in the starter file to print the variable today. Do not change it. Note that no matter when the application is run, the value in today should be the current date. That means do not put any parameters in the parentheses for the Day constructor.
- Create a Day object representing the first day of Spring Break and assign it to a variable. (Note that the word break has special meaning in Java, and you can not use it as a variable name)
- Calculate how many days the start of Spring Break is from today (it will be a positive number). Print it.
- Now calculate the date 30 days from today.
- Print the year. (Use a method to get the year)
- Print the month. (Use a method to get the month)
- Print the day of the month. (Use a method to get the day)
For the draft, just add code to the starter to define the variable today and assign today's date to it. When you run the program, the date will be printed by the starter code. Remember to use the version of the constructor that does not take parameters.
2A draft:
2A final:
2B
Complete the class LeetSpeak class using String methods. Remember that all the String methods are accessors. They do not change the original String. If you want to apply multiple methods to a String, you will need to save the return value in a variable.
Complete the class by doing the following
- print the word in uppercase
- print the length of the word
- in the original word, replace
"l" with "1" That is lowercase letter el and the number one. Just replace the single character, not the whole word. ( Use the unmodified variable word)
- print the changed word
- In the changed word, replace
"e" with "3" (Just replace the single character, not the whole word)
- print the this changed word
- In this newest changed word, replace
"t" with "7" (Just replace the single character, not the whole word)
- print the final changed word (with all the replacements)
- the code to print the original word is already included for you. Do not change that statement
You will need to use the replace() method multiple times. Then print the final string. Remember that replace is an accessor method. It returns the changed version of the string. If you want to do something with the returned string - like use replace on it again - you need to save the return value in a variable.
You are given a word in the starter file and Codecheck will test with that word and with a different word. You should not worry about the other word. Codecheck will take care of it.
For the draft, add code to do the first two steps: The original word will be printed for you.
2B draft:
2B final:
2C
In this application you will finish the CirclesViewer
class. You will need the Horstmann graphics package. Download and unzip it if you have not done so. Put it in a convenient location. (You will need this again in future assignments and exams).The URL is https://s3.amazonaws.com/udacity-hosted-downloads/graphics.zip
Create a new Bluej project. Select Project->Import ... Navigate to the graphics folder, select it, and click Open to add it to your project. You may get a warning. Just click Continue. Be sure the folder you import contains the files directly and does not contain an extra folder. Your workbench should look similar to this.

Now create a new class, CirclesViewer
, and copy the starter code from Codecheck. Finish the application to draw three circles . The centers of the circles fall on a horizontal line. Then draw a line connecting centers of the circles. The drawing will looks like this:

Specifications:
- Create in this order: first circle, second circle, third circle, line
- The diameter of all 3 circles is 40.
- The upper left hand corner of the bounding rectangle for the left most circle is at at 50, 10.
- Fill it with red. (Do not draw it) Use the predefined color from the Color class.
- The upper left hand corner of the bounding rectangle for the second circle is at 90, 10.
- Fill it with yellow (Do not draw it) Use the predefined color from the Color class.
- You figure out the coordinates of the last circle
- Fill it with blue. Use the predefined color from the Color class.
- Draw a line between the centers of the first and last circles - the second circle's center will automatically be on the same horizontal line.
- Draw the line in black.
For the draft, fill the first circle with red
2C draft:
2C final: