473,698 Members | 2,888 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help inputting data from file into array

1 New Member
Basically, the project I'm working on this week is to make a school lunch menu with a GUI, when the person types in a day, the menu for that day shows up. We have two files, ones a day off text file which just has the days off in it, and the other is a lunch menu file, which each line being an entry. Each day inside that lunch menu file ends with the word Milk. I've been trying to get the days off from the file and store it into an array of int, but every time i System.out.prin t the array.... it gives me gibberish. Can you guys help me with this (and any other issues you see in the program). I'd greatly appreciate it because I've been looking at this for awhile and am really stuck.

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.util.Scanner;
  3. import java.util.ArrayList;
  4.  
  5. public class SchoolLunch implements StringLogInterface{
  6.     private int[] indexArray = new int[31];
  7.     private static Scanner input;
  8.     private static PrintWriter output;
  9.  
  10.     private void getDaysOff(){
  11.         int line = 0;
  12.         try{
  13.             FileReader reader1 = new FileReader("days_off.dat");
  14.             input = new Scanner(reader1);
  15.  
  16.             while(input.hasNextInt()){
  17.                 line = input.nextInt();
  18.                 System.out.println(indexArray);
  19.             }    
  20.             indexArray[line]++;
  21.  
  22.         }catch(FileNotFoundException e){
  23.                 System.out.print("The file could not be found.");
  24.                 e.printStackTrace();
  25.             }
  26.  
  27.         }
  28.  
  29.     private void buildMenu(){
  30.         int menuentry = 1;
  31.         String names = "a";
  32.         try{
  33.             FileReader reader2 = new FileReader("lunches.dat");
  34.             input = new Scanner(reader2);
  35.             ArrayStringLog log1 = new ArrayStringLog("Day" + " " + menuentry);
  36.  
  37.  
  38.             while(input.hasNext() && !names.contains("Milk")){
  39.                 names = input.nextLine();
  40.                 log1.insert(names);
  41.                 log1.isFull();
  42.                 log1.size();
  43.                 menuentry++;
  44.                 log1.getName();
  45.                 log1.toString();
  46.  
  47.             }
  48.             System.out.print(log1);
  49.         }catch(FileNotFoundException e){
  50.                 System.out.print("The file could not be found.");
  51.                 e.printStackTrace();
  52.             }
  53.     }    
  54.  
  55.  
  56.     private boolean isDayOff(int n){
  57.         int line2 = 0;
  58.  
  59.         try{
  60.             FileReader reader1 = new FileReader("days_off.txt");
  61.             input = new Scanner(reader1);
  62.  
  63.             while(input.hasNext()){
  64.                 line2 = input.nextInt();
  65.             }    
  66.         }catch(FileNotFoundException e){
  67.                 System.out.print("The file could not be found.");
  68.                 e.printStackTrace();
  69.             }
  70.         if(line2 == n)
  71.             return true;
  72.             else
  73.                 return false;
  74.     }
  75.  
  76.     private void getMenu(int k){
  77.         indexArray[k]++;
  78.     }
  79.  
  80.     public static void main(String[] args) {
  81.         SchoolLunch sl = new SchoolLunch();
  82.         sl.getDaysOff();
  83.  
  84.  
  85.  
  86.     }
  87.  
  88. }
From just trying to run the getDaysOff method, this is what i get in the console...

[I@fd13b5
[I@fd13b5
[I@fd13b5
[I@fd13b5
[I@fd13b5
[I@fd13b5
[I@fd13b5
[I@fd13b5
[I@fd13b5
[I@fd13b5
[I@fd13b5
Feb 3 '08 #1
1 2218
BigDaddyLH
1,216 Recognized Expert Top Contributor
That's what you get when you try to directly write an array object. Specifically, that is what the toString method of arrays return. Demo:
Expand|Select|Wrap|Line Numbers
  1. import java.util.Arrays;
  2.  
  3. public class ArrayExample {
  4.     public static void main(String[] args) {
  5.         int[] v = {10,20,30,40,50,60};
  6.  
  7.         System.out.println("#1 " + v);
  8.  
  9.         System.out.println("#2 " + Arrays.toString(v));
  10.  
  11.         System.out.print("#3");
  12.         for(int i=0; i<v.length; ++i) {
  13.             System.out.print(" " + v[i]);
  14.         }
  15.         System.out.println();
  16.     }
  17. }
Feb 4 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3053
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers to have an easier time understanding what I do. Therefore this weekend I'm going to spend 3 days just writing comments. Before I do it, I thought I'd ask other programmers what information they find useful. Below is a typical class I've...
9
2123
by: Nathan Rose | last post by:
Here's my problem. I am reading from a text file using this: if (!file_exists($file)) { echo "Don't exist\n"; return false; } $fd = @fopen($file, 'r'); if (!is_resource($fd))
8
4024
by: Kruton | last post by:
What is the easiest way to take a string from a console while including whitespaces? This program's user will input a line of text that will consist of multiple tokens, but the number tokens and the length of each line will vary at each use. Is there a way to get scanf to take a string that contains whitespace? Or is there another function that would work? -Thank you
2
2382
by: saltedcoffee | last post by:
hey, I am beginer to C++ programing. I am working on a project called the "maze Problem" First of all I am required to read a text file in( which is the maze) and store it into a 2 dimentional vector. This is what I have till now: #include <iostream> #include "maze.h" #include <vector> #include <fstream>
5
2720
by: Chris | last post by:
I have a meetings section I'm developing on our intranet. Using PHP/MySQL. Meeting info and Meeting docs reside on 2 related tables in the db. Users may want to upload anywhere from 1 to 10 or more documents to share/use during a meeting presentation. What would be the most efficient way to approach this? This is the logic I'm currently considering: Page 1: Meeting Information input with link to a document upload page (this page...
8
2744
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only the sequence nos and it should be such that i can access it through the structure .plz help me .
1
2543
by: Ramper | last post by:
Have a .txt document as: String int int int int int int int
2
1725
by: UofFprogrammer | last post by:
Hello, Several Weeks ago I asked a question about testing for the end of an input file. I have been using this method pretty well for inputting information from an external file. I am using C++. char line; while(file>>line){ Where line is a c-string and file is an input stream. But this only reads until the first space it encounters. I now want to try to take in an entire line, regardless of what it contains (such as whitespace) as a...
5
1658
by: tim123 | last post by:
Hey. I'm having some issues reading in data from a tab delimited text file. I only want to input numbers, and ideally I'd like it to be able to cope with a line or 2 of text at the top in case someone leaves the file headings on when exporting the data from the spreadsheet. My code is dim data(,) as double dim lines, i as integer dim s as string fileopen(1,"c:\mydatafile.txt", openmode.input)
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8611
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8876
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7741
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4624
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.