Question: Write a program that reads data about the atomic elements and then displays the information when the user enters the atomic number of the element.
elements.txt: 89 Actinium 227 Write a program that reads data about the atomic elements and then displays the information when the user enters the atomic number of the element. The file elements.txt contains the following information on each line for each of the 118 elements: Atomic number Name Atomic weight All elements are numbered from 1 to 1 18 There are no missing numbers. The name of the element (i.e. Oxygen). The weight of an atom of this element. This number has a decimal point. arrays start their numbering There are 118 elements in the file numbered 1 to 118. Remember that at zero. The elements in the file are not in sequential order. Your program will want to read the file and make a simple Element object for each of the elements. The objects should be stored in an array using the atom ic number as the index of the array The Element class should have two class instance variables to hold the name and atomic weight You will need to a constructor to initialize these to values to constructor parameters. After reading the data from the file and creating the objects in the array, the program should ask the user for an atomic number. Using the number as an index into the array, the program should display the name and atomic weight of the element. Program outline while more data in the file read number, name and weight from the file create Element object with name and weight put object in the array indexed by the atomic number while requestedNu>0 read requestedNum from keyboard if requestedNum>0 atom Element object at index requestedNum display name and weight of atom Sample output Enter atomic number of element >8 Oxygen with atomic weight 15.999 Enter atomic number of element >82 Lead with atomic weight 207.2 Enter atomic number of element >116 Livermorium with atomic weight 293.0 Enter atomic number of element >0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
