• Post Reply Bookmark Topic Watch Topic
  • New Topic

Netbeans reading from a file.  RSS feed

 
Clemz Chins
Greenhorn
Posts: 10
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I got an assignment which goes something like this:

You must develop a program. that reads the file icecream.dat. This file is supplied. You must use TextIO methods to read the file. As you read the file, count the total number of ice cream cones that were sold. (This is the same as the number of lines that you read from the file.) Also count the total number of "Strawberry" cones that were sold.

At the end of the program, print out the total number of cones, the number of Strawberry cones, and the percentage of cones that were Strawberry.

Note: To do this program, you have to know when to stop reading from the file. TextIO has a function named TextIO.eof() to check whether the entire file has been read. The value of this function is true if the entire file has been read. The value is false if there is more data in the file. You want to continue reading from the file as long as TextIO.eof() is false.

Note: Suppose that flavor is a variable of type String and you want to test whether its value is "Strawberry". To do this, test whether flavor.equals("Strawberry"). (Do not use == to test for equality of Strings.)

Each line of the file icecream.dat is an ice cream flavor such as "Vanilla" or "Strawberry." A line represents the sale of one ice cream cone of the given flavor.

Now, I have written code which looks like this in Netbeans but it will not build, I am wondering if I did something wrong:



If you would go through it and pinpoint at some of the things I have done incorrectly, I would be delighted. I did not pay attention to the TextIO instruction as it is the creation of an author who wrote the book that we are reading and am having a torrid time wrapping my mind around it. Instead I have used Scanner.

Thanks a lot.

 
Carey Brown
Saloon Keeper
Posts: 3323
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start by pairing up your open/close braces.
 
Carey Brown
Saloon Keeper
Posts: 3323
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not using TextIO. The TextIO library is not a part of Java. Where are you supposed to get it from and where is the documentation?
 
Clemz Chins
Greenhorn
Posts: 10
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The TextIO part was provided by the instructor. I added to the project file previously when I was trying to use it. Thanks for your assistance.
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TextIO is one of the programs that come with this course/book:

http://math.hws.edu/javanotes/

That course really helped me very much into Java, years ago, so I can recommend it.
 
Junilu Lacar
Sheriff
Posts: 11493
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the brace on line 17.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!