public class TestClass {
成都地區(qū)優(yōu)秀IDC服務(wù)器托管提供商(創(chuàng)新互聯(lián)公司).為客戶提供專業(yè)的四川電信機(jī)房托管,四川各地服務(wù)器托管,四川電信機(jī)房托管、多線服務(wù)器托管.托管咨詢專線:028-86922220
public static void main(String[] args) {
Hello hello = new Hello();
String str = hello.getInfo();
System.out.println(str);
}
}
public class Robot
{
private int x = 0, y = 0;// 初始狀態(tài)處在(0,0)位置
private int battery = 200;// 初始電池容量
private int direction = 0;// 0=North, 1=East, 2=South, 3=West
private int[] xwalk = { 0, 1, 0, -1 };
private int[] ywalk = { 1, 0, -1, 0 };
public void walk(int distance)
{
if (battery = distance)
{
battery -= distance;
x += xwalk[direction] * direction;
y += ywalk[direction] * direction;
}
}
public void turnleft()
{
if (battery 0)
{
battery--;
direction = (4 + direction - 1) % 4;
}
}
public void turnright()
{
if (battery 0)
{
battery--;
direction = (direction + 1) % 4;
}
}
public int getBatteryStatus(){return battery;}
public void recharge(){battery = 200;}
public int getXpos(){return x;}
public int getYpos(){return y;}
public int direction(){return direction;}
}
補(bǔ)充說明:好用就行,不求你追加分。其實(shí)這個程序給80分已經(jīng)很多了,先謝謝你啦
編寫電池類(Cell):具有品牌屬性,可以續(xù)電
public?class?Cell?{
private?String?brand;
public?String?getBrand()?{
return?brand;
}
public?void?setBrand(String?brand)?{
this.brand?=?brand;
}
Cell(String?brand){
this.brand?=?brand;
}
public?void?relay()?{
System.out.println("正在續(xù)電.......");
}
}
編寫測試類(TestCell)
import?javax.swing.CellEditor;
public?class?TestCell?{
public?static?void?main(String[]?args)?{
Cell?cell?=?new?Cell("大牌電池");
System.out.println("測試結(jié)果:"+cell.getBrand());
cell.relay();
}
}
不知道你沒有導(dǎo)入Scanner類,在java文件開頭加上 import java.util.Scanner;
如果你寫了那就可能是java包的路徑錯了,沒有找到這個類。
解決方法:
你把import java.util.Scanner;改成import java.util.*;
你拿我這代碼去看看會不會出錯,我這邊沒問題。
import?java.util.Scanner;
public?class?TestIn?{
public?TestIn()?{
//?TODO?Auto-generated?constructor?stub
}
/**
*?@param?args
*/
public?static?void?main(String[]?args)?{
//?TODO?Auto-generated?method?stub
Scanner?scanner?=?new?Scanner(System.in);
int?data?=?scanner.nextInt();
System.out.println(data);
}
}
如果你還是錯誤,那可能就是你的路徑問題了