[求助]刚开始学,一头雾水...
麻烦各位帮忙给看看...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;
}
} 不知道你哪里不明白?
这里是一个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;
}
} 这是一个不完整的java程序
其中缺少一个Instantiierung,一个Konstruktor,及一个Methode
不明白这3个词的意思,及整个程序,因为是初学什么都不懂,而且明天考试,不知道你能不能推荐一些网上的资源,救命啊! 编译的时候问题好像出在这一行上...
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 是叫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的选吧.... 谢谢诸位...
以下是德文的原题...
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! Konto.java:9: variable sparbuch might not have been initialized
sparbuch.einzahlen(100);
^
1 error
Exit code: 1
There were errors
这又是什么意思... 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");
} 最初由 ZICK 发布
Konto.java...
这就是我郁闷的地方......英文initializ.德文initialisierung...( or initializierung ....;p 偶记不清哩)
那里来的instaniierung 呢??? instaniierung ??
我的德文书写的是 instanzierung (不知记错了没有,呵呵)
我认为是中文的"实例化",部分中文书是这样描述的 最初由 leotao 发布
instaniier...
richtig - Instanzierung!
搞定...
谢谢楼上诸位了不好意思,能不能麻烦再看看下例
public class LineTest{
public static void main(String args[])
{
Line line = new Line(0,0,10,20);
line.moveVertical(10);
line.moveHorizontal(20);
System.out.println(line.startPoint.toString() + "," + line.endPoint.toString());
}
}
public class Line
{
Point startPoint, endPoint;
public Line(int x1, int y1, int x2, int y2)
{
startPoint = new Point (x1, y1);
endPoint = new Point (x2,y2);
}
public Line()
{
this (0,0,0,0);
}
public void moveVertical(int distance)
{
startPoint.incrY(distance);
endPoint.incrY(distance);
}
public void moveHorizontal(int distance)
{
startPoint.incrX(distance);
endPoint.incrX(distance);
}
}
public class Point
{
private int x,y;
public Point(int x,int y)
{
this.x = x;
this.y = y;
}
public void incrX(int d)
{
x += d;
}
public void incrY(int d)
{
y += d;
}
public String toString()
{
return x + "/" + y;
}
}
LineTest.java:12: class Line is public, should be declared in a file named Line.java
public class Line
^
LineTest.java:39: class Point is public, should be declared in a file named Point.java
public class Point
^
2 errors
Exit code: 1
There were errors 那就把2个public 去了.
谢了!
具体这一句是什么意思啊?public Point(int x,int y)
{
this.x = x;
this.y = y;
}
好像是个很常见的例子
public class SortDemo{
public static void main(String args[])
{
int[] arrayOfInts = { 32,87,3,589,12,1076,2000,8,622,127 };
for (int i= arrayOfInts.length;--i>=0;)
{ for (int j=0;j<i;j++)
{ if (arrayOfInts > arrayOfInts)
{int temp = arrayOfInts;
arrayOfInts = arrayOfInts;
arrayOfInts = temp;
}
}
}
for (int i=0;i < arrayOfInts.length;i++)
{ System.out.println(arrayOfInts + " ");
}
System.out.println();
}
}
但是中间这一段没读懂...
if (arrayOfInts > arrayOfInts)
{int temp = arrayOfInts;
arrayOfInts = arrayOfInts;
arrayOfInts = temp;
} 是class Point的konstruktor.
class Point
{
private int x,y; 这两个是class point 的 attribute
public Point(int x,int y) // konstruktor注意, 一定是public .this是关键字
{
this.x = x;
this.y = y;
}
public void incrX(int d) // 这以下就都是methode 了
{
x += d;
}
public void incrY(int d)
{
y += d;
}
public String toString()
{
return x + "/" + y;
}
} 回第16贴.
程序好象bubblesort 吧.......8)
if (arrayOfInts > arrayOfInts)
{int temp = arrayOfInts;
arrayOfInts = arrayOfInts;
arrayOfInts = temp;
}
如果Array中第j个元素大于它后边那个, 即第j+1个, 那么就将他们两个的位置交换.
比如87 大于 3 吧, 那执行完这5行后, 就成 3 在8 前边了.
全部运行完了应该是个从小排到大的folge 检讨一下,我觉得我这个讲的不清楚.
public Point(int x,int y)
{
this.x = x;
this.y = y;
}
你也可以这么写.
public Point ( int a , int b )
{
x= a;
y= b;
}
这样是不是对于谁给谁附值清楚点了呢?:-)
懂了
谢谢 two steps 了...今天到此为止了,呵呵... 好啊, hören wir auf...:-)
我也是刚开始学的....你那个名字好有意思啊, 让我想起了我们一个tutor....他的口头语好象就是什么zik zak....;p 你在哪里上学啊,学info的吗,第几学期,真的好厉害啊.肯定以前c学的很好 呵呵, 你说的我脸都红了....也加上天热ing.... O-)
aachen , info第二学期
"肯定以前c学的很好"faint....倒ing....偶家只有java的书...都是到德国后听说这里是学java后现买的......
不好意思,我又回来了...
public class RectangleDemo{
public static void main(String args[])
{
Point p1;
Rectangle r1 = new Rectangle(p1,40,30);
r1.move(50,50);
System.out.println("Der Flaecheninhalt des Rechtecks ist " + r1.area());
}
}
class Rectangle
{
Point origin;
int width, height;
int area()
{
return(width*height);
}
}
class Point
{
int x,y;
Point(int xCoord,int yCoord)
{
x = xCoord;
y = yCoord;
}
}
RectangleDemo.java:6: cannot resolve symbol
symbol: constructor Rectangle(Point,int,int)
location: class Rectangle
Rectangle r1 = new Rectangle(p1,40,30);
^
RectangleDemo.java:7: cannot resolve symbol
symbol: method move(int,int)
location: class Rectangle
r1.move(50,50);
^
2 errors
Exit code: 1
There were errors RectangleDemo.java:6: cannot resolve symbol
symbol : constructor Rectangle (Point,int,int)//class Rectangle没有型如(Point, int, int ) 的konstruktor,
location: class Rectangle
Rectangle r1 = new Rectangle(p1,40,30);//而main里边却来了个对r1的initialisierung.
^
RectangleDemo.java:7: cannot resolve symbol
symbol : method move (int,int)
location: class Rectangle
r1.move(50,50);
^
同样, 里只有一个求面积的methode, 而没有这个move ( int , int) methode ...编译时找不找呀. 同事同事
页:
[1]