Multiple Inputs and Writing to .txt

Click For Summary

Discussion Overview

The discussion revolves around designing a Java program that collects user input regarding property sales, including IDs and prices, and writes this information to text files. Participants explore how to handle multiple inputs, implement exception handling, and structure the program's flow.

Discussion Character

  • Technical explanation
  • Homework-related
  • Exploratory

Main Points Raised

  • One participant outlines the need to collect a person's ID, house ID, listing price, and selling price, and write this data to a file named Sales.txt.
  • Another participant questions the programming specifications and asks about the language and operating system being used.
  • A participant emphasizes the importance of understanding how to implement the design, particularly regarding multiple inputs and writing to text files simultaneously.
  • Some participants suggest starting with a simple algorithm to gather user input sequentially rather than worrying about multiple lines of input at once.
  • There are suggestions to break down the overall task into smaller, manageable tasks to facilitate the programming process.
  • One participant proposes creating a sample dialog to illustrate how the program should interact with the user, indicating where loops might be necessary.

Areas of Agreement / Disagreement

Participants generally agree on the need to structure the program and break down tasks, but there is no consensus on the specific implementation details or how to handle multiple inputs effectively.

Contextual Notes

Some participants note that exception handling may not be necessary at the initial stages of development, suggesting a focus on basic input and output operations first. There is also uncertainty about the exact requirements for user input formats and how to manage them.

Euler2718
Messages
90
Reaction score
3
Essentially, my problem is to: design a program that takes the following information:

-a persons ID
-a houses ID
-listing price of house
-selling price of house

and write the input to a text file, called Sales.txt. Secondly, based on the list and selling price, commission is calculated based on some conditions. After everything has been entered, the persons ID, the houses ID, and the final commission price has to be written to another text file called Commissions.txt; this info on Commissions.txt also has to be printed to the screen.

I also need to include exception handling for if the user inputs an invalid form. Let's assume the input form is that of: PPPPP HHHH LLLLLL SSSSSS
of course the prices wouldn't really need to be concerned as the prices could theoretically be anything, but the two id's would need a particular form.

So my problem is I haven't a clue how to start. I've learned the basics of being able to read a text file and write in the editor to the file, but how do I go about having a user input multiple lines of text and have that then written to the .txt files in question? I'm guessing there would be a while loop in there. My biggest concern is not knowing how to deal with the multiple inputs and writing to the text files.

Any insight would be great.
 
Technology news on Phys.org
1. you have to design the specifications, then write code?
2. if so what language & OS are you running?
 
jim mcnamara said:
1. you have to design the specifications, then write code?
2. if so what language & OS are you running?

With all due respect, did you read my description fully? I'm not sure on how to implement my design, with regards to the multiple inputs and writing to the text file simultaneously. The language is given in the tag - java. I'm running linux mint 17.2.
 
Morgan Chafe said:
Essentially, my problem is to: design a program that takes the following information:

-a persons ID
-a houses ID
-listing price of house
-selling price of house

and write the input to a text file, called Sales.txt. Secondly, based on the list and selling price, commission is calculated based on some conditions. After everything has been entered, the persons ID, the houses ID, and the final commission price has to be written to another text file called Commissions.txt; this info on Commissions.txt also has to be printed to the screen.

I also need to include exception handling for if the user inputs an invalid form. Let's assume the input form is that of: PPPPP HHHH LLLLLL SSSSSS
of course the prices wouldn't really need to be concerned as the prices could theoretically be anything, but the two id's would need a particular form.

So my problem is I haven't a clue how to start. I've learned the basics of being able to read a text file and write in the editor to the file
What does "write in the editor to the file" mean?
Do you know how to open a file and read from it using Java? The process is similar if you want to write to a file.
Morgan Chafe said:
, but how do I go about having a user input multiple lines of text and have that then written to the .txt files in question? I'm guessing there would be a while loop in there.
Don't get caught up in implementation details, yet. First, make a list of the things you need to do, to get an idea of your overall algorithm. I wouldn't even put in exception handling at this point -- just get your input operations working, and the output to the commssions file and the screen.

You don't need to input multiple lines of text -- just input one piece of information at a time.

Your algorithm should start out something like this:
  • Prompt user for ID
  • Input user ID
  • Prompt user for house ID
  • Input house ID
  • etc.
You will probably need a loop of some kind when you build in the exception handling, but at this point, you don't.
Morgan Chafe said:
My biggest concern is not knowing how to deal with the multiple inputs and writing to the text files.

Any insight would be great.
 
  • Like
Likes   Reactions: Euler2718
Think about the flow of your program, all of the tasks that it needs to do. The first step to writing a program is usually taking paper and pencil (actually, it's usually a whiteboard and markers) and separating the large task into several smaller, more manageable tasks. A quick whiteboard diagram of what you described:

Screen Shot 2016-03-23 at 9.57.18 AM.png
 
More concretely, assuming this program is supposed to communicate with the user via plain text at a command line, I would write out a sample "dialog" between the program and the user:

Please enter the following information:
Person's ID: 12345
House ID: 67890
[etc.]

Decide on some way for the program to ask the user whether he wants to continue entering data, or stop. Show a few complete "cycles" of data entry. Then write your code such as to reproduce this dialog. A sequence of dialog that repeats, indicates the location of a loop in the program.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 15 ·
Replies
15
Views
3K
Replies
3
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 8 ·
Replies
8
Views
9K
  • · Replies 3 ·
Replies
3
Views
2K