We were instructed to make a program where the user will input the Planets' name and mass then the data will be shown in a list (optional:the list should be in alphabetical order). We need to make some sort of menu where it displays 3 choices: Add Planet and Mass, View Record, and exit. I got a help from a friend with some parts except the part when displaying the data. it only says "null". it should look like:
Planets and Their Masses:
Earth 1234
Jupiter 12345
Mars 1234
here's the code that needs editing...I've been searching on how to solve this and can't seem to find the solution, and I need to submit this 5 hours from now.
import java.io.*; import java.util.Arrays; public class Planets { int a=0; int b=0; String[] planet = new String[8]; double[] mass = new double[8]; public static void main(String[]args)throws Exception { int choice; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); do { System.out.println("[1] Add Planet/Mass"); System.out.println("[2] View Records"); System.out.println("[3] Exit"); System.out.print("Select your choice: "); choice = Integer.parseInt(br.readLine()); if (choice==1) { System.out.println("\n\n"); Planets i = new Planets(); i.Input(); } if (choice==2) { System.out.println("\n"); Planets v = new Planets(); v.View(); } } while (choice!=3); System.out.println("Thank You!"); } public void Input()throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter planet name: "); planet[0] = br.readLine(); System.out.println("Enter mass: "); mass[0] = Double.parseDouble(br.readLine()); } void View() { System.out.println("Planets and their Masses: "); System.out.println("" +planet[0] +mass[0]); } }