• 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个图书对象,放到目录集合中。做一个菜单,可以添加,删除,修改,查询

一包文本;

2

3本公共课书{

四私有字符串id;

5私有字符串名;

6私人双价;

七公共字符串getId() {

8返回id;

9 }

10 public void setId(字符串id) {

11 this.id=id

12 }

13公共字符串getName() {

14返回名称;

15 }

16 public void setName(字符串名){

17 this.name=name

18 }

19 public double getPrice() {

20退货价格;

21 }

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

23 this.price=价格;

24 }

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

26超();

27 this.id=id

28 this.name=name

29 this.price=价格;

30 }

31公书(){

32超();

33 }

34

35 }

一包文本;

2

3导入Java。util。ArrayList

四导入Java。util。列表;

5导入Java。util。扫描仪;

6

七公共课图书测试{

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

9

10 /**

11 * @param args

12 */

13 public static void main(String[]args){

14 //待办事项自动生成的方法存根

15 creat booklist();

16 menu();

17

18 }

19

20 public static void creatBookList(){

21 //待办事项自动生成的方法存根

22本书b1=新书(' 1 ',' JavaScript ',59.8);

23书单。添加(B1);

24本书b2=新书(' 2 ','安卓移动应用', 49.9);

25本书单。添加(B2);

26书b3=新书(' 3 ','信息系统分析与设计', 49.8);

27个书单。添加(B3);

28 }

29

30公共静态空的菜单(){

31为(;) {

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

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

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

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

36 System.out.println('5 .退出程序');

37

int i = inputInt("请选择你的操作:"); 38 switch (i) { 39 case 1: 40 addBook(); 41 break; 42 case 2: 43 updateBook(); 44 break; 45 case 3: 46 delBook(); 47 break; 48 case 4: 49 findBook(); 50 break; 51 case 5: 52 return; 53 default: 54 System.out.println("输入错误,请重新输入"); 55 break; 56 } 57 } 58 } 59 60 private static void findBook() { 61 // TODO Auto-generated method stub 62 System.out.println("id 图书名称 图书价格"); 63 for (Book book : listbooks) { 64 System.out.println(book.getId() + " " + book.getName() + " " 65 + book.getPrice()); 66 } 67 68 } 69 70 private static void delBook() { 71 // TODO Auto-generated method stub 72 String id = inputStr("请输入要删除图书的id"); 73 for (int i = 0; i < listbooks.size(); i++) { 74 Book book = listbooks.get(i); 75 if (id.equals(book.getId())) { 76 listbooks.remove(i); 77 } 78 } 79 80 } 81 82 private static void updateBook() { 83 // TODO Auto-generated method stub 84 String id = inputStr("请输入要修改的图书id"); 85 for (int i = 0; i < listbooks.size(); i++) { 86 Book book = listbooks.get(i); 87 if (id.equals(book.getId())) { 88 book.setName(inputStr("请输入修改后的图书名称:")); 89 book.setPrice(inputDouble("请输入修改后的图书价格")); 90 listbooks.remove(i); 91 listbooks.add(i, book); 92 } 93 } 94 95 } 96 97 private static void addBook() { 98 // TODO Auto-generated method stub 99 String id = inputStr("请输入要添加的图书id"); 100 String name = inputStr("请输入要添加的图书名称"); 101 double price = inputDouble("请输入要添加的图书价格"); 102 Book book = new Book(id, name, price); 103 listbooks.add(book); 104 105 } 106 107 public static String inputStr(String msg) { 108 System.out.print(msg); 109 return new Scanner(System.in).nextLine(); 110 } 111 112 public static int inputInt(String msg) { 113 System.out.print(msg); 114 return new Scanner(System.in).nextInt(); 115 } 116 117 public static double inputDouble(String msg) { 118 System.out.print(msg); 119 return new Scanner(System.in).nextDouble(); 120 } 121 122 }

vaglfp3355y3371.png

 

 a5k2stlxnia3372.png

 

 pfby3lk0mgp3373.png

 

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

 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <%@page import="com.gd.entity.Book"%>
 3 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 4 <html>
 5 <head>
 6 </head>
 7 
 8 <body>
 9     <%
10         List<Book> list = new ArrayList<Book>();
11         Book b1=new Book(1 "JavaScript     " 59.8);
12         Book b2=new Book(2 "Android移动应用 " 49.9);
13         Book b3=new Book(3 "信息系统分析与设计" 49.8);
14         list.add(b1);
15         list.add(b2);
16         list.add(b3);
17         for (int i = 0; list != null && i < list.size(); i++) {
18             out.print(list.get(i).getId() + "." + list.get(i).getName()
19                     + "," + list.get(i).getPrice() + "<br>");
20         }
21     %>
22 </body>
23 </html>

bdzbaoe5n3a3374.png

 

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

xgq00b0f3se3375.png

 

 lti2r5lumlp3376.png

 

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