CS46A Fall 19

2A

New Year's Eve is Dec 31, 2019.

Write a program HowLongIsIt which will calculate how many days from today (whatever day the program is run) until New Year's Eve.

Chapter 2 Worked Example 1 from your text or in VitalSource if you are signed in 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.

Create a class called HowLongIsIt and copy in the starter code for the Codecheck URL below. Create a Day class and copy that code from Codecheck link

Now in the main method, do the following:

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.

2A draft:
2A final: (new URL Sep 2)

2B

Complete the class UsingStrings class using String methods. Remember that all the String methods are accessors. They do not change the original String.

Complete the class by doing the following

You are given a word in the starter file and Codecheck will test with that word and with a different word. You do not need to worry about the second word. Codecheck will take care of that.

For the draft, just print the string length. The original word will be printed for you.

2B draft:
2B final:

2C

Railroad crossings have a signal consisting of two circles. Frist one flashes red and then the other flashes red.

a railroad crossing signal

In this problem, you will write a class RailroadCrossingSignal (name of class fixed Sep 4) to model a railroad crossing signal using the Ellipse and Rectangle classes from the Horstmann graphics package. Download and unzip the graphics package if you have not done so. The URL is in the syllabus area of Canvas.

Create a new Bluej project. Select Project->Import ... Navigate to the graphics folder you downloaded and add to your project. Be sure the folder you import contains the files directly and does not contain an extra folder. Your workbench should look similar to the one below - although your classes may be in a different configuration.

Create a class called RailroadCrossingSignal in the project. Add a main method to the class. There is no starter file this time

Your drawing should follow these specifications. The code goes in the main method.

Final output:

output for 2c

 

For the draft create the left circle and fill it with red (Use Color.RED)

2C draft:
2C final: