|
Learning objectives:After completing this project, you should be able to:
Items in red are learning objectives for this part of the project. |
Group work
| DefiningYourOwnClasses report
| Time limit
|
DefiningYourOwnClasses project and report. JOptionPane for all required input and output (I/O) in this project (you are free to use whatever method you prefer for other I/O).setReal and setImaginary assign values to the real and imaginary fields, replace the assignments with invocations of the setReal and setImaginary mutators.public is a bad idea, but we're going to do it anyway for now):
public double magnitude = 0.0;
public double argument = 0.0;
setReal, setImaginary, setMagnitude, and setArgument) so that they also assign the appropriate values to the new fields. Do not invoke the accessors (getReal, getImaginary, getMagnitude, and getArgument). Hint: consider reusing some of the code in getMagnitude and getArgument.getMagnitude and getArgument methods so that they return the values of the appropriate fields. getMagnitude and getArgument methods so that they return the values of the appropriate fields have on the behavior of the program? Describe the tests that you performed to verify that the program behaves as expected. main method:
Complex part3 = new Complex();
part3.setReal( 3.0 );
part3.setImaginary( 4.0 );
System.out.println(
"The complex number " + part3.getReal() + " + " + part3.getImaginary() + "i \n" +
"has magnitude " + part3.getMagnitude() + " and argument " + part3.getArgument() + "."
);
part3.magnitude = -1.0;
part3.argument = Math.PI * 2.0;
System.out.println(
"But thanks to public access, we can make it look like \n" +
"the complex number " + part3.getReal() + " + " + part3.getImaginary() + "i \n" +
"has magnitude " + part3.getMagnitude() + " and argument " + part3.getArgument() + "."
);
magnitude and argument fields public visibility was a bad idea. magnitude and argument fields to private.Complex class to tell which fields exist within the class? Can they tell how the methods are implemented? This is called information hiding, and we say that the Complex class encapsulates the implementation details.
DefiningYourOwnClasses3.