/** * Author: Josiah Yoder et al. * User: yoder * Class: SE1011-051 * Lesson: Week 8, Day 1 */ import java.text.DecimalFormat; import java.util.Scanner; public class Example051_8_2 { /* * This is a scratch-paper method */ public static void main(String[] ignored) { // In-class exercise Complex051_8_2 c1 = new Complex051_8_2(3,4); Complex051_8_2 c2 = new Complex051_8_2(1,2); // Complex051_8_2 c5 = add(c1, c2); // Not the "object oriented" way c1 = c1.add(c2); // a // "Point a" // We discussed Garbage Collection at this point. Complex051_8_2 c3 = new Complex051_8_2(5); Complex051_8_2 c4 = new Complex051_8_2(c1); // Decimal Formatter // Use "0" to print a number at this place, even if it is zero. // Use "#" to print a number at this place, except print nothing if it is zero. // The number of #'s before the decimal place doesn't really make a difference. You can't do // fixed-width formatting to make sure the output always has the same length, as far as // I can tell. DecimalFormat myFormat = new DecimalFormat("$#############.00"); Scanner in = new Scanner(System.in); System.out.println("Enter a number"); double input = in.nextDouble(); System.out.println("The number you entered is: " + myFormat.format(input)); // Simplifying long methods with helper methods // See Lab7_051_8_2.java } }