Code:
import java.text.DecimalFormat;
import java.util.Random;
/**
* Class for generation of random ISBN
*/
public class RandomISBN
{
// private attributes containing the different parts of the isbn
private String prefix;
private String group;
private String publisher;
private String book;
private int checksum;
public static void main (String[] args)
{
String x;
int zaehler;
for (zaehler = 1; zaehler <= 3;)
{
x = RandomISBN();
System.out.println (x);
}
}
// constructor ------------------------------------------------
public RandomISBN()
{
this.makeISBN();
}
// public methods ---------------------------------------------
public String toString()
{
return prefix + "-" + group + "-" + publisher + "-" +
book + "-" + checksum;
}
// private methods --------------------------------------------
/**
* Creates a new random isbn.
*/
private void makeISBN()
{
// generate Random - Objects and Format - Objects:-----
Random generator = new Random ();
DecimalFormat formatedPrefix = new DecimalFormat ("000");
DecimalFormat formatedGroup = new DecimalFormat ("000");
DecimalFormat formatedPublisher = new DecimalFormat ("00");
DecimalFormat formatedBook = new DecimalFormat ("0000");
// generate and format random Numbers:------------------
prefix = formatedPrefix.format (generator.nextInt (2) +978);
group = formatedGroup.format (generator.nextInt (999) +1);
publisher = formatedPublisher.format (generator.nextInt (99) +1);
book = formatedBook.format (generator.nextInt (9900) +100);
// generate Checknumber - Algorithm:--------------------
char z01, z02, z03, z04, z05, z06, z07, z08, z09, z10, z11, z12;
z01 = prefix.charAt (0);
z02 = prefix.charAt (1);
z03 = prefix.charAt (2);
z04 = group.charAt (0);
z05 = group.charAt (1);
z06 = group.charAt (2);
z07 = publisher.charAt (0);
z08 = publisher.charAt (1);
z09 = book.charAt (0);
z10 = book.charAt (1);
z11 = book.charAt (2);
z12 = book.charAt (3);
checksum = (10-(z01+z03+z05+z07+z09+z11+3*(z02+z04+z06+z08+z10+z12))%10)%10;
}
}
Das ganze ist eine Übungsaufgabe aus der Uni. (erlerne gerade Java, 3.Woche). Mein Problem ist nun, dass ich nicht genau weiss, wie ich von der main-Methode aus auf die RandomISBN() und die toString() Methode zugreiffen kann. Als Fehlermeldung bringt mir hier der Compiler nur:
RandomISBN.java:32: cannot find symbol
symbol: method RandomISBN()
location:class RandomISBN
x = RandomISBN();
1 error
Vielen Dank für die Hilfe (ps: bin neu in diesem Forum; also bitte einfach mitteilen, falls ich was nicht nach Regel mache!! =) thx)