Problem 169
Getting Data from a File
Make a class to store information about a dog. It should contain fields for:
- a breed, which is a String,
- an age, which is an integer, and
- a weight, which is a double
Using Notepad or the text editor of your choice, create a text file containing the data above for two dogs. Save this file in same directory as this program.
- Create two Dog objects (not in an array).
- Ask the user for the name of a file to open, and open that file and read in attributes.
- Display the values you read in.
Which file to open: dogs.txt Reading data from dogs.txt First dog: Yorkie, 4, 14 Second dog: Great_Dane, 7, 93
For reference
Here is a repl.it for how to read in information from a file.
◄ 168: A Little Database is Shorter with a Loop 170: Getting More Data from a File ►
Adapted from ProgrammingByDoing.com
©2013 Graham Mitchell
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.