
正文
进书和售书java代码,网上书店java代码
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
用java定义一个图书类,要求包含作者,书名,书号,价格等信息并要求从主函数输出一本书的信息。
package cn.book;
public class Book {
private String auther="吴承恩";
private String name="西游记";
private String number="1";
private double price=100;
public String getAuther() {
return auther;
}
public void setAuther(String auther) {
this.auther = auther;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
@Override
public String toString() {
return " 作者:" + auther + ", 书名:" + name + ", 书号:" + number + ", 价格:" + price ;
}
//可以从这调用get set 方法 设置属性
public static void main(String[] args) {
Book book = new Book();
System.out.println(book.toString());
}
}
相关问答
Q1: 老师要求用java(eclipse)做一个图书管理系统,内容有增删改查等功能(实现进书,借书,还书
我这倒是有个现成的图书管理系统,是之前同学发给我让我帮他改错的,数据库用的是oracle,不知道是不是符合你的要求。
Q2: 求java编程源代码,关于图书借阅系统的,
/
用户登陆数据库代码:
import java.sql.*;
class Database {
Connection con;
ResultSet rs;
Statement stmt;
public Database() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//
加载
JDBC-ODBC
桥驱动程序
String url = "jdbcdbc:HDB";
con = DriverManager.getConnection(url);
//
连接数据库
HDB //stmt
提供一个创建
SQL
查询、执行查询、得到返回结果
的空间
stmt =
// con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
// ResultSet.CONCUR_READ_ONLY);
} catch (Exception ex) {
System.out.println(ex);
}
}
/*
根据用户名,获取密码
*/
public String getPswd(String name) {
try {
// rs
为执行
SQL
语句所查询的结果赋给结果集对象
rs
rs = stmt.executeQuery("SELECT pswd FROM User WHERE Name = '"
+ name + "'");
rs.last();
//
把
rs
的指针移到最后一行
if (rs.getRow() == 0) {
return null;
} else {
String pswdDB = rs.getString("Pswd");
//
获取
rs
结果集中的
pswd
列的数据
return pswdDB;
}
} catch (Exception e) {
System.out.println(e);
return null;
}
}
/*
增加一行用户名、密码数据
*/
public boolean insertData(String name, String pswd) {
try {
String s = getPswd(name);
if (s == null) {
int rtn = stmt.executeUpdate("INSERT INTO User VALUES('" + name
+ "','" + pswd + "')");
if (rtn != 0)
return true;
} else {
return false;
}
return false;
} catch (Exception et) {
System.out.println(et);
return false;
}
}
}
//
进库数据库代码:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
class BookDatabase {
Connection con;
ResultSet rs;
Statement stmt;
public BookDatabase() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//
加载
JDBC-ODBC
桥驱动程序
String url = "jdbcdbc:Book";
con = DriverManager.getConnection(url);
//
连接数据库
HDB //stmt
提供一个创建
SQL
查询、执行查询、得到返回结果
的空间
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
} catch (Exception ex) {
System.out.println(ex);
}
}
/*
增加一行用户名、密码数据
*/
public boolean insertData(String id, String name, String where, String
price, String date) {
try {
int rtn = stmt.executeUpdate("INSERT INTO Book VALUES('" + id
+ "','"
+ name + "','" + where + "','" + price + "','" + date
+ "')");
if (rtn != 0) {
return true;
} else {
return false;
}
} catch (Exception et) {
System.out.println(et);
return false;
}
}
/*
* public boolean deleteData(String id){ try{ int rtn =
* stmt.executeUpdate("DELETE FROM Book WHERE id=001" ); if( rtn != 0 ){
* return true; } else{ return false; } } catch(Exception e){
* System.out.println( e ) return false; } } public boolean Select(String
* id){ try{ int rtn = stmt.executeUpdate("SELECT * FROM BookIn WHERE
* id='"+id+"'");
*
* if( rtn != 0 ){ return true; } else{ return false; } } catch(Exception
* e){ System.out.println( e ) return false; } }
*/
}
//
出库数据库代码:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
Q3: 急求图书馆管理系统代码java,c++,delphi,vb都可以
/*1、 系统初始化10种图书(图书名自定);
2、 显示所有图书列表(编号、名称和当前状态);
3、 显示图书借出状态(是否已经被借阅);
4、 操作者可以通过图书名称进行查询,并借阅;
5、 操作者也可以归还某本已经借阅的图书;
6、 对某本图书的借阅次数进行汇总求和;
7、 求出借阅次数最多和最少的图书;*/
#ifndef LIBRARY_H
#define LIBRARY_H
#includevector
#includestring
#includeiterator
#includeutility
#includeiostream
using std::cin;
using std::vector;
using std::iterator;
using std::string;
using std::pair;
using std::istream;
class Book{
public:
Book(istream i):ve(bo(i)){};//1、 系统初始化10种图书(图书名自定);
void list(size_t n) const//查询
{ pairstring,bool ir=ve[n+1];
std::cout"第"n"本书名"ir.first"状态"std::ends;
(ir.second==true)?std::cout"存在":std::cout"已借出"std::endl;
std::coutstd::endl;}//2、 显示图书列表(编号、名称和当前状态);
void list(string str) //查询并借阅
{
vectorpairstring,bool ::iterator itr=ve.begin();
vectorpairstring,int ::iterator it=pai.begin();
while(itr!=ve.end())
{if(itr-first==strit-first==str)br {std::cout"存在!请输入y/n确认是否借阅"std::ends;br char ch;cinch;br if(ch=='y')br {itr-second=false;br it-second=it-second++;br std::cout"已借阅"std::ends;}
}else{std::cout"不存在"std::ends;}
++itr;++it;
}
}
void rest(string str)
{vectorpairstring,bool ::iterator itr=ve.begin();br while(itr++!=ve.end())br {if(itr-first==stritr-second==false)br {itr-second=true;br std::cout"已归还"" ";}else{std::cout"不在"std::endl;}}}//5、 操作者也可以归还某本已经借阅的图书;
void sum(const string str)
{vectorpairstring,int ::iterator it=pai.begin();br int max=(++it)-second;br int min=(++it)-second;br string ma,mi;br while(it!=pai.end())br {br if(it-first==str)br {std::cout"借阅次数为"(it-second)std::ends;}
if(maxit-second)
{max=it-second;br ma=it-first;}
if(minit-second)
{min=it-second;br mi=it-first;}}
std::cout"借阅最多次de 图书"ma" "max"次"std::endl;
std::cout"借阅最少次de 图书"mi" "min"次"std::endl;}/*6、 对某本图书的借阅次数进行汇总求和;
7、 求出借阅次数最多和最少的图书;*/
private:
vectorpairstring,bool bo(istream);
vectorpairstring,bool ve;
vectorpairstring,int pai;
};
vectorpairstring,bool Book::bo(istream is)//创建 图书 及存在情况
{
int i=0;
std::string s;
std::vectorpairstring,bool v;
vectorpairstring,int pai;
while(iss)
{
v.push_back(make_pair(s,true));
pai.push_back(make_pair(s,0));
++i;
if(i==10)
break;
}
is.clear();
return v;
}
#endif
下面是 main
#includeiostream
#include"library.h"
using namespace std;
int main()
{
size_t x=5;
string str;
Book a(cin);//初始化
cin.clear();
a.list(x);//输入数字查询
cout"输入查询"endl;
cinstr;
a.list(str);//输入字符查询并借阅
//a.rest(string("sa"));//归还
//a.sum(string("sa"));//查询某本书的借阅次数并统计输出借阅最多和最少的书
return 0;
}
Q4: java实现简单的图书销售统计系统,要用GUI 求java高手帮忙 谢谢啦
我看到数据好像是保存在文件中的,这样解析很不给力。
建议使用 access 数据库,小巧又好用。
其他的这几个功能也不难,楼主,你哪里不会,你的思路是什么,可以讲一讲,可以协助你完成。
Q5: java图书管理界面系统的源代码
java swing 登陆界面code
/*
* Login.java
*
* Created on __DATE__, __TIME__
*/
package com.agen.library.window;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import com.agen.library.factory.DAOFactory;
import com.agen.library.util.GlobalUser;
import com.agen.library.vo.User;
/**
*
* @author __USER__
*/
public class Login extends javax.swing.JFrame {
/**
*
*/
private static final long serialVersionUID = -2176093732040600809L;
/** Creates new form Login */
public Login() {
super("易云图书管理软件V1.0");
Image ime = Toolkit.getDefaultToolkit().getImage(
getClass().getResource("/images/ico.png"));
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setIconImage(ime);
initComponents();
setLocationRelativeTo(null);
this.setResizable(false);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// GEN-BEGIN:initComponents
// editor-fold defaultstate="collapsed" desc="Generated Code"
private void initComponents() {
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jPasswordField1 = new javax.swing.JPasswordField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jMenuItem2 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
formKeyPressed(evt);
}
public void keyTyped(java.awt.event.KeyEvent evt) {
formKeyTyped(evt);
}
});
jLabel2.setFont(new java.awt.Font("微软雅黑", 0, 14));
jLabel2.setText("\u7528\u6237\u540d\uff1a");
jLabel3.setFont(new java.awt.Font("微软雅黑", 0, 14));
jLabel3.setText("\u5bc6 \u7801\uff1a");
jTextField1.setFont(new java.awt.Font("微软雅黑", 0, 14));
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jPasswordField1.setFont(new java.awt.Font("微软雅黑", 0, 12));
jPasswordField1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
jPasswordField1KeyTyped(evt);
}
});
jButton1.setBackground(new java.awt.Color(223, 216, 216));
jButton1.setFont(new java.awt.Font("微软雅黑", 0, 14));
jButton1.setText("\u767b\u9646");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setBackground(new java.awt.Color(223, 216, 216));
jButton2.setFont(new java.awt.Font("微软雅黑", 0, 14));
jButton2.setText("\u53d6\u6d88");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jLabel1.setIcon(new javax.swing.ImageIcon(
getClass().getResource("/images/login_main.jpg"))); // NOI18N
jMenu1.setText("File");
jMenu1.setFont(new java.awt.Font("微软雅黑", 0, 14));
jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
java.awt.event.KeyEvent.VK_Q,
java.awt.event.InputEvent.CTRL_MASK));
jMenuItem1.setText("Exit");
jMenuItem1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jMenuItem1MouseClicked(evt);
}
});
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem1);
jMenuBar1.add(jMenu1);
jMenu2.setText("Help");
jMenu2.setFont(new java.awt.Font("微软雅黑", 0, 14));
jMenuItem2.setText("About");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem2);
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addGroup(
layout.createSequentialGroup()
.addContainerGap()
.addGroup(
layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
false)
.addComponent(
jLabel2,
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()
.addComponent(
jLabel3)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout.createSequentialGroup()
.addGap(10,
10,
10)
.addComponent(
jButton1)
.addGap(47,
47,
47)
.addComponent(
jButton2))
.addComponent(
jPasswordField1)
.addComponent(
jTextField1,
javax.swing.GroupLayout.DEFAULT_SIZE,
197,
Short.MAX_VALUE))
.addContainerGap()))));
layout.setVerticalGroup(layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(
jTextField1,
javax.swing.GroupLayout.PREFERRED_SIZE,
24,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(
jPasswordField1,
javax.swing.GroupLayout.PREFERRED_SIZE,
23,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap(
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)));
pack();
}// /editor-fold
// GEN-END:initComponents
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
About.start();
}
private void jPasswordField1KeyTyped(java.awt.event.KeyEvent evt) {
if (evt.getKeyChar() == '\n') {
String name = jTextField1.getText(); // 获取用户名
String pass = String.valueOf(jPasswordField1.getPassword());// 获取密码
User user = null;
// 未输入用户名
if (name.equals("") || name == null) {
JOptionPane.showMessageDialog(this, "用户名不允许为空!", "cuowu", 0);
return;
}
try {
user = DAOFactory.getIUserDAOInstance().findById(name);
if (user != null) {
if (user.getPass() != null user.getPass().equals(pass)) {
GlobalUser.LOGIN_USER = user; // 记录当前用户
// 进入主界面
Main.start();
this.dispose();
} else {
JOptionPane.showMessageDialog(this, "用户名或密码错误!");
return;
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (user == null) {
JOptionPane.showMessageDialog(this, "用户名或密码错误!", "消息", 0);
return;
}
}
}
private void formKeyTyped(java.awt.event.KeyEvent evt) {
}
private void formKeyPressed(java.awt.event.KeyEvent evt) {
}
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jTextField1.setText("");
jPasswordField1.setText("");
jTextField1.requestFocus();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String name = jTextField1.getText(); // 获取用户名
String pass = String.valueOf(jPasswordField1.getPassword());// 获取密码
User user = null;
// 未输入用户名
if (name.equals("")) {
JOptionPane.showMessageDialog(this, "用户名不允许为空!");
return;
}
try {
user = DAOFactory.getIUserDAOInstance().findById(name);
if (user != null) {
if (user.getPass() != null user.getPass().equals(pass)) {
GlobalUser.LOGIN_USER = user; // 记录当前用户
// 进入主界面
Main.start();
this.dispose();
} else {
JOptionPane.showMessageDialog(this, "用户名或密码错误!", "消息", 0);
return;
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (user == null) {
JOptionPane.showMessageDialog(this, "用户名或密码错误!", "消息", 0);
return;
}
}
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
if (JOptionPane.showConfirmDialog(this, "你确定要退出吗?", "提示",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
System.exit(0);
}
}
private void jMenuItem1MouseClicked(java.awt.event.MouseEvent evt) {
System.exit(1);
}
/**
* @param args
* the command line arguments
*/
public static void main(String args[]) {
// System.out.println(Login.class.getResource("src/images/images/login_main.jpg"));
// new javax.swing.ImageIcon(
// Login.class.getResource("../../../../images/login_main.jpg"));
// new Login().setVisible(true);
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Login().setVisible(true);
}
});
}
// GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JTextField jTextField1;
// End of variables declaration//GEN-END:variables
}




