Automatic Landscape, Redux

In this automatically adjustable image, you will draw a sun or moon in the sky of a landscape. But this time, you'll need to handle the fact that the sun and moon cross the sky every day.

Part 1: Draw a landscape, sun, and moon

If you wish to use the landscape that one of you did for the previous assignment as a starting point, feel free. Alternatively, you can start over from scratch if you like. Create a directory named landscape2 to store your work, then copy into it the Canvas.java that we used in the previous lab. Again create a landscape in a 500 x 500 canvas.

Draw a sun (yellow circle) in the top left corner of the corner, and a crescent moon in the top right corner. Here's how to make a crescent: draw a white circle, then draw another circle that partially overlaps it that is the same color as the background.

Part 2: Make the position of your sun and moon depend on time

The goal of this part of the assignment is to place the sun (or moon) in different places in the sky, depending on time of day. We will keep things simple: assume that the sun appears in full at the left side of the screen at 6 AM, and finally completely vanishes from the right side of the screen at 8 PM. Likewise, the moon crescent completely appears on the left side of the screen at 8 PM, and vanishes from the right side of the screen at 6 AM.

Your program should ask your user how many hours have passed since midnight. The user should then enter an integer indicating how many hours have passed. Thus if the user enters 9, this means that it is 9 AM. If the user enters 23, this means that it is 11 PM. If the user enters 25, this means that it is 1 AM the next day. Your program should then draw the sun or the moon in its correct location. Here is a sample of what the interaction between your program and your user should look like. The user's responses are in red so that you can see what the user has typed. (In reality, though, this should appear in the same color as all the other text in your terminal window.)


Automatic Day/Night Builder

How many hours have passed since midnight? 8

Here is your picture!

You will need to do some arithmetic in a similar fashion to the last assignment to determine precisely where the sun or moon should go. This is all entirely doable using the five basic arithmetic operators, namely +, -, *, /, and/or %. (While this program might be easier to write using "if" statements or perhaps loops, I'd encourage you to try to do this just with the artithmetic operators for the practice.)

Here are some ways you can push yourself further if you like:

Good luck, and have fun!