Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA PLEASE AND THANKS :) (WITH COMMENTS IF POSSIBLE) 3.4 Defining your own class (Atom) Your task is write a class named Atom. The

IN JAVA PLEASE AND THANKS :) (WITH COMMENTS IF POSSIBLE)image text in transcribedimage text in transcribedimage text in transcribed

3.4 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 given Protons, 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() - returns the 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". (Use the dropdown list labeled to "Current file" at the top of the editing window to switch between files.) 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. 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. Current file: Atom Test.java Load default template... 1 public class Atom Test 2 { 3 public static void main(String[] args) 4 { 5 Atom a = new Atom(3, 4, 5); 6 System.out.println("Atomic mass: " + a.getAtomicMass()); 7 System.out.println("Expected: 7"); 8 System.out.println("Edit the AtomTest main method to try out your Atom class"); 9 } 10 } Current file: Atom.java Load default template... 1 2 /** 3 * Class that models an atom containing protons, neutrons, and electrons. 4 5 public class Atom 61 7 // instance variables 8 9 // constructor 10 11 // methods 12 13

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions