Question: 3 . 5 Defining your own class ( Atom ) Your task is write a class named Atom. The Atom class has three instance variables

3.5 Defining your own class (Atom)
Your task is write a class named Atom. The Atom class has three instance variables representing an atom's state: the number of protons, neutrons, and electrons. The constructor should look like this:
public Atom(int givenProtons, int givenNeutrons, int givenElectrons){
// insert code to assign given values to instance variables
}
Class Atom should also have the following methods:
int getatomicMass ()- returns total number of protons plus neutrons
int getAtomicCharge ()- returnsthe difference between the number of protons and electrons
void decay ()- decreases the number of protons by 2 and the number of neutrons by 2
In addition to the Atom class, there is a class AtomTest with a main method that will execute when you click the Run button in "Develop mode". The given main method does very little, but you can edit this main method however you wish to try things out, it will not be graded. Note that it won't compile until you have provided the specified constructor.
Note that the editing window has a dropdown menu to switch between the two files Atom.java and AtomTest.java. The code for the class Atom MUST go in the file Atom.java.
When in "Submit mode", the auto-grader will run a number of unit tests. The first one just checks that you have all the declarations right and have not added anything like a public variable that violates the specified public API. Read the error messages starting at the top and be sure you pass this first test before worrying about the rest.
For this exercise, you can resubmit as many times as you want. Only the Atom class is tested and graded when you submit.
 3.5 Defining your own class (Atom) Your task is write a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!