In: Computer Science
*Java*
Write an application that declares an array of three Listings whose contents are input by the user (User inputs name and age for each listing). After the input, the listings should output in reverse order.
import java.util.Scanner; public class Listing { private String name; private int age; public Listing() { name = " "; age = 0; } public Listing(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "name='" + name + '\'' + ", age=" + age; } public void input() { Scanner in = new Scanner(System.in); System.out.print("Enter name: "); name = in.nextLine(); System.out.print("Enter age: "); age = Integer.parseInt(in.nextLine()); } } class ListingTest { public static void main(String[] args) { Listing[] listings = new Listing[3]; for (int i = 0; i < listings.length; i++) { listings[i] = new Listing(); listings[i].input(); } for (int i = listings.length-1; i >= 0; i--) { System.out.println(listings[i]); } } }