Claire Saunders

Greenhorn
+ Follow
since Sep 29, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Claire Saunders

Hi all,

My current assignment is to modify a previous assignment for reading and partially solving Sudokus. We're supposed to move the display function of the original file into a new class, SudokuConsoleObserver, and implement the Observer design pattern in order to solve it (among other things I haven't gotten to yet...)

I've created SudokuObservable, ObserverApplication, and SudokuConsoleObserver, and SudokuObservable requires a notifyObservers method. The problem is, this method can't be static, and I'm not allowed to reference it in a static method... so if I try to call notifyObservers in the method I want, I get the error "Cannot make a static reference to the non-static method notifyObservers() from the type SudokuObservable." I also tried calling notifyObservers from ObserverApplication and got the same error. If I change notifyObservers to static, I get the message "This static method cannot hide the instance method from Observable."

How do I fix this? I can't add static and I can't take a static away. I suspect that I'm just misunderstanding something important about implementing Observer, since I've never done that before.

Thank you so much for your help!

Relevant code:

14 years ago
So having successfully fixed the mystery error of my last thread, I must move on to the new challenge of getting the code to run like it should.

The desired output for this project is a table of wins and losses, so it should read something like:

unc: 2 0
usc: 0 2
uva: 1 1

Instead, my output is


null: 0 0
null: 0 0
null: 0 0
null: 0 0
null: 0 0
null: 0 0
null: 0 0
null: 0 0
null: 0 0
null: 0 0
null: 0 0
null: 0 0



So I know it's looping the correct number of times, however, somehow the information isn't getting inputted correctly. Since this is my first project with scanners, it is most likely something in the two scanners I'm using. I'm not getting any error messages anymore though. Any help would be greatly appreciated!

My complete code:


And the other class
14 years ago

Rahul.p Kumar wrote:put the files in class path location and see whether it works?


=D That worked! At last!

Of course now I have to deal with all the other errors that I haven't noticed 'til now. Such is life. :P
14 years ago

Ulf Dittmer wrote:Check the permissions on the file - FileNotFoundException is also thrown if the application doesn't have access rights to a file.


I've tried swapping the files, just to check-- AccInfo.txt gives me no error messages in the second scanner, and Week1.txt gives the same error message in the first. So I do have access rights to it. Thanks for the suggestion, though!


EDIT-- I realized why the second file wasn't giving me any error messages. I had no "readWeekInfo()" under main. Now both give me the error message.

So how do I check if I have access rights to the file?
14 years ago
Hello all!

I'm in a programming class and we're writing our first program with scanners. I'm using two different text files. Unfortunately, only one of them works-- the other is consistently giving me this error message:

Exception in thread "main" java.io.FileNotFoundException: AccInfo.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at comp401pkg.AnalyzeAccFootball.readTeamInfo(AnalyzeAccFootball.java:18)
at comp401pkg.AnalyzeAccFootball.main(AnalyzeAccFootball.java:12)

The file is saved in the same location as the java and the working text file, though, so it should work fine. Or so I thought. Any suggestions as to what could be wrong would be greatly appreciated!

Full code, in case you need it:
package comp401pkg;
import static java.lang.System.out;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class AnalyzeAccFootball {
private static AccFootballTeam[] team = new AccFootballTeam[12];

public static void main(String[] args) throws FileNotFoundException {
readTeamInfo();
printTeams();
}


public static void readTeamInfo() throws FileNotFoundException {
Scanner input = new Scanner(new File("AccInfo.txt"));
for (int i = 0; i < 12; i++) {
String line = input.nextLine();
String[] word = line.split(";");
team[i] = new AccFootballTeam(word[0], word[1], word[2] );
}
}


public static void readWeekInfo() throws FileNotFoundException {
Scanner input = new Scanner(new File("Week1.txt"));
for (int i = 0; i < 12; i++) {
String line = input.nextLine();
String[] word = line.split(";");
for (int k = 0; k < 12; k++) {
if (team[k].abbreviation==word[1]) {
team[k].score = word[2];
team[k].opponentScore = word[3];
}
else
if (team[k].abbreviation==word[4]) {
team[k].score = word[3];
team[k].opponentScore = word[2];
}
}
}
}


public static void printTeams() {
for( int i = 0; i < 12; i++ ) {
out.println(team[i].toString() );
}
}
}
14 years ago