• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

1.做一个图书类图书身份证,名称、价格、获取、设置访问器,构造方法2个,1个无参,1个有参做一个测试类,在主要的中创建3个图书对象,放到目录集合中。做一个菜单,可以添加,删除,修改,查询

包装文本;

公共类图书{

私有字符串id;

私有字符串名称;

私人双倍价格;

公共字符串getId() {

返回id;

}

公共void集合id(字符串id) {

this.id=id

}

公共字符串getName() {

返回名称;

}

公共void集合名称(字符串名){

this.name=name

}

public double getPrice() {

退货价格;

}

公共无效定价(双倍价格){

this.price=价格;

}

公共图书(字符串,字符串名称,双价格){

super();

this.id=string

this.name=name

this.price=价格;

}

公共图书(){

super();

}

}

包装文本;

导入Java。util。ArrayList

导入Java。util。列表;

导入Java。util。扫描仪;

公共课书籍测试{

静态list book list books=new ArrayList book();

/**

* @param args

*/

公共静态void main(String[] args) {

//TODO自动生成的方法存根

creat booklist();

menu();

}

public static void creatBookList(){

//TODO自动生成的方法存根

图书b1=新书(' 1。‘VB’,39.9);

列出书籍。添加(B1);

书b2=新书(' 2。‘VS’,59.9);

列出书籍。添加(B2);

书b3=新书(' 3。‘C’,49.9);

列出书籍。添加(B3);

书籍b4=新书(' 4。‘Java’,69.9);

列出书籍。添加(B4);

}

公共静态空的菜单(){

for(;) {

系统。出去。println('-');

System.out.println('- 1添加图书-');

System.out.println('- 2修改图书-');

System.out.println('- 3删除图书-');

System.out.println('- 4查询图书-');

System.out.println("- 5退出程序 -"); System.out.println("------------------------"); int a = inputInt("请选择操作:"); switch (a) { case 1: addBook(); break; case 2: updateBook(); break; case 3: delBook(); break; case 4: findBook(); break; case 5: return; default: System.out.println("输入错误,请重新输入"); break; } } } private static void findBook() { // TODO Auto-generated method stub System.out.println("id 图书名称 图书价格"); for (Book book : listbooks) { System.out.println(book.getId() + " " + book.getName() + " " + book.getPrice()); } } private static void delBook() { // TODO Auto-generated method stub String id = inputStr("请输入要删除图书的id"); for (int i = 0; i < listbooks.size(); i++) { Book book = listbooks.get(i); if (id.equals(book.getId())) { listbooks.remove(i); } } } private static void updateBook() { // TODO Auto-generated method stub String id = inputStr("请输入要修改的图书id"); for (int i = 0; i < listbooks.size(); i++) { Book book = listbooks.get(i); if (id.equals(book.getId())) { book.setName(inputStr("请输入修改后的图书名称:")); book.setPrice(inputDouble("请输入修改后的图书价格")); listbooks.remove(i); listbooks.add(i, book); } } } private static void addBook() { // TODO Auto-generated method stub String id = inputStr("请输入要添加的图书id"); String name = inputStr("请输入要添加的图书名称"); double price = inputDouble("请输入要添加的图书价格"); Book book = new Book(id, name, price); listbooks.add(book); } public static String inputStr(String msg) { System.out.print(msg); return new Scanner(System.in).nextLine(); } public static int inputInt(String msg) { System.out.print(msg); return new Scanner(System.in).nextInt(); } public static double inputDouble(String msg) { System.out.print(msg); return new Scanner(System.in).nextDouble(); } }

  im25mkqbtvb3109.png

 

 2.上题的类,在一个JSP页面中,创建一个集合,里面放3个图书,集合循环遍历显示在页面上

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="BookMan.Book" %>
    
  </head>
 
  <body>
  <%
        ArrayList<Book> list=new ArrayList<Book>();
        Book book1=new Book(1,"钢铁是怎样炼成的",43);
        Book book2=new Book(2,"海底两万里",44.5);
        Book book3=new Book(3,"Java",54.2);
        list.add(book1);
        list.add(book2);
        list.add(book3); 
        for(Book book:list){
        out.println(book);
        }
    %>
  </body>
</html>

  rhap32jgavf3110.png

 

 3.在MySQL中创建Book表,里面id,name,price,
用命令实现,
添加一个图书,
根据名称删除图书,
把所有名称是“我”开头的图书删除,
删除全部图书,
把20元以上的图书价格都修改为18.8,
查看全部图书,
查看价格高于10块钱的全部图书

DROP TABLE IF EXISTS `book`;
CREATE TABLE `book`  (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '图书编号',
  `name` varchar(25) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '图书名称',
  `price` decimal(10, 2) NOT NULL COMMENT '图书价格',
  PRIMARY KEY (`id`) USING BTREE
);
INSERT INTO `book` VALUES (1, '图书一', 50.90);
INSERT INTO `book` VALUES (2, '图书二', 40.50);
INSERT INTO `book` VALUES (3, '图书三', 45.90);
INSERT INTO `book` VALUES (4, '图书四', 20.00);
UPDATE `book` SET `price`=18.8 WHERE `price`>20;
SELECT * FROM `book`;
SELECT * FROM `book` WHERE `price`>10;
DELETE FROM `book` WHERE `name` LIKE '我%';
DELETE FROM `book`;

  

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now