I am working on a basic classified ad system that when used prompts the user with several questions. The user input answering those questions is then printed out when the user enters a show command. I am trying to figure out a way to store the previous input while still saving future input so that when the user calls the method to "show" all the ads, all the ads print out. Here is the code I have for creating the ad:
/**
*
*/
private String addItem()
{
Scanner scanRead = new Scanner(System.in);
System.out.println("What is your username?");
username = scanRead.nextLine();
System.out.println("What is the title of the ad you are posting?");
title = scanRead.nextLine();
System.out.println("Type your description here: ");
description = scanRead.nextLine();
System.out.println("How much are you asking for the item?");
price = scanRead.nextLine();
ad = username + title + description + price;
return null;
}
Then I just have a simple print method to display the ads:
/**
* Display the details of this post.
*
*/
public void display()
{
System.out.println(ad);
}