Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Project12 Import note: Please as you work, ask any clarifying questions, if need be, don’t just assume to do something if it’s not clear. Main project: For this project, you will make an animation...

1 answer below »
Project12
Import note: Please as you work, ask any clarifying questions, if need be, don’t
just assume to do something if it’s not clear.
Main project: For this project, you will make an animation using DUDraw. Your project
must use classes and objects in the following way.
1. Objects In Class: You must create a class to represent objects that move in you
animation. Your class must have as instance variables at least two objects from
another class that does animations. Think of the instance variable objects as
components of your main animated object. For example, you could create a class called
Fe
isWheel that has 12 Blinker instance variables. Or you could create a class called
Monster that has three GooglyEye instance variables. You do not have to implement
these more basic classes (the code for these classes (SpinningWheel class, GooglyEye
class, Blinker class and Particle class are provided). However, you encouraged to
implement and use your own more basic classes, and are welcome to modify o
enhance the given basic classes (for example, you may add a setter method to change
the size after the object is created, or you may add color, or any other changes you find
useful). You of course may also create new classes of your own for the components -
the possibilities are limitless. If you choose to set the DUDraw scale to other than 1x1,
you may have to make modifications to the underlying classes.
2. A
ay of Objects: You must use a
ays of objects somewhere in your program. You
may either have your class create an a
ay of the more basic component objects (fo
example, a fe
is wheel with an a
ay of blinkers). Another option is for your main
program to create an a
ay of objects of *your* class (for example, your program has an
a
ay of Monster objects)
3. Driver: You must have a separate "driver" program that instantiates object(s) or an
a
ay of objects of your class. This driver class should contain the main() method. Note
that this project will have at least three classes (the driver program, the class you
create, and at least one class for the underlying objects, such as wheels, blinkers,
particles, or whatever else you create)
4. Animation: The animation must continue indefinitely. This means, for example, that
moving objects must bounce off of the edges of the canvas, color-changing objects
must continue to change colors indefinitely, etc.
5. Interaction: The animation must be interactive. This means the animation
esponds/changes in some way when a key is typed or the mouse is moved or pressed.
Here is the example for the basic classes that you are free to use as-is or to modify as
you see fit. If you choose, you do not need to use these - you can create your own
instead.
Second project:
Part 1, First version:
a console/keyboard version of tic-tac-toe:
This program will consist of two classes, TicTacToeBoard, and TicTacToeConsoleGame.
TicTacToeBoard class should have:
● Instance Variables: a 2D a
ay of ints, to store the cu
ent contents of the board. Use
-1 to indicate that the position is occupied by X, 1 to indicate that the position is
occupied by O, and 0 to indicate the position is empty.
● Public Methods:
○ A no-argument constructor, that does the things that a no-argument
constructor should do
○ gameWon(), returns an int, -1 if X has won, 1 if O has won, and 0 if there
is no winner for the given board
○ boardFull(), returns a boolean, true of the board is fully populated, false
otherwise
○ squareOpen(), takes an int row and int column to indicate a position on
the board, and returns a boolean, true if the position is not yet taken.
○ placeMarker(), takes an int row, int column and int player (-1 for X, 1 fo
O), and occupies the given position with the given player. Returns a
oolean (true if the marker was placed successfully, false if it failed fo
any reason).
○ drawGameToConsole(), uses System.out.print() to output the state of the
game to the console.
TicTacToeConsoleGame class should have a main method. It should create a TicTacToeBoard
object, using it to hold details of the cu
ent state of the game. The main method should manage
turn-taking, securing input from the user for the row/column the cu
ent player wants to take, and
displaying the board between each turn. It should end the game when either one player has
three-in-a-row (row, column or diagonal), or when the board is full (tie game, some people call it
a "cats game"). When the game is over, the program should tell the user the outcome ("X wins",
"O wins", or "Cats game").
Part 2, second version:
Create another class called TicTacToeGraphicalGame. This class should use the TicTacToeBoard
class without any changes, except to add a method called drawGameToCanvas(). Understand
that by designing TicTacToeBoard well, we can make a fundamental change to the game
(console versus graphical) by hardly changing half of the program. This is one of the goals of
object-oriented programming. The drawGameToCanvas() method outputs the cu
ent state of the
game to a DUDraw canvas instead of the console. Much like the first version, the class
TicTacToeGraphicalGame uses TicTacToeBoard to hold details of the cu
ent state of the game.
But it works by getting input from the user in a DUDraw window. Each user clicks on a square to
indicate which spot they want to occupy. Like before, it should manage turn-taking, and tell the
user the outcome with the game is over.
Question 1:
Write the dayOfYear() method for our Date class. The answer should be accurate,
taking into account that different months have different lengths, and, in particular,
Fe
uary has 29 days if the year is a leap year and 28 days otherwise.
Here are a couple of examples:
January 1, 2019: dayOfYear() should return a value of 1.
August 23, 2008: dayOfYear() should return a value of 236
August 23, 2007: dayOfYear() should return a value of 235
Question 2:
You'll need to write a boolean method in your BouncingRectangle class called
overlaps() that take another bouncing rectangle and determines if it overlaps this
ectangle, returning true if it does, false otherwise.
Then your main program needs to loop through each of your rectangles, checking each
ectangle to see if it is stopped and if it overlaps with any other moving rectangle. This
equires a nested for loop!
Question 3:
The purpose of this problem is to review the following:
● Create complex boolean expressions, or nested if/if else statements to
accomplish a logical task
● Write methods that take parameters and return values (in this case a boolean
value)
● Using a while or do/while loop to continue getting input from the user that is
e
or-checked until a valid number is entered
● Using a while loop to repeat a multi-step interaction with a user.
Write a Java program that determines whether or not a year is a leap year.
(2 pts of 3) Write a Java program that prompts the user to input a year, co
ectly
determines if that year is a leap-year, and reports the result (yes or no) to the user.
Implement the program by creating a method called isLeapYear that takes an intege
epresenting a year as a parameter and returns true if the year is a leap year and false
otherwise. In main, before calling the isLeapYear method, check if the user inputs a yea
prior to 1582. If they do, tell them the input is invalid. Make sure to test all types of leap
years and non-leap years (see the previous homework assignment for an explanation of
this)
(3 pts of 3) If the user enters a year before 1582, let them know their e
or, and continue
prompting until they input a valid year. Then allow the user to check multiple years.
Prompt them for the year, letting them know that a negative year will signal the end of
the program. The program repeats the process above until they input a negative yea
(i.e., it prompts for input until the user inputs a valid year, properly determines if the yea
is a leap year, then asks them for another year).
Question 4:
The point of this question is to practice declaration/instantiation/initializing contents of
a
ays of objects.
Write code that does the following:
● declares an a
ay of 60 Time24Hour objects,
● instantiates that a
ay
● then initializes the a
ay to hold 60 Time24Hour objects. (Hint: use a for-loop).
The time objects should each be different, should start out at 1:00 and end
1:59
● Now using DUDraw, you can display the time using the method
DUDraw.text(double x, double y, String text) draw the time on the screen of a
clock that ticks from 1:00 to 1:59.
○ Example of using DUDraw.text: DUDraw.text(0.5, 0.5, "Hello
World"); will draw the string "Hello World" in the center of the
screen.
○ Remember to use DUDraw.clear() to clear the string before you
draw the new string
○ DUDraw.pause XXXXXXXXXXto slow down the animation
Question 5:
Suppose you have a Java class to store time, as defined in the diagram below:
Time24Hou
private int hou
private int minute
public Time24Hour()
Default constructor, time initialized to midnight
public Time24Hour(int h, int m)
Constructor, initialize time to h o'clock, m
minutes
public boolean setTime(int h, int m)
Set the time to h o'clock, m minutes, return
false if the time is invalid
public boolean equals(Time24Hour t)
Determine if this time and time t are the
same
public boolean precedes(Time24Hour t)
Determine if this time comes before
time t
public String toString()
Output in 24-hour format, such as 07:23, o
17:09
Here is some sample code that uses and tests the class:
import java.util.Scanner;
public class UseTime24HourClass {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
Time24Hour quittingTime = new Time24Hour(17,0);
Time24Hour now = new Time24Hour();
int hours, minutes;
System.out.println("Please enter the time in hours (24-hour clock)
followed by minutes");
hours = keyboard.nextInt();
minutes = keyboard.nextInt();
if (now.setTime(hours, minutes))
{
System.out.println("The time is now " + now);
if (now.equals(quittingTime))
{
System.out.println("It's quitting time!");
}
else if (now.precedes(quittingTime))
{
System.out.println("It's not quitting time yet.");
}
else
{
System.out.println("It's past quitting time!");
}
}
else
{
System.out.println("That is not a valid time");
}
}
}
Implement the class, and test it using the sample test code above. Note that you
project should have two separate
Answered 1 days After Nov 23, 2021

Solution

Ramachandran answered on Nov 24 2021
127 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here