import java.util.*;
class computer{//
private String name;
private String color;
private String type;
private String ram;
private String harddisk;
private int price;
private String state;
public String open(String state){
return state;
}
public String close(String state){
return state;
}
public String hitch(String state){
return state;
}
public computer(){//默认的构造方法
name=" ";
color=" ";
type=" ";
ram=" ";
harddisk=" ";
price=0;
state=" ";
}
public computer(String tanjicong,String lan,String p4,String 1G,String hongji,int 3500,String good){//自己定义的构造方法
name="micro";
color="lan";
type="p4";
ram="1G";
harddisk="hongji";
price=3500;
state="good";
}
public String getname(){
return name;
}
public String getcolor(){
return color;
}
public String gettype(){
return type;
}
public String getram(){
return ram;
}
public String getharddisk(){
return harddisk;
}
public int getprice(){
return price;
}
public String getstate(){
return state;
}
}
public class jisuanji{//主类
public static void main(String args[]){
computer[] staff=new computer[4];
staff[1]=new computer();
staff[2]=new computer("dell","黑","pentium4","512MB","120G","3000","良好");
staff[3]=new computer("联想","黑","pentium4","256MB","80G","2000","良好");
for(int i=1;i<=3;i++)
{
computer e=staff[i];
System.out.println("计算机品牌:"+e.getname()+"计算机音色"+e.getcolor()+
"型号"+e.gettype()+"内存容量"+e.getram()+"硬盘容量"+e.getharddisk()+"价格"+e.getprice()+"工作状态"+e.getstate());
}
}
}
这个程序不难,但是就是作的不对,不知道为什么原因,老是有语法错误,各位高手帮我看看,这到底是什么原因!有劳各位拉!
----------------解决方案--------------------------------------------------------
建议你把参数传递好好看看..
[此贴子已经被作者于2006-6-8 9:37:58编辑过]
----------------解决方案--------------------------------------------------------
你当然不对了,你无论传入的参数是什么,都是]
name="micro";
color="lan";
type="p4";
ram="1G";
harddisk="hongji";
price=3500;
state="good";
----------------解决方案--------------------------------------------------------
你当然不对了,你无论传入的参数是什么,都是]
name="micro";
color="lan";
type="p4";
ram="1G";
harddisk="hongji";
price=3500;
state="good";
----------------解决方案--------------------------------------------------------
你的computer构造函数的参数定义的是int,而实际传入的是字符型
----------------解决方案--------------------------------------------------------
所以楼主应该先看看JAVA的基础知识
----------------解决方案--------------------------------------------------------
import java.util.*;
class computer
{
private String name;
private String color;
private String type;
private String ram;
private String harddisk;
private int price;
private String state;
public String open(String state)
{
return state;
}
public String close(String state)
{
return state;
}
public String hitch(String state)
{
return state;
}
public computer()
{
name="micro";
color="lan";
type="p4";
ram="1G";
harddisk="hongji";
price=3500;
state="good";
}
public computer(String name,String Color,String type,String ram,String harddisk,int price,String state)
{
this.name = name;
this.color = Color;
this.type = type;
this.ram = ram;
this.harddisk = harddisk;
this.price = price;
this.state = state;
}
public String getname()
{
return name;
}
public String getcolor()
{
return color;
}
public String gettype()
{
return type;
}
public String getram()
{
return ram;
}
public String getharddisk()
{
return harddisk;
}
public int getprice()
{
return price;
}
public String getstate()
{
return state;
}
}
class jisuanji
{
public static void main(String args[])
{
computer[] staff=new computer[4];
staff[1]=new computer();
staff[2]=new computer("dell","黑","pentium4","512MB","120G",3000,"良好");
staff[3]=new computer("联想","黑","pentium4","256MB","80G",2000,"良好");
for(int i=1;i<=3;i++)
{
computer e=staff[i];
System.out.println("计算机品牌:"+e.getname()+" 计算机颜色"+e.getcolor()+
" 型号"+e.gettype()+" 内存容量"+e.getram()+" 硬盘容量"+e.getharddisk()+" 价格"+e.getprice()+" 工作状态"+e.getstate());
}
}
}
----------------解决方案--------------------------------------------------------
楼上对了
----------------解决方案--------------------------------------------------------
呵呵!非常感谢啊!我正在学JAVA,正努力着哩!我每天都自己编一些程序,看看自己的问题在那里!哦,斑竹说的很对!我的好好的学习一些基础知识!谢谢你们拉!,辛苦了,喝杯茶吧!
----------------解决方案--------------------------------------------------------
学习任何一样东西,基础很重要,不能好高鹜远,一定要一步一步来
这样才能学好
----------------解决方案--------------------------------------------------------