Multiple Inputs and Writing to .txt

In summary, the program needs to prompt for an ID, then a house ID, then a selling price, and finally, a commission amount. It should keep track of which data is being entered, and print the data to the screen once it's all been entered.
  • #1
Euler2718
90
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
  • #2
1. you have to design the specifications, then write code?
2. if so what language & OS are you running?
 
  • #3
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.
 
  • #4
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 Euler2718
  • #5
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
 
  • #6
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.
 

FAQ: Multiple Inputs and Writing to .txt

What is the purpose of using multiple inputs when writing to a .txt file?

The purpose of using multiple inputs when writing to a .txt file is to allow for a more efficient and organized way of storing data. By using multiple inputs, different types of data can be stored in a single file, making it easier to retrieve and analyze the information.

What types of data can be written to a .txt file using multiple inputs?

Multiple inputs can be used to write various types of data to a .txt file, including text, numbers, and symbols. This allows for the storage of different types of information, such as words, numbers, and special characters, all in one file.

How can multiple inputs be implemented when writing to a .txt file?

Multiple inputs can be implemented by using programming languages such as Python or Java, which have built-in functions for writing to .txt files. These functions allow for the creation of multiple input fields, which can then be used to store different types of data in a single file.

What are the advantages of using multiple inputs when writing to a .txt file?

There are several advantages to using multiple inputs when writing to a .txt file. These include improved organization and efficiency, as well as the ability to store different types of data in a single file. Additionally, multiple inputs allow for easier retrieval and analysis of data.

Are there any limitations to using multiple inputs when writing to a .txt file?

One limitation of using multiple inputs when writing to a .txt file is that the data may become disorganized if not properly structured. Additionally, there may be compatibility issues with certain programming languages or software when trying to read or write to a .txt file with multiple inputs. It is important to carefully plan and structure the data when using multiple inputs to avoid these limitations.

Similar threads

Replies
1
Views
1K
Replies
15
Views
2K
Replies
4
Views
2K
Replies
2
Views
3K
Replies
7
Views
2K
Replies
2
Views
5K
Replies
8
Views
8K
Replies
1
Views
2K
Back
Top