疑问求解答!!!
哎。。疑问求解!!! 例: String[ 军事小说 ] == int[ 0001 ] 当中的平等关系怎么实现,, 解析:编号 0001 等于 军事小说
哎。。疑问求解!!! 例: String[ 军事小说 ] == int[ 0001 ] 当中的平等关系怎么实现,, 解析:编号 0001 等于 军事小说
2015-07-19
package com.maple;
public class Book {
Book(){ //无参构造函数
}
Book(int newNumber,String newName){ //构造函数的值实现数组的传递; //有参构造函数
this.number=newNumber;
this.name=newName;
}
private int number; //私有变量
private String name;
public int getNumber(){ //实现私有变得传值过程 get , set
return number;
}
public void setNumber(int newNumber){
this.number=newNumber;
}
public String getName(){
return name;
}
public void setName(String newName){
this.name=newName;
}
}
package com.maple;
import java.util.Scanner;
public class MapleBook {
/**
* 模拟借书系统
* 声明图书信息变量String
* 声明图书序列号变量 int
* 使用try catch 判断用户输出并抛出异常
* @param args
*{"武侠小说","言情小说","都市小说","玄幻小说","科幻小说","修真小说","恐怖小说","军事小说"}
*/
/*static String[] book1=new String[]{"武侠小说","言情小说","都市小说","玄幻小说","科幻小说","修真小说","恐怖小说","军事小说"};
static String bk1=book1[0];
static String bk2=book1[1];
static String bk3=book1[2];
static String bk4=book1[3];
static String bk5=book1[4];
static String bk6=book1[5];
static String bk7=book1[6];
static String bk8=book1[7];*/
Book[] books={new Book(1,"武侠小说"),new Book(2,"言情小说"),new Book(3,"都市小说"),new Book(4,"玄幻小说"),new Book(5,"科幻小说"),new Book(6,"修真小说"),new Book(7,"恐怖小说"),new Book(8,"军事小说")};
public static void main(String[] args) {
System.out.println("请你按指示输入相应的信息!!!");
MapleBook mbs=new MapleBook();
mbs.check();
Scanner stc=new Scanner(System.in);
while(true){
try{
int str=stc.nextInt();
if(str==1){
mbs.findNum();
continue;
}else if(str==2){
mbs.findName();
continue;
}
}catch(Exception e){
System.out.println("你按要求输入!!!");
continue;
}
}
}
public void check (){
System.out.println("1:按编号查找。"+"2:按名字查找");
}
public void findNum(){
System.out.println("请按编号输入");
Scanner src=new Scanner(System.in);
int str=src.nextInt();
for(int i=0;i<books.length;i++){
if(books[i].getNumber()==str){
System.out.println("您输入的编号:"+books[i].getNumber()+" 是"+books[i].getName());
}
}
}
public void findName(){
System.out.println("请按名字输入");
Scanner stc=new Scanner(System.in);
String str=stc.next();
for(int i=0;i<books.length;i++){
if(str.equals(books[i].getName())){
System.out.println("您要找的是:"+books[i].getName());
}
}
}
}
举报