ZICK 发表于 2003-7-20 23:39

[求助]刚开始学,一头雾水...

麻烦各位帮忙给看看...

public class Konto
{
        private int betrag;
       
        public static void main(String args[])
        {
           konto sparbuch;
           sparbuch.einzahlen(100);
           sparbuch.abheben(30);
           sparbuch.einzahlen(60);
      System.out.println("Der Kontostand des Sparbuchs beträgt" + sparbuch.saldo() + "Euro");
        }
       
        public void abheben (int hoehe)
        {
      betrag = betrag - hoehe;
   }
   
   public int saldo()
   {
      return betrag;
   }
}

stl02 发表于 2003-7-21 07:01

不知道你哪里不明白?
这里是一个public class Konto,自带一个private int betrag;
还有三个内置public Methoden。我又加了一个。

第一个MAIN产生一个类型是Konto 的Sparbuch,然后是aufrufen另几个Methoden,最后ausgeben.


public class Konto
{
private int betrag;

public static void main(String args[])
{
konto sparbuch;
sparbuch.einzahlen(100);
sparbuch.abheben(30);
sparbuch.einzahlen(60);
System.out.println("Der Kontostand des Sparbuchs beträgt" + sparbuch.saldo() + "Euro");
}

public void abheben (int hoehe)
{
betrag = betrag - hoehe;
}

public void einzahlen (int hoehe)
{
betrag = betrag + hoehe;
}

public int saldo()
{
return betrag;
}
}

ZICK 发表于 2003-7-21 11:40

这是一个不完整的java程序
其中缺少一个Instantiierung,一个Konstruktor,及一个Methode
不明白这3个词的意思,及整个程序,因为是初学什么都不懂,而且明天考试,不知道你能不能推荐一些网上的资源,救命啊!

ZICK 发表于 2003-7-21 12:13

编译的时候问题好像出在这一行上...

Konto.java:8: cannot resolve symbol
symbol: class konto
location: class Konto
           konto sparbuch;
         ^
1 error
Exit code: 1
There were errors

运行时...

java.lang.NoClassDefFoundError: Konto
Exception in thread "main" Exit code: 1
There were errors

two steps 发表于 2003-7-21 12:14

是叫instantiierung 么....还是initialisierung.(初始化).????
缺的methode我猜是einzahlen,2楼已经帮着补上了. :p
konstruktor可能是指klass konto里的, 只写了个attribute :private betrag ,而没有这个类的konstruktor. 同常至少有个standarkonstruktor,就是弄个空的:public konot( ){ betrag = null; }.其它的看需要.比如在这个程序里, 可以写个.public konto (int qian) {betrag = qian;}
initialisierung是说main里头的,sparbuch需要先被initialisieren.就是用class konto里的konstuktor(en).   alternativ的选吧....

ZICK 发表于 2003-7-21 12:22

谢谢诸位...
以下是德文的原题...

Die folgende Klasse bildet ein unvollständiges Java-Programm.
Ergänzen Sie alle drei Auslassungen durch neuen Programm-Code!
Machen Sie klar,an welcher Stelle weches neue Code-Stück einzufügen ist.
Hinweis:es fehlen eine Instantiierung,ein Konstruktor und eine Methode!

ZICK 发表于 2003-7-21 12:32

Konto.java:9: variable sparbuch might not have been initialized
           sparbuch.einzahlen(100);
         ^
1 error
Exit code: 1
There were errors

这又是什么意思...

two steps 发表于 2003-7-21 12:38

sorry, 偶偶偶还是不明白那个instantiierung, 下面ergäzung的是按iinitialisierung理解的.

public class Konto
{
    private int betrag;

    public Konto ()    // standare konstruktor
    {
       betrag=null;
    }

    public void abheben (int hoehe)
    {
      betrag = betrag - hoehe;
   }

   public int saldo()
   {
          return betrag;
      }

   public void einzahlen (int money)   // Methode
   {
          betrag=betrag + money;
   }
}
到此为止, 新的类 konto 就算是写完了.
下面是将其调用.

public static void main(String args[])
{
konto sparbuch;
sparbuch = new konto ();// initialisierung

sparbuch.einzahlen(100);
sparbuch.abheben(30);
sparbuch.einzahlen(60);
System.out.println("Der Kontostand des Sparbuchs beträgt" + sparbuch.saldo() + "Euro");
}

two steps 发表于 2003-7-21 12:43

最初由 ZICK 发布
Konto.java...

这就是我郁闷的地方......英文initializ.德文initialisierung...( or initializierung ....;p 偶记不清哩)

那里来的instaniierung 呢???

leotao 发表于 2003-7-21 12:46

instaniierung ??
我的德文书写的是 instanzierung (不知记错了没有,呵呵)
我认为是中文的"实例化",部分中文书是这样描述的
页: [1] 2 3
查看完整版本: [求助]刚开始学,一头雾水...