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. - import java.io.*;
-
import java.util.Scanner;
-
import java.util.ArrayList;
-
-
public class SchoolLunch implements StringLogInterface{
-
private int[] indexArray = new int[31];
-
private static Scanner input;
-
private static PrintWriter output;
-
-
private void getDaysOff(){
-
int line = 0;
-
try{
-
FileReader reader1 = new FileReader("days_off.dat");
-
input = new Scanner(reader1);
-
-
while(input.hasNextInt()){
-
line = input.nextInt();
-
System.out.println(indexArray);
-
}
-
indexArray[line]++;
-
-
}catch(FileNotFoundException e){
-
System.out.print("The file could not be found.");
-
e.printStackTrace();
-
}
-
-
}
-
-
private void buildMenu(){
-
int menuentry = 1;
-
String names = "a";
-
try{
-
FileReader reader2 = new FileReader("lunches.dat");
-
input = new Scanner(reader2);
-
ArrayStringLog log1 = new ArrayStringLog("Day" + " " + menuentry);
-
-
-
while(input.hasNext() && !names.contains("Milk")){
-
names = input.nextLine();
-
log1.insert(names);
-
log1.isFull();
-
log1.size();
-
menuentry++;
-
log1.getName();
-
log1.toString();
-
-
}
-
System.out.print(log1);
-
}catch(FileNotFoundException e){
-
System.out.print("The file could not be found.");
-
e.printStackTrace();
-
}
-
}
-
-
-
private boolean isDayOff(int n){
-
int line2 = 0;
-
-
try{
-
FileReader reader1 = new FileReader("days_off.txt");
-
input = new Scanner(reader1);
-
-
while(input.hasNext()){
-
line2 = input.nextInt();
-
}
-
}catch(FileNotFoundException e){
-
System.out.print("The file could not be found.");
-
e.printStackTrace();
-
}
-
if(line2 == n)
-
return true;
-
else
-
return false;
-
}
-
-
private void getMenu(int k){
-
indexArray[k]++;
-
}
-
-
public static void main(String[] args) {
-
SchoolLunch sl = new SchoolLunch();
-
sl.getDaysOff();
-
-
-
-
}
-
-
}
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
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: - import java.util.Arrays;
-
-
public class ArrayExample {
-
public static void main(String[] args) {
-
int[] v = {10,20,30,40,50,60};
-
-
System.out.println("#1 " + v);
-
-
System.out.println("#2 " + Arrays.toString(v));
-
-
System.out.print("#3");
-
for(int i=0; i<v.length; ++i) {
-
System.out.print(" " + v[i]);
-
}
-
System.out.println();
-
}
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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))
|
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
|
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>
|
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...
| |
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 .
|
by: Ramper |
last post by:
Have a .txt document as:
String
int
int
int
int
int
int
int
|
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...
|
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)
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |