|
发表于 2020-1-7 12:39:01
|
显示全部楼层
LZ错误地方和原因帮你标出,建议多看下书
package huangwei;
import java.io.*;
import java.util.*;
class stock
{
String name;
String author;
int price;
stock(String a,String b,int c)
{
name=a;
author=b;
price=c;
}
void print()
{
System.out.println("name is "+name);
System.out.println("author is "+author);
System.out.println("price is "+price);
}
void get()
{
int N=100;
stock []a=new stock[N];
a[0]=new stock("Java","PlayGrrrr...",12);
a[1]=new stock("C#","Bill Gates",13);
a[2]=new stock("Delphi","Boxer",14);
a[3]=new stock("Oracle","zy",15);
}
}
class process
{
void step1()
{
System.out.println("do what?");
System.out.println("a.search b.add c.exit");
char ch=0;
try
{
ch=(char)System.in.read();
System.in.skip(2);
}catch(IOException z){}
if(ch=='a')
{
System.out.println("a.by name b.by author");
char ch2=0;
try
{
ch2=(char)System.in.read();
System.in.skip(2);
}catch(IOException z){}
if(ch2=='a')
{
System.out.print("plz input the book's name:");
InputDate fuck=new InputDate();
fuck.findbookname();
}
if(ch2=='b')
{
System.out.print("plz input the author's name:");
InputDate fuck2=new InputDate();
fuck2.findauthorname();
}
}
if(ch=='b')
{
InputDate fuck3=new InputDate();
fuck3.add();
}
if(ch=='c')
{
System.out.println("c u");
}
}
}
class InputDate
{
static private String s;
static public void input()
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try{
s=br.readLine();
}catch(IOException e){}
}
static public String getString()
{
input();
return s;
}
static public int getInt()
{
input();
return Integer.parseInt(s);
}
public void findbookname()
{
int N=100;
stock []a=new stock[N];
a[0]=new stock("Java","PlayGrrrr...",12);
a[1]=new stock("C#","Bill Gates",13);
a[2]=new stock("Delphi","Boxer",14);
a[3]=new stock("Oracle","zy",15);
stock mis=new stock("Think in JAVA","LXX",100);
//stock中的构造方法的参数是3个,你却直接不加参
//每个类都有一个默认的无参的构造方法,当你建立新的构造方法时,原先默认的无参方法就没了
// stock mis=new stock();
mis.get();
s=InputDate.getString();
Vector names=new Vector();
for(int i=0;i<a.length&&a[i+1]!=null;i++)
{
names.add(a[i].name);
}
if(names.indexOf(s)!=-1)
{
System.out.println("u can fint it here!");
}
else
System.out.println("sorry,there is not such a book!");
}
public void findauthorname()
{
s=InputDate.getString();
int N=100;
stock []a=new stock[N];
a[0]=new stock("Java","PlayGrrrr...",12);
a[1]=new stock("C#","Bill Gates",13);
a[2]=new stock("Delphi","Boxer",14);
a[3]=new stock("Oracle","zy",15);
Vector authornames=new Vector();
for(int i=0;i<a.length&&a[i+1]!=null;i++)
{authornames.add(a[i].author);}
if(authornames.indexOf(s)!=-1)
{
System.out.println("there is such a book!");}
else
System.out.println("i didn't hear that pl at all!");
}
public void add()
{
int N=100;
stock []a=new stock[N];
a[0]=new stock("Java","PlayGrrrr...",12);
a[1]=new stock("C#","Bill Gates",13);
a[2]=new stock("Delphi","Boxer",14);
a[3]=new stock("Oracle","zy",15);
System.out.println("plz input info:");
String ab,b;
int c;
ab=InputDate.getString();
b=InputDate.getString();
c=InputDate.getInt();
int i=0;
while(a[i]!=null)i++;
a[i]=new stock(ab,b,c);
System.out.println("successfully added");
process a1=new process();
a1.step1();
}
}
class main
{
public static void main(String args[])
{
process a1=new process();
a1.step1();
}
}
|
|