第9周作业

1.
package com.hm.book;

public class Book {

        private Integer id;
        private String name;
        private double price;
        public Integer getId() {
            return id;
        }
        public void setId(Integer id) {
            this.id = id;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public double getPrice() {
            return price;
        }
        public void setPrice(double price) {
            this.price = price;
        }
        public Book(Integer id, String name, double price) {
            super();
            this.id = id;
            this.name = name;
            this.price = price;
        }
        public Book() {
            super();
        }

 @Override
    public String toString() {
        return "Book{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", price=" + price +
                '}';
    }



package com.hm.test;

import com.hm.book.Book;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Test {
    public static void main(String[] args) {
        List<Book> list = new ArrayList<Book>();
        Book book = new Book();
        Book b1 = new Book(001, "数据库", 40);
        Book b2 = new Book(002, "操作系统", 50.00);
        Book b3 = new Book(003, "计算机组成原理", 55);
        list.add(b1);
        list.add(b2);
        list.add(b3);
        show(list, book);
    }

    public static void show(List<Book> list, Book book) {
        System.out.println("1.添加图书");
        System.out.println("2.删除图书");
        System.out.println("3.修改图书");
        System.out.println("4.查询图书");
        System.out.println("请选择");
        select(list, book);
    }

    public static void select(List<Book> list, Book book) {
        int i = new Scanner(System.in).nextInt();
        switch (i) {
            case 1:
                System.out.println("添加图书的编号:");
                book.setId(new Scanner(System.in).nextInt());
                System.out.println("添加图书的名称:");
                book.setName(new Scanner(System.in).next());
                System.out.println("添加图书的价格:");
                book.setPrice(new Scanner(System.in).nextDouble());
                list.add(book);
                System.out.println("添加成功");
                show(list, book);

                break;
            case 2:
                System.out.println("输入要删除图书的名称:");
                String name=new Scanner(System.in).next();
                for (int j = 0; list != null && j < list.size(); j++) {
                    if (list.get(j).getName().equals(name)) {
                        list.remove(j);
                    }
                }
                System.out.println("删除成功");
                show(list, book);
                break;
            case 3:
                System.out.println("输入要修改图书的编号:");
                int k=new Scanner(System.in).nextInt();;
                for (int j = 0; list != null && j < list.size(); 

 

 2.

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>图书</title>
</head>
<body>
ArrayList<Books> books=new ArrayList<Books>();
Books books1 = new Books("001","40","数据库");
Books books2 = new Books("002","50","操作系统");
Books books3 =new Books("003","55","计算机组成原理");
book.add(books1);
book.add(books2);
book.add(books3);
</body>
</html>

3.

create table book(
id int(10) auto_increment primary key,
name varchar(40),
price double(6,3));
insert into Book(id,name,price)values(1,"English",99);
delete from book where name='Math';
delete from book where name like '我%';
delete from book;
update book set price=18.8 where price>20;
select * from book;
select * from book where price>10;

 

posted @ 2022-05-01 18:27  777733333  阅读(19)  评论(0编辑  收藏  举报