
**PLEASE HELP WRITE IN JAVA
Using this ParticleBase class below create a Particle subclass
I will Thumbs up.
//ParticleBase.java
import java.awt.Color;
public class ParticleBase
{
private Color color;// color as variable of Color class
/*constructor that takes Color object as input argument
* and set to this class color*/
public ParticleBase(Color color)
{
this.color = color;
}
/*The getColor that returns the color object*/
public Color getColor()
{
return color;
}
}//end of the ParticleBase class
Instructions
A Particle Class
Create a subclass of ParticleBase called Particle that will serve as the common parent class for all of your other subclasses. This class represents the common properties and behaviors that all particles share.
Every particle has 6 basic attributes: velocity, acceleration, strength, density, dissolvability, and color. Your Particle class must store and manage all of these except the color, which is managed by the ParticleBase superclass. Your Particle class must provide all of the following:
Particle(color, willDissolve, density)
A constructor that takes the particle's color (as a Color object), a boolean value indicating if the particle will dissolve in acid, and a floating-point double representing the particle's density (in g/cm3). A particle's initial velocity should be 0.0, its initial acceleration should be 1.0, and its strength should be 100.
getDensity()
A getter method that returns this particle's density (a floating-point value).
getVelocity()
A getter method that returns this particle's downward velocity.
getAcceleration()
A getter method that returns this particle's downward acceleration.
getStrength()
A getter method that returns this particle's strength (an integer value).
willDissolve()
A getter method that returns tha boolean value indicating whether this particle can be dissolved (i.e., is it reactive).
weaken()
This method reduces the particle's strength by 1. If the strength becomes zero, this method should remove this particle from the world.
isFalling()
Returns a boolean value indicating whether this particle is in free-fall or not. A particle is falling if it is above the maximum y value and there is nothing in the space immediately underneath it. Be sure not to access the world out of bounds (you cannot fall outside the world).
fall()
This method implements the behavior of falling, using a simple model of Newtonian physics. This method should add the particle's current acceleration to its velocity, in order to update its velocity. The velocity represents the number of cells downward this particle will fall in one turn (as a floating-point number). Once the velocity has been updated, use the integer equivalent of the velocity (use a typecast) as the distance to fall. Note: use a loop to fall one cell at a time until the desired distance is reached, so you can stop falling as soon as the particle lands on something (remember, you already have a boolean method to check for this that you can use in a loop condition). Remember to reset the velocity to zero if the particle stops by landing on something.
swapPlacesIfPossible(x, y)
This method changes place with another particle at the specified location, if appropriate, and returns a boolean value indicating whether this action succeeded. If the specified location is empty, then this particle can definitely move there. If the specified location is already occupied by another particle, and that other particle has a lower density than this one, then this method causes the two particles to swap places (both particles move). Be sure to ensure that the specified location is within bounds (you cannot swap places to a location outside the world).
dodge()
When this particle is not falling (moving straight down through air), it must be "on top of" some other particle, or the bottom edge of the world. In these situations, even though it isn't falling it may still "slide" or "flow" to another position under some circumstances, and the dodge() method implements these alternative motions. Simulating the physics of sliding is beyond the complexity of what we want to do in this assignment. Instead, we will use a really simple model:
-
The particle will "sink" by swapping places with what is immediately below it (x + 0, y + 1) if possible.
-
If it can't sink straight down, the particle will swap places with what is down and to the left one cell (x - 1, y + 1) if possible.
-
Finally, if neither of those options are possible, it will swap places with what is down and to the right one cell (x + 1, y + 1) if possible.
The dodge() method returns a boolean value indicating whether or not the particle moved.
act()
Executes one "turn" for this particle. Each turn, the particle should fall, if it is falling, or dodge otherwise.

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- Given the following Date class public class Date { private int year; private int month; private int day; public Date() { /** Implementation not shown */ } public Date(int year, int month, int day) { /** Implementation not shown */ } public void print() { /** Implementation not shown */ } } assuming that months in the Date class are numbered starting at 1, which of the following code segments will create a Date object for the date September 20, 2020 using the correct constructor? Date d = new Date(); Date d = new Date(9,20); Date d = new Date(9,20,2020); Date d = new Date(2020,9,20); Date d = new Date(2020,20,9);arrow_forwardJava Questions - Based on the code, which answer out of the choices "1, 2, 3, 4, 5" is correct. Explanation is not needed, just please make sure that the answer you have chosen is the correct option. Thanks. Question is in attached picture.arrow_forwardThis class is used to store a time of day and output it.It also stores the current time of day and manipulates it. class Time{ // instance variables for an object to store a time of day: private int hours; private int minutes; // static Time object to store the current time of day, // defaults to midnight: private static Time curTime = new Time(); // Default Constructor // initialize time to 00:00 (midnight) public Time() { hours = minutes = 0; } // Constructor to parse a string hh:mm as the Time public Time(String hourColonMinute) { int colonIdx = hourColonMinute.indexOf(':'); hours = Integer.parseInt(hourColonMinute.substring(0, colonIdx)); minutes = Integer.parseInt(hourColonMinute.substring(colonIdx+1)); normalize(); } // initialize time using parameters for hour and minute public Time(int hr, int min) { hours = hr; minutes = min; normalize(); } // set current time to parameters public static void setCurTime(int hr, int min) {…arrow_forward
- Program 2: The driving class CarTest public class CarTest { 7 ||---- Creates and exercises some Car objects. ||‒‒‒‒‒ public static void main(String[] args) { J /*add code here. Hint: Call constructor four times to create four objects. Then print the descriptions of the four objects. */ System.out.println(cl); System.out.println (c2); System.out.println (c3); System.out.println (c4); /*add code here. Hint: Update data and print updated information. */arrow_forwardWrite in Javaarrow_forwardCode for Activity2PayStub: // Activity2PayStub.java import java.util.Scanner; public class Activity2PayStub{ // constants public static final double OVERTIME_RATE = 1.5; public static final double SS_WITHHOLDING = .1; public static final double FEDERAL_TAX = .2; // fields private String name, ssn; private int regHours, overHours; private double hourlyRate, regPay, overRate, overPay, grossPay, ssWith, fedTax, netPay; public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); // create an object of Activity2PayStub class Activity2PayStub a2ps = new Activity2PayStub(); // get inputs a2ps.getInput(keyboard); // compute payments a2ps.calculate(); // display information a2ps.printPayStub(); } /** * method that takes inputs of name, ssn, regular hours, overtime hours * and hourly rate and set the fields to the values input by the user */ public void getInput(Scanner keyboard) {…arrow_forward
- IN JAVA Look at the following class definition: public class Dog {private int age = 0; // age is given in years, the default value is 0private String name = "Fido"; // default name is FidoDog(String firstName, int firstAge) {name = firstName;age = firstAge;if (age < 0) {age = 0;}}public void setName(String newName) {name = newName;}public int getAge() {return age;}public String getName() {return name;}public void haveBirthdayParty() {age = age + 1;System.out.println("Happy birthday " + name + "! You are now " + age + " years old!");}public void printInfo() {System.out.println("This dog's name is " + name + " and he's " + age + " years old!");}} Make a post containing your answers to all of the questions below: Can you create a new dog without specifying its name? Why or why not? Which of the Dog class's methods are accessors? Which ones are mutators? Can you use the methods provided to make a dog younger? (In other words, can you set age to a lower value than it already was?)…arrow_forwardSee ERROR in Java file 2: Java file 1: import java.util.Random;import java.util.Scanner; public class Account {// Declare the variablesprivate String customerName;private String accountNumber;private double balance;private int type;private static int numObjects;// constructorpublic Account(String customerName, double balance, int type) { this.customerName = customerName;this.balance = balance;this.type = type;setaccountNumber(); // set account number functionnumObjects += 1;}private void setaccountNumber() // definition of set account number{Random rand = new Random();accountNumber = customerName.substring(0, 3).toUpperCase();accountNumber += type;accountNumber += "#";accountNumber += (rand.nextInt(100) + 100);}// function to makedepositvoid makeDeposit(double amount){if (amount > 0){balance += amount;}}// function for withdrawboolean makeWithdrawal(double amount) {if (amount < balance)balance -= amount;elsereturn false;return true;}public String toString(){return accountNumber +…arrow_forwardJava Instance data:Variable mpg for fuel efficiency (miles per gallon = mpg)Variable gas to save how many gallons of gas left in the tank Constructors:Default constructor with no parameter. Use 0 as initial values.Overloaded constructor with two parameters Methods:getMPG() & setMPG()(getGas() & setGas()toString() methoddrive() to simulate that the car is driven for certain miles. For example, v1.drive(100) means vehicle v1 is driven 100 miles. You need to calculate the gas cost and update the gas tank: gas = gas - miles/mpg. You also need to check if there is enough gas left since gas should not be negative. You need to figure out the formal parameters for the above methods. In the testing class, prompt the user for information to create two objects of the Vehicle class. Let each vehicle drive 200 miles. Print out the left gas for each vehicle. Ex: Vehicle 1 Enter the mpg: 40 Enter the gas left: 10.5 Vehicle 2 Enter the mpg: 35 Enter the gas left: 2.1 Vehicle 1…arrow_forward
- Problem Description and Given Info For this assignment you are given the following Java source code files: IStack.java (This file is complete – make no changes to this file) MyStack.java (You must complete this file) Main.java (You may use this file to write code to test your MyStack) You must complete the public class named MyStack.java with fields and methods as defined below. Your MyStack.java will implement the IStack interface that is provided in the IStack.java file. You must implement your MyStack class as either a linked list or an array list (refer to your MyArrayList and MyLinkedList work). Your MyStack must not be arbitrarily limited to any fixed size at run-time. UML UML CLass Diagram: MyStack Structure of the Fields While there are no required fields for your MyStack class, you will need to decide what fields to implement. This decision will be largely based on your choice to implement this MyStack as either an array list or a linked list. Structure of the Methods As…arrow_forwardJava Program This assignment requires one project with two classes. Class Employee Class Employee- I will attach the code for this: //Import the required packages. import java.text.DecimalFormat; import java.text.NumberFormat; //Define the employee class. class Employee { //Define the data members. private String id, lastName, firstName; private int salary; //Create the constructor. public Employee(String id, String lastName, String firstName, int salary) { this.id = id; this.lastName = lastName; this.firstName = firstName; this.salary = salary; } //Define the getter methods. public String getId() { return id; } public String getLastName() { return lastName; } public String getFirstName() { return firstName; } public int getSalary() { return salary; } //Define the method to return the employee details. @Override public String toString() { //Use number format and decimal format //to…arrow_forwardConstructor overloading is not possible in java.True or False.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





