/* Workshop 3 Molecule - Atom */ package molecule; import java.util.Scanner; public class Atom { int number; String symbol, fullName; float weight; public boolean accept(int numberX, String symbolX, String fullNameX, float weightX) { if (numberX == 0) { return false; } else { number = numberX; symbol = symbolX; fullName = fullNameX; weight = weightX; return true; } } public void display() { System.out.printf("%-5d %-5s %-10s %f\n", number, symbol, fullName, weight); // System.out.println(number + " - " + symbol + " - " + fullName + " - " + weight); } public class Molecule { String structure, name, symbol; float weight; int number, count = 0; boolean check = true; Scanner input = new Scanner(System.in); Atom[] atom = new Atom[10]; public void constructor() { do { atom[count] = new Atom(); System.out.print("Enter atomic number : "); number = input.nextInt(); input.nextLine(); if (number == 0) { break; } System.out.print("Enter symbol : "); symbol = input.nextLine(); System.out.print("Enter full name : "); name = input.nextLine(); System.out.print("Enter atomic weight : "); weight = input.nextFloat(); System.out.println(""); check = atom[count].accept(number, symbol, name, weight); count++; } while (check == true && count < 10); } public void display() { for (int i = 0; i < count; i++) { atom[i].display(); } } public static void main(String[] args) { Molecule molecule = new Molecule(); System.out.println("Atomic Information"); System.out.println("=================="); molecule.constructor(); molecule.display(); } }