java编写电池类代码 编写电池类cell
JAVA测试类怎么写,求大神指导下!
public class TestClass {
成都地区优秀IDC服务器托管提供商(创新互联公司).为客户提供专业的四川电信机房托管,四川各地服务器托管,四川电信机房托管、多线服务器托管.托管咨询专线:028-86922220
public static void main(String[] args) {
Hello hello = new Hello();
String str = hello.getInfo();
System.out.println(str);
}
}
用java编写一个程序
public class Robot
{
private int x = 0, y = 0;// 初始状态处在(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;}
}
补充说明:好用就行,不求你追加分。其实这个程序给80分已经很多了,先谢谢你啦
javab编程题目求大神帮忙解答一下,谢谢!
编写电池类(Cell):具有品牌属性,可以续电
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("正在续电.......");
}
}
编写测试类(TestCell)
import javax.swing.CellEditor;
public class TestCell {
public static void main(String[] args) {
Cell cell = new Cell("大牌电池");
System.out.println("测试结果:"+cell.getBrand());
cell.relay();
}
}
JAVA 大神求帮助,帮我看看哪里错。怎么改?
不知道你没有导入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);
}
}
如果你还是错误,那可能就是你的路径问题了
网站栏目:java编写电池类代码 编写电池类cell
文章位置:http://myzitong.com/article/ddiepjs.html