我們能根據(jù)此要求提供一份與需求相適應(yīng)的代碼(教學(xué)版,個人版,專業(yè)版,企業(yè)版)
我們提供的服務(wù)有:成都網(wǎng)站設(shè)計、網(wǎng)站建設(shè)、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、靖江ssl等。為上千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的靖江網(wǎng)站制作公司
為獲取建議,你需要告訴我們有效的電子郵件地址。
您還可以直接依靠百度Hi聯(lián)系我們, 或借助百度知道向我求助, 或憑借百度知道發(fā)送短消息
或QQ:六五七幺五六幺五('幺'讀 yao 一聲)
有時間能完成你的題目
ES:\FFF2ABE57886516CE04C493C49B6329A
交易提醒:預(yù)付訂金是陷阱
定制開發(fā)管理系統(tǒng),B2B/B2C電子商務(wù),企業(yè)/個人網(wǎng)站更有優(yōu)惠
編寫一個教師類,其中有成員屬性:name、classcount.方法: int sumClass()、avgClass();
class teacher{
String name,classcount;
List list;
public int sumClass(int sum){
return sum;
}
public int avgClass(int Date){
int avg=this.sum/Date;
return avg;
}
public teacher(String name,int classcount){
this.name=name;this.classcount=classcount;
}
public static void main(String[] args){
while(true){
teacher a=new teacher("張三",10);
list=new List();
list.put(a);
System.out.println(a.name+"老師的總課時:"+a.sumClass()+"\n\t"+"平均課時:"+a.avgClass());
}
}
}
隨手寫,未測試,給樓主參考吧。我想應(yīng)該沒什么大問題吧,嘿嘿~
分三個包,自己建個包,導(dǎo)進去就ok了,數(shù)據(jù)庫是access的。
package 登錄;
import java.awt.EventQueue;
public class Cilent {
private JFrame frame;
private JTextField textField;
private JPasswordField passwordField;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Cilent window = new Cilent();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Cilent() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setTitle("登陸界面");
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
frame.setResizable(false);
JLabel lblNewLabel = new JLabel("用戶名");
lblNewLabel.setBounds(38, 43, 80, 34);
frame.getContentPane().add(lblNewLabel);
textField = new JTextField();
textField.setBounds(155, 42, 227, 37);
frame.getContentPane().add(textField);
textField.setColumns(10);
JLabel label = new JLabel("密 碼");
label.setBounds(38, 115, 80, 34);
frame.getContentPane().add(label);
passwordField = new JPasswordField();
passwordField.setBounds(155, 115, 227, 37);
frame.getContentPane().add(passwordField);
JButton btnNewButton = new JButton("登 錄");
btnNewButton.setBounds(60, 187, 115, 34);
frame.getContentPane().add(btnNewButton);
btnNewButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
UserCheck UC=new UserCheck(textField.getText(),String.valueOf(passwordField.getPassword()));
if(UC.getI()!=0) //有此用戶
{
frame.setVisible(false);
}
else
{
textField.setText("");
passwordField.setText("");
}
}
});
JButton button = new JButton("取 消");
button.setBounds(242, 187, 115, 34);
frame.getContentPane().add(button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
textField.setText("");
passwordField.setText("");
}
});
}
}
/*****************************************************************/
package 登錄;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import 操作處理.UsersCL;
/**@author 20111024
* 檢測登錄的用戶在數(shù)據(jù)庫中有無,若沒有,則提示沒有此用戶,
* 若有,則判斷級別:普通用戶還是管理員。
*/
public class UserCheck {
private int i=0; //用戶級別:0不是用戶、1是管理員、2是普通用戶
UserCheck(String name ,String password)
{
String jdriver="sun.jdbc.odbc.JdbcOdbcDriver";
String connectDB="jdbc:odbc:Students";
Statement stmt=null;
ResultSet rs=null;
Connection con=null;
try {
Class.forName(jdriver);
con=DriverManager.getConnection(connectDB);
stmt=con.createStatement();
String query="select * from users where name='"+name+"' and passwd='"+password+"'";
rs=stmt.executeQuery(query);
if(rs.next())
{
//數(shù)據(jù)庫中有此用戶,訪問成功
i=Integer.parseInt(rs.getString(3));
UsersCL UL=new UsersCL(i);
}
else
{
i=0; //沒有用戶是默認(rèn)是0級
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public int getI() {
return i;
}
}
/********************************************************************************************/
package 操作處理;
import java.awt.EventQueue;
public class UsersCL implements ActionListener{
private JFrame frame;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
private int i=0;
private JLabel label_3;
private JTextField textField_4;
public UsersCL(int i) {
this.i=i;
frame = new JFrame();
frame.setTitle("用戶處理界面");
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
frame.setResizable(false);
frame.setVisible(true);
JLabel lblNewLabel = new JLabel("學(xué) 號");
lblNewLabel.setBounds(24, 32, 74, 29);
frame.getContentPane().add(lblNewLabel);
JLabel label = new JLabel("姓 名");
label.setBounds(24, 71, 74, 29);
frame.getContentPane().add(label);
JLabel label_1 = new JLabel("年 齡");
label_1.setBounds(24, 110, 74, 29);
frame.getContentPane().add(label_1);
label_3 = new JLabel("性 別");
label_3.setBounds(24, 149, 74, 29);
frame.getContentPane().add(label_3);
JLabel label_2 = new JLabel("狀 態(tài)");
label_2.setBounds(24, 195, 74, 29);
frame.getContentPane().add(label_2);
textField = new JTextField();
textField.setBounds(101, 34, 113, 25);
frame.getContentPane().add(textField);
textField.setColumns(10);
textField_1 = new JTextField();
textField_1.setColumns(10);
textField_1.setBounds(101, 73, 113, 25);
frame.getContentPane().add(textField_1);
textField_2 = new JTextField();
textField_2.setColumns(10);
textField_2.setBounds(101, 112, 113, 25);
frame.getContentPane().add(textField_2);
textField_3 = new JTextField();
textField_3.setEditable(false);
textField_3.setColumns(10);
textField_3.setBounds(101, 199, 288, 25);
frame.getContentPane().add(textField_3);
textField_4 = new JTextField();
textField_4.setColumns(10);
textField_4.setBounds(101, 149, 113, 25);
frame.getContentPane().add(textField_4);
if(1==i)
{
JButton btnNewButton = new JButton("追 加");
btnNewButton.setBounds(276, 41, 113, 29);
frame.getContentPane().add(btnNewButton);
btnNewButton.addActionListener(this);
btnNewButton.setActionCommand("追加");
JButton button_1 = new JButton("刪 除");
button_1.setBounds(276, 145, 113, 29);
frame.getContentPane().add(button_1);
button_1.addActionListener(this);
button_1.setActionCommand("刪除");
}
JButton button = new JButton("查 詢");
button.setBounds(276, 91, 113, 29);
frame.getContentPane().add(button);
button.addActionListener(this);
button.setActionCommand("查詢");
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String name,age,sex,query=null;
int num,age1,count=0;
num=Integer.parseInt(textField.getText());
name=textField_1.getText();
age1=Integer.parseInt(textField_2.getText());
sex=textField_4.getText();
if(e.getActionCommand().equals("追加"))
{
query="insert into students values("+num+","+"'"+name+"',"+age1+",'"+sex+"');";
count=1;
}
else if(e.getActionCommand().equals("查詢"))
{
query="select * from students where XSB="+num+";";
count=2;
}
else if(e.getActionCommand().equals("刪除"))
{
query="delete from students where XSB="+num+" and name="+"'"+name+"'";
count=3;
}
Statement stmt=null;
ResultSet rs=null;
Connection con=null;
String jdriver="sun.jdbc.odbc.JdbcOdbcDriver";
String connectDB="jdbc:odbc:Students";
String query1=null;
try {
Class.forName(jdriver);
con=DriverManager.getConnection(connectDB);
stmt=con.createStatement();
if(count==1)
{
query1="select * from students where XSB="+num+";";
rs=stmt.executeQuery(query1);
if(rs.next())
textField_3.setText("已經(jīng)由此記錄,不能追加!");
else
{
stmt.executeUpdate(query);
textField_3.setText("已經(jīng)追加完成!");
}
}
else if(2==count)
{
stmt.executeQuery(query);
rs=stmt.executeQuery(query);
if(rs.next())
{
textField_3.setText("已查找到此記錄!");
}
else
{
textField_3.setText("沒有此記錄,可以追加!");
}
}
else if(3==count)
{
query1="select * from students where XSB="+num+" and name="+"'"+name+"'";
rs=stmt.executeQuery(query1);
if(rs.next())
{
stmt.executeUpdate(query);
textField_3.setText("已刪除此記錄!");
}
else
textField_3.setText("無此記錄!");
}
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
finally{
//關(guān)閉資源
if(stmt!=null){
try {
stmt.close();
} catch (Exception e2) {
// TODO: handle exception
}
stmt=null;
}
if(con!=null){
try {
con.close();
} catch (Exception e2) {
// TODO: handle exception
}
con=null;
}
}
}
}
幫你寫好啦,采納吧。
public?class?Teacher?{
//?員工號
private?int?id;
//?姓名
private?String?name;
//?工資
private?double?salary;
//?績效工資
private?double?bonus;
//?課時數(shù)量
private?double?lessonNum;
//?課時系數(shù)
private?static?double?lessonRate?=?1;
public?Teacher(int?id,?String?name,?double?salary,?double?bonus,?double?lessonNum)?{
this.id?=?id;
this.name?=?name;
this.salary?=?salary;
this.bonus?=?bonus;
this.lessonNum?=?lessonNum;
}
//?總工資
public?double?sumSalary()?{
return?salary?+?bonus;
}
//?當(dāng)量課時
public?double?curLessonNum()?{
return?lessonNum?*?lessonRate;
}
public?static?void?setLessonRate(double?lessonRate)?{
Teacher.lessonRate?=?lessonRate;
}
//?測試
public?static?void?main(String[]?args)?{
//?創(chuàng)建兩個教師對象,輸出兩位教師的姓名+總工資
Teacher?t1?=?new?Teacher(1,?"zhangSan",?5000,?2000,?20);
Teacher?t2?=?new?Teacher(2,?"wangWu",?6000,?4000,?30);
System.out.println("姓名"?+?t1.name?+?"總工資"?+?t1.sumSalary());
System.out.println("姓名"?+?t2.name?+?"總工資"?+?t2.sumSalary());
//?輸出課時系數(shù)為1.2時,兩位教師的當(dāng)量課時
Teacher.setLessonRate(1.2);
System.out.println(t1.name?+?"當(dāng)量課時:"?+?t1.curLessonNum());
System.out.println(t2.name?+?"當(dāng)量課時:"?+?t1.curLessonNum());
//?輸出課時系數(shù)為1.1時,兩位教師的當(dāng)量課時
Teacher.setLessonRate(1.1);
System.out.println(t1.name?+?"當(dāng)量課時:"?+?t1.curLessonNum());
System.out.println(t2.name?+?"當(dāng)量課時:"?+?t1.curLessonNum());
}
}
運行結(jié)果:
class MyClass1
{
private int data;
public int getDate()
{
return data;
}
public void setData(int data)
{
this.data=data;
}
}