computer science area (2 Viewers)

Loppan

Senior Member
Jul 13, 2002
2,528
It's me again with a problem :D

Here's a bit of code. The problem that I have is that it doesn't print out the books of a certain writer.

public void findWriter(String w) {

Collator co = Collator.getInstance();
co.setStrength(Collator.PRIMARY);
System.out.println("Books that" + w + " written:");
for (int i = 0; i < antal; i++) {
if (co.compare(reg.findWriter(),w) == 0) {
System.out.println(reg);
}
}


antal are the number of books in the array. reg is the array.
 

Martin

Senior Member
Dec 31, 2000
56,812
Well assuming the method findWriter() returns the correct string, I see no reason why this should not work. The only concern that comes to mind is you want to eliminate any possible whitespaces that could have been stored inadvertently. You could accomplish that by running trim() on each of the strings before they are compared, ie..

if (co.compare(reg.findWriter().trim(),w.trim()) == 0) {
System.out.println(reg);
}
 

Loppan

Senior Member
Jul 13, 2002
2,528
++ [ originally posted by Loppan ] ++
It's me again with a problem :D

Here's a bit of code. The problem that I have is that it doesn't print out the books of a certain writer.

public void findWriter(String w) {

Collator co = Collator.getInstance();
co.setStrength(Collator.PRIMARY);
System.out.println("Books that" + w + " written:");
for (int i = 0; i < antal; i++) {
if (co.compare(reg.returnWriter(),w) == 0) {
System.out.println(reg);
}
}


antal are the number of books in the array. reg is the array.




public String returnWriter() {
return writer;
}
 

Loppan

Senior Member
Jul 13, 2002
2,528
I used the skip.Line() wrong in the main class.

Here's another problem:

C:\Program\Xinox Software\JCreator LE\MyProjects\cd5450\Lab5\BokProjekt\Projektuppgift\Bokhylla.java:114: cannot resolve symbol
symbol : method taBortBok (Bok)
location: class Bokregister
r.remove(b1);


Class Bok:

public void removeBok(Bok b) {
b = null;
}


Main:

{
System.out.print("What bok? Number xxxx-xxxxx: ");
Std.in.skipLine();
String isbn=Std.in.readLine();
Bok b1=r.findIsbn(isbn);
System.out.print("Remove" +b1);
svar=(char)Std.in.readChar();
if (svar=='j') {
r.remove(b1);
}
 

Martin

Senior Member
Dec 31, 2000
56,812
++ [ originally posted by Loppan ] ++
C:\Program\Xinox Software\JCreator LE\MyProjects\cd5450\Lab5\BokProjekt\Projektuppgift\Bokhylla.java:114: cannot resolve symbol
symbol : method taBortBok (Bok)
location: class Bokregister
I don't see any method called taBortBok in your code.
 

Loppan

Senior Member
Jul 13, 2002
2,528
I was tired when I was doing that one :embarass:

Here is another problem. I want to find a number. I have declared it as a String. I have for ex. this number 1887-87897. I don't know how to find it. I have done this method but it's probably wrong.

public Bok findNumber(String n) {

Collator co = Collator.getInstance();
co.setStrength(Collator.PRIMARY);

for (int i=0;i<antal;i++) {
if (co.compare(reg.readNumber(),n) == 0) {
System.out.println(reg);
return reg;
}
}
return null;
}
 

Anders

Senior Member
Dec 13, 2002
3,134
Hi nerds! ;) :D

I've got a little problem... please help me!

I need a search form that can search in a txt file...

If you don't know what the hell I'm talking about, let me know and I'll go in to details. ;)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 2)