Java小项目另一个水果摊

article/2025/10/12 9:55:01

文章目录

  • 前言
  • 一、包和表截图
  • 二、源代码
    • 1.JDBC连接Mysql数据
      • 管理员界面:增删查改
      • 用户界面 :查找水果
      • 建立断开连接
    • 2.GUI窗口界面
      • 开始选择界面
      • 用户购买水果界面
      • 管理员登录界面
      • 管理员界面
    • 3.水果属性
    • 4.main方法
  • 总结
    • 拒绝白嫖,给个三连鼓励一下吧!


前言

前一段时间利用Java基础知识集合和IO流做了个简单的小项目-水果摊,感觉不过瘾,最近又想着用GUI和Mysql数据库重做一下,名为另一个水果摊,下面就来分享一下代码吧

一、包和表截图

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

二、源代码

1.JDBC连接Mysql数据

管理员界面:增删查改

package com.vector.service;import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.vector.dao.Fruit;
import com.vector.units.ConnectMsql;public class FruitDao {public static String add(Fruit fruit) {String s = null;try {// Connection connection = ConnectMsql.getConnectMsql();String sql = "insert into fruit(name,price,number) values(?,?,0)";Connection connection = ConnectMsql.getConnectMsql();PreparedStatement ad = connection.prepareStatement(sql);Statement stmt = connection.createStatement();ResultSet rs = stmt.executeQuery("select * from fruit");int f = 0;while (rs.next()) {if (fruit.getName().equals(rs.getString("name"))) {f = 1;}/** System.out.println(rs.getInt("id") + " " + rs.getString("name") + " " +* rs.getDouble("price") + " " + rs.getInt("number"));*/}if (f == 0) {ad.setString(1, fruit.getName());ad.setDouble(2, fruit.getPrice());int i = ad.executeUpdate();if (i > 0) {// System.out.println("添加成功!");s = "添加成功!";} else {// System.out.println("水果重复,添加失败!");s = "水果重复,添加失败!";}} else {s = "水果重复,添加失败!";}} catch (SQLException e) {// TODO Auto-generated catch block// e.printStackTrace();}return s;}public static String delete(String name) {String sql = "delete from fruit where name = ?";String s1 = null;Connection connection = ConnectMsql.getConnectMsql();PreparedStatement dele = null;try {dele = connection.prepareStatement(sql);dele.setString(1, name);int i = dele.executeUpdate();if (i > 0) {s1 = "删除成功!";} else {s1 = "删除失败!未找到该水果!";}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return s1;}public static String change(String name, double price) {String sql = "update fruit set price= ? where name= ?";String s2 = null;try {Connection connection = ConnectMsql.getConnectMsql();PreparedStatement upda = connection.prepareStatement(sql);upda.setDouble(1, price);// upda.setInt(2, 2);upda.setString(2, name);// System.out.println(name);int i = upda.executeUpdate();if (i > 0) {s2 = " 修改成功!";} else {s2 = "修改失败,水果不存在!";}} catch (SQLException e) {e.printStackTrace();}return s2;}public static ResultSet list() {ResultSet rs = null;Connection connection = ConnectMsql.getConnectMsql();Statement stmt;try {stmt = connection.createStatement();rs = stmt.executeQuery("select * from fruit");/** while (rs.next()) { s="序号:"+rs.getInt("id") + " 水果名称:" + rs.getString("name")* + " 水果价格:" + rs.getDouble("price") + " ";* System.out.println("序号:"+rs.getInt("id") + " 水果名称:" + rs.getString("name") +* " 水果价格:" + rs.getDouble("price") + " " );* * }*/} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return rs;}}

用户界面 :查找水果

package com.vector.service;import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;import com.vector.dao.Fruit;
import com.vector.units.ConnectMsql;public class UFruitDao {public static List<Fruit> list = new ArrayList<>();static Fruit f = null;public static List Uadd(String name, int number) {ResultSet rs = null;Connection connection = ConnectMsql.getConnectMsql();try {Statement stmt = connection.createStatement();rs = stmt.executeQuery("select * from fruit");int k = 0;while (rs.next()) {if (rs.getString("name").equals(name)) {f = new Fruit(rs.getString("name"), rs.getDouble("price"), number);k = 1;}/** System.out.println("序号:" + rs.getInt("id") + " 水果名称:" + rs.getString("name")* + " 水果价格:" + rs.getDouble("price") + " ");*/}if (k == 0) {System.out.println("水果不纯在,添加失败!");}k = 0;for (Fruit s : list) {if (s.getName().equals(name)) {s.setNumber(s.getNumber() + number);k = 1;}}if (k == 0)list.add(f);} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return list;}
}

建立断开连接

package com.vector.units;import java.sql.*;public class ConnectMsql {public static Connection connect;public static Connection getConnectMsql() {try {Class.forName("com.mysql.cj.jdbc.Driver");// Class.forName("org.gjt.mm.mysql.Driver");// System.out.println("成功加载Mysql驱动程序!");} catch (Exception e) {System.out.print("加载Mysql驱动程序时出错!");e.printStackTrace();}try {connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/fru?&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true","root", "zpx");// System.out.println("成功连接Mysql服务器!");Statement stmt = connect.createStatement();} catch (Exception e) {System.out.print("获取连接错误!");e.printStackTrace();}return connect;}public static void closeConnection() {if (connect != null) {try {connect.close();// sSystem.out.println("数据库连接关闭");} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}

2.GUI窗口界面

开始选择界面

package com.vector.view;
import java.awt.BorderLayout;
import java.awt.EventQueue;import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;import com.vector.test.logon;
import com.vector.view.userInterface;import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.ImageIcon;
import javax.swing.JTextArea;
import java.awt.Color;
import java.awt.CardLayout;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.SystemColor;public class selInterface extends JFrame {private JPanel contentPane;/*** Launch the application.*/public static void star() {EventQueue.invokeLater(new Runnable() {public void run() {try {selInterface frame = new selInterface();frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}/*** Create the frame.*/public selInterface() {setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\eclip\\FruitV\\src\\tubiao.png")); //左上角图标setTitle("\u6C34\u679C\u644A");setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setBounds(100, 100, 600, 600);JMenuBar menuBar = new JMenuBar();menuBar.setToolTipText("");setJMenuBar(menuBar);JMenu menu = new JMenu("\u9875\u9762\u9009\u62E9");menuBar.add(menu);Monitor2 monitor = new Monitor2();JMenu menu_1 = new JMenu("\u7BA1\u7406\u5458\u754C\u9762");menu_1.setIcon(new ImageIcon("D:\\eclip\\FruitV\\src\\556.png"));   //管理员图标menu.add(menu_1);JMenuItem menuItem = new JMenuItem("\u767B\u5F55");menu_1.add(menuItem);menuItem.addActionListener(monitor);JMenuItem menuItem_2 = new JMenuItem("\u987E\u5BA2\u754C\u9762");menuItem_2.setIcon(new ImageIcon("D:\\eclip\\FruitV\\src\\557.png"));    //登录图标menu.add(menuItem_2);menuItem_2.addActionListener(monitor);contentPane = new JPanel();contentPane.setBackground(Color.WHITE);contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));setContentPane(contentPane);contentPane.setLayout(null);JLabel lblNewLabel_1 = new JLabel("");lblNewLabel_1.setBounds(0, 71, 584, 465);lblNewLabel_1.setIcon(new ImageIcon("D:\\eclip\\FruitV\\src\\122.png"));     //顾客图标contentPane.add(lblNewLabel_1);JLabel label = new JLabel("\u6B22\u8FCE\u6765\u5230\u6C34\u679C\u644A");label.setBounds(245, 0, 99, 71);contentPane.add(label);JLabel lblNewLabel = new JLabel("");lblNewLabel.setIcon(new ImageIcon("D:\\eclip\\FruitV\\src\\lan.png"));      //窗口上方蓝色方块lblNewLabel.setBackground(Color.GREEN);lblNewLabel.setBounds(0, 0, 584, 71);contentPane.add(lblNewLabel);ImageIcon ig = new ImageIcon("D:\\eclip\\FruitV\\src\\tubiao.png");   //左上角图标ImageIcon img = new ImageIcon("D:\\eclip\\FruitV\\src\\QQ图片20210420205633.png");     //窗口背景图JLabel imgLabel = new JLabel(img);this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));imgLabel.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());}
}
class Monitor2 implements ActionListener {public void actionPerformed(ActionEvent e) {//System.out.println("有响应");String buttonName = e.getActionCommand();if(buttonName.equals("登录")) {logon.star();}if(buttonName.equals("顾客界面")) {System.out.println("顾客界面");userInterface.start();}}
}

在这里插入图片描述

用户购买水果界面

package com.vector.view;import java.awt.Image;
import java.awt.List;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.jar.JarFile;
import javax.swing.*;
import com.vector.dao.Fruit;
import com.vector.service.UFruitDao;public class userInterface extends JFrame {public static ArrayList <Fruit> list;static double x;JPanel contentPane;Image im;Box boxH, boxH1; Box boxVOne, boxVTwo; Box button, show;Box show1, show2;public static JTextArea a1,a2; public userInterface() {setLayout(new java.awt.FlowLayout());setResizable(false);contentPane = new JPanel();setContentPane(contentPane);contentPane.setOpaque(false);setVisible(true);setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);init();}void init() {ImageIcon ig = new ImageIcon("D:\\eclip\\FruitV\\src\\tubiao.png");im = ig.getImage();setIconImage(im);ImageIcon img = new ImageIcon("D:\\eclip\\FruitV\\src\\beijing.png");JLabel imgLabel = new JLabel(img);this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));imgLabel.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());boxH = Box.createHorizontalBox();boxVOne = Box.createVerticalBox();boxVTwo = Box.createVerticalBox();button = Box.createHorizontalBox();show = Box.createVerticalBox();show1 = Box.createVerticalBox();show2 = Box.createVerticalBox();boxH1 = Box.createHorizontalBox();JTextField t1 = new JTextField(10);JTextField t2 = new JTextField(10);JTextField t3 = new JTextField(10);a1 = new JTextArea(9, 30);a2 = new JTextArea(4, 30);JScrollPane s1=new JScrollPane(a1);JScrollPane s2=new JScrollPane(a2);JButton b1 = new JButton("确定添加");JButton b2 = new JButton("确定购买");JButton b3 = new JButton("确定付款");boxVOne.add(new JLabel("水果名称:"));boxVOne.add(new JLabel("水果数量(斤):"));boxVTwo.add(t1);boxVTwo.add(t2);button.add(b1);show.add(s1);show.add(Box.createVerticalStrut(20));show.add(Box.createHorizontalStrut(110));show.add(b2);show.add(Box.createVerticalStrut(20));boxH.add(boxVOne);boxH.add(Box.createHorizontalStrut(10));boxH.add(boxVTwo);boxH.add(button);add(boxH);add(show);boxH1.add(new JLabel("请付款:"));boxH1.add(Box.createHorizontalStrut(10));boxH1.add(t3);boxH1.add(b3);show2.add(boxH1);show2.add(Box.createVerticalStrut(10));show2.add(s2);add(show1);add(show2);Monitor1 monitor =new Monitor1();b1.addActionListener(monitor);b2.addActionListener(monitor);b3.addActionListener(monitor);monitor.setText1(t1);monitor.setText2(t2);monitor.setText3(t3);}public class Monitor1 implements ActionListener {JTextField text1,text2,text3;public void setText1(JTextField text1) {this.text1 = text1;}public void setText2(JTextField text2) {this.text2 = text2;}public void setText3(JTextField text3) {this.text3 = text3;}@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubString buttonName = e.getActionCommand();try {if(buttonName.equals("确定添加")) {String name=text1.getText();String number0 = (String) text2.getText();int number = Integer.valueOf(number0.toString());list =new ArrayList<>();list = (ArrayList<Fruit>) UFruitDao.Uadd(name, number);a1.setText("");for (Fruit s : list) {//System.out.println(s.toString());a1.append(s.toString()+"\n");}System.out.println("添加成功!");}if(buttonName.equals("确定购买")) {x=0;for (Fruit s : list) {x+=s.getNumber()*s.getPrice();}a1.append("请付款:"+x+"元。"+"\n");}if(buttonName.equals("确定付款")) {String money0 = (String) text3.getText();double money = Double.valueOf(money0.toString());double s=money-x;a2.setText("");if(s>0) {//System.out.println("付款成功,找你"+s+"元。");a2.append("付款成功,找你"+s+"元,慢走不送!");}if(s==0) {//System.out.println("付款成功,刚好够");a2.append("付款成功,刚好够,慢走不送!");}if(s<0) {//System.out.println("付款失败,钱不够");a2.append("付款失败,钱不够。");}	}}catch(Exception e2) {System.out.println("添加失败,请按要求输入!");}}}public static void start() {userInterface win = new userInterface();win.setBounds(100, 100, 600, 600);win.setTitle("水果摊");}
}

在这里插入图片描述

管理员登录界面

package com.vector.test;import java.awt.BorderLayout;
import java.awt.EventQueue;import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;import com.vector.view.admInterface;import javax.swing.JLabel;
import java.awt.Color;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;public class logon extends JFrame {private JPanel contentPane;private JTextField textField;private JPasswordField passwordField;/*** Launch the application.*/public static void star() {EventQueue.invokeLater(new Runnable() {public void run() {try {logon frame = new logon();frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}/*** Create the frame.*/public logon() {setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\eclip\\FruitV\\src\\556.png"));setTitle("\u7BA1\u7406\u5458\u767B\u5F55\u7CFB\u7EDF");setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setBounds(100, 100, 600, 600);contentPane = new JPanel();contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));setContentPane(contentPane);contentPane.setLayout(null);JLabel label = new JLabel("\u7BA1\u7406\u5458\u767B\u5F55\u7CFB\u7EDF");label.setForeground(new Color(139, 0, 139));label.setBounds(239, 38, 112, 15);contentPane.add(label);JLabel label_1 = new JLabel("\u7528\u6237\u540D\uFF1A");label_1.setBounds(120, 98, 54, 15);contentPane.add(label_1);textField = new JTextField();textField.setText("1+1=\uFF1F");textField.setBounds(179, 95, 214, 21);contentPane.add(textField);textField.setColumns(10);JLabel label_2 = new JLabel("\u5BC6\u7801\uFF1A");label_2.setBounds(120, 162, 54, 15);contentPane.add(label_2);Monitor3 monitor =new Monitor3();passwordField = new JPasswordField();passwordField.setBounds(179, 159, 214, 18);contentPane.add(passwordField);monitor.setP1(passwordField);JButton button = new JButton("\u767B\u5F55");button.setBounds(193, 228, 93, 23);contentPane.add(button);button.addActionListener(monitor);JButton button_1 = new JButton("\u9000\u51FA");button_1.setBounds(296, 228, 93, 23);contentPane.add(button_1);button_1.addActionListener(monitor);JLabel label_4 = new JLabel("\u731C\u731C\u5BC6\u7801\u662F\u4EC0\u4E48......");label_4.setForeground(new Color(139, 0, 0));label_4.setBounds(231, 341, 176, 15);contentPane.add(label_4);JLabel lblNewLabel = new JLabel("");lblNewLabel.setIcon(new ImageIcon("D:\\eclip\\FruitV\\src\\dongtai.gif"));lblNewLabel.setBounds(231, 379, 123, 99);contentPane.add(lblNewLabel);JLabel lblNewLabel_1 = new JLabel("");lblNewLabel_1.setBounds(401, 162, 106, 15);contentPane.add(lblNewLabel_1);}
}
class Monitor3 implements ActionListener {JPasswordField p1;public void setP1(JPasswordField p1) {this.p1 = p1;}public void actionPerformed(ActionEvent e) {String s=p1.getText();String buttname=e.getActionCommand();if(buttname.equals("登录")) {if(s.equals("2")) {admInterface.start();}else {System.out.println("密码错误!");}}if(buttname.equals("退出")) {System.exit(0);}}
}

在这里插入图片描述

管理员界面

package com.vector.view;import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;import com.vector.dao.Fruit;
import com.vector.service.FruitDao;
import com.vector.units.ConnectMsql;public class admInterface extends JFrame {public static JTextArea a1;public static JTextArea a2;Image im;public static Fruit fruit;public admInterface() {setLayout(new FlowLayout());setVisible(true);setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);ImageIcon ig = new ImageIcon("D:\\eclip\\FruitV\\src\\tubiao.png");im = ig.getImage();setIconImage(im);// Component H= Box.createHorizontalStrut(10);// Component V= Box.createVerticalStrut(10);Box boxH1 = Box.createHorizontalBox();Box boxH2 = Box.createHorizontalBox();Box boxH3 = Box.createHorizontalBox();Box boxH4 = Box.createHorizontalBox();Box boxH5 = Box.createHorizontalBox();Box boxV = Box.createVerticalBox();JTextField t1 = new JTextField(10);JTextField t2 = new JTextField(10);JTextField t3 = new JTextField(10);JTextField t4 = new JTextField(10);JTextField t5 = new JTextField(10);JButton B1 = new JButton("确定添加");JButton B2 = new JButton("确定删除");JButton B3 = new JButton("确定修改");JButton B4 = new JButton("刷新");a1 = new JTextArea(8, 20);a2 = new JTextArea(11, 20);JScrollPane scroll1 = new JScrollPane(a1);JScrollPane scroll2 = new JScrollPane(a2);boxH1.add(new JLabel("水果名称:"));boxH1.add(t1);boxH1.add(Box.createHorizontalStrut(10));boxH1.add(new JLabel("水果价格(/斤):"));boxH1.add(t2);boxH1.add(Box.createHorizontalStrut(10));boxH1.add(B1);boxH2.add(new JLabel("水果名称:"));boxH2.add(Box.createHorizontalStrut(10));boxH2.add(t3);boxH2.add(Box.createHorizontalStrut(10));boxH2.add(B2);boxH3.add(new JLabel("水果名称:"));boxH3.add(Box.createHorizontalStrut(10));boxH3.add(t4);boxH3.add(Box.createHorizontalStrut(10));boxH3.add(new JLabel("水果新价格(/斤):"));boxH3.add(Box.createHorizontalStrut(10));boxH3.add(t5);boxH3.add(B3);boxH4.add(new JLabel("操作结果:"));boxH4.add(Box.createHorizontalStrut(10));boxH4.add(scroll1);boxH5.add(new JLabel("水果列表:"));boxH5.add(Box.createHorizontalStrut(10));boxH5.add(scroll2);boxV.add(Box.createVerticalStrut(10));boxV.add(new JLabel("增加水果"));boxV.add(Box.createVerticalStrut(10));boxV.add(boxH1);boxV.add(Box.createVerticalStrut(20));boxV.add(new JLabel("删除水果"));boxV.add(Box.createVerticalStrut(10));boxV.add(boxH2);boxV.add(Box.createVerticalStrut(20));boxV.add(new JLabel("更改水果价格"));boxV.add(Box.createVerticalStrut(10));boxV.add(boxH3);boxV.add(Box.createVerticalStrut(20));boxV.add(boxH4);boxV.add(Box.createVerticalStrut(20));boxV.add(boxH5);boxV.add(Box.createVerticalStrut(10));boxV.add(B4);add(boxV);Monitor monitor = new Monitor();B1.addActionListener(monitor);B2.addActionListener(monitor);B3.addActionListener(monitor);B4.addActionListener(monitor);monitor.settext1(t1);monitor.settext2(t2);monitor.settext3(t3);monitor.settext4(t4);monitor.settext5(t5);}public class Monitor implements ActionListener {JTextField text1, text2, text3, text4, text5;public void settext1(JTextField str) {text1 = str;}public void settext2(JTextField str) {text2 = str;}public void settext3(JTextField str) {text3 = str;}public void settext4(JTextField str) {text4 = str;}public void settext5(JTextField str) {text5 = str;}public void actionPerformed(ActionEvent e) {String buttonName = e.getActionCommand();try {if (buttonName.equals("确定添加")) {String name = text1.getText();String price0 = (String) text2.getText();double price = Double.valueOf(price0.toString());// System.out.println(name + price);fruit = new Fruit(name, price, 0);String s = FruitDao.add(fruit);a1.append(s + "\n");ConnectMsql.closeConnection();}if (buttonName.equals("确定删除")) {String name = text3.getText();String s = null;try {s = FruitDao.delete(name);} catch (Exception e1) {// TODO Auto-generated catch block// e1.printStackTrace();System.out.println("添加失败,请输入正确的格式!");}a1.append(s + "\n");ConnectMsql.closeConnection();}if (buttonName.equals("确定修改")) {String name = text4.getText();// System.out.println(name);String price0 = (String) text5.getText();String s = null;double price = Double.valueOf(price0.toString());try {s = FruitDao.change(name, price);} catch (Exception e2) {e2.printStackTrace();}a1.append(s + "\n");ConnectMsql.closeConnection();}if (buttonName.equals("刷新")) {ResultSet rs = FruitDao.list();try {a2.setText("");while (rs.next()) {a2.append("序号:" + rs.getInt("id") + ",   水果名称:" + rs.getString("name") + ",   水果价格:"+ rs.getDouble("price") + " \n");}} catch (SQLException e1) {// TODO Auto-generated catch blockSystem.out.println("添加失败,请输入正确的格式!");// e1.printStackTrace();}ConnectMsql.closeConnection();}} catch (Exception e1) {System.out.println("添加失败,请依照正确格式输入!");a1.append("添加失败,请依照正确格式输入!");}}}public static void start() {admInterface win = new admInterface();win.setBounds(100, 100, 600, 700);win.setTitle("管理员页面");}}

在这里插入图片描述

3.水果属性

package com.vector.dao;public class Fruit {private String name;private double price;private int number;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 int getNumber() {return number;}public void setNumber(int number) {this.number = number;}public Fruit( String name, double price, int number) {this.name = name;this.price = price;this.number = number;}public String toString() {return "水果名称:"+name+",水果价格:"+price+",购买水果数量:"+number;}}

4.main方法

package com.vector.domain;import com.vector.view.selInterface;public class mainV {public static void main(String[] args) {selInterface.star();}}

总结

拒绝白嫖,给个三连鼓励一下吧!

在这里插入图片描述


http://chatgpt.dhexx.cn/article/TvY1p3RW.shtml

相关文章

JavaWeb之综合小项目

案例需求&#xff1a; 使用Java程序操作数据库&#xff0c;并把结果显示在jsp页面上。 &#xff08;这里只做查询操作&#xff0c;增删改操作类似如此&#xff09; 使用工具&#xff1a; maven&#xff0c;idea&#xff0c;tomcat&#xff0c;MySQL数据库。 使用技术&#xff1…

20个Java小项目,献给嗜学如狂的人,拿来练练手

给大家推荐一条由浅入深的JAVA学习路径&#xff0c;首先完成 Java基础、JDK、JDBC、正则表达式等基础实验&#xff0c;然后进阶到 J2SE 和 SSH 框架学习。最后再通过有趣的练手项目进行巩固。 JAVA基础 1. Java编程语言&#xff08;新版&#xff09; 2. Java进阶之设计模式…

Java面试:java小项目实例

前言 本人是底层 211 本科,刚毕业,⽆科研经历,但是有些项⽬经历。 在国内监控行业某头部企业做过一段时间的实习。 想着投下字节,可以积累⼀下⾯试经验和为金九银十面招做准备。投了简历之后,过了一段时 间,HR 就打电话跟我约时间, 说明一下,我投的是北京 office。 以下就是一…

java 练手小项目

学习了javaSE的基础&#xff0c;为了巩固对Java面向对象编程&#xff0c;以及java多线程编程的理解&#xff0c;使用swing 写了一个很简单的小项目&#xff0c;源码github地址: https://github.com/pythondever/swing-demo 喜欢的同学可以学习学习 整体代码流程 * 1. JFra…

javaWeb小项目

作为一个学习加Java的小白&#xff0c;非常开心能记录下自己的成长历程。技术有限&#xff0c;请见谅&#xff01; 我主要学习的是Java后端&#xff0c;当我学着做了一个web小项目之后对javaee项目也有了初步见解&#xff01; 老师说万物皆对象&#xff0c;万物皆增删改查。我的…

java练习小项目(一)

学习java有一段时间了&#xff0c;都是处于那种三天打鱼&#xff0c;两天晒网的状态&#xff0c;没有效率&#xff0c;因为方法不对&#xff0c;一直是在看资料&#xff0c;看视频&#xff0c;并没有实际上手项目&#xff0c;就算当时看了&#xff0c;记住了&#xff0c;最后还…

适合Java新手练手的小项目!

对于很多朋友来说&#xff0c;Java是学习编程的开始&#xff0c;也有很多朋友希望通过Java可以找到工作&#xff0c;那么当我们学习了Java的基础知识之后&#xff0c;我们急需要一些项目去帮我们整理一下自己学习的知识点以及提高一下编程能力&#xff0c;对小的工程有一个大致…

Java小项目谁看谁都会(图书管理)

在我之前的几篇博客中对于Java语法&#xff0c;思想等等进行了总结&#xff0c;但是还是差点那味&#xff0c;就是没有将这些知识串起来那么今天的这篇博客我就将Java中&#xff1a;类 对象 封装 继承 多态 抽象类 接口等等知识共同使用完成一个Java的小项目一起来看 介绍 我…

推荐几个适合新手的Java练手项目(好玩又有趣)

Java练手项目第一波 一、坦克大战 链接&#xff1a;https://www.bilibili.com/video/BV1zP4y1b7gw/?spm_id_from333.337.search-card.all.click Java练手小项目&#xff0c;熟练掌握面向对象编程思想、对象池的使用、IO流、多线程、GUI等基础。 二、贪吃蛇 链接&#xff1a;ht…

10个优质的Java练手项目

10个优质的Java练手项目 最近有很多小伙伴私信我说推荐几个毕设项目&#xff0c;还有就是学了Java有一段时间了&#xff0c;想找几个项目想练练手&#xff0c;在面试的时候也可以增加一点项目经验。 在这里我收集了10个可以直接导入运行的项目。 由简单到复杂&#xff0c;分别…

JAVA小项目(一)——一个简单的记帐本【轻松入门,附源码】

目录 1. 实现效果 2.项目架构 3. 细节代码实现 &#x1f31e;哈喽&#xff0c;大家好丫&#xff0c;你们的小郭子又来啦 ~ &#x1f31e;今天我们用java来写一个简单的小项目——【记账本】&#xff0c;嘿嘿 话不多说&#xff0c;直接上干货&#xff0c; 1. 实现效果 2.项目…

【目标定位】基于matlab TDOA GPS混合定位【含Matlab源码 2310期】

⛄一、基于粒子滤波污染源定位简介 1 混合定位的系统结构 本文提出的GPS/TDOA混合定位系统结构可见于图1。 移动终端集成了无线通信模块和GPS接收模块,终端可同时测得通信网络中相对于服务基站的TDOA和GPS卫星到终端的伪距。在CDMA通信系统中,从通信终端测量TDOA的具体方法和…

基于图像的目标检测与定位方法概述

目录 1. 目标检测与定位概念2. 目标检测与定位方法2.1 传统目标检测流程2.2 two-stage检测算法2.2.1 R-CNN2.2.2 two-stage其他算法2.2.2.1 Spatial Pyramid Pooling&#xff08;空间金字塔池化&#xff09;2.2.2.2 Fast-RCNN2.2.2.3 P11 Faster RCNN 2.3 One-Stage2.3.1 YOLO2…

大疆无人机实现目标定位

大疆无人机实现目标定位 大疆无人机回传的实时视频可以帮助飞友观察发现美景&#xff0c;就称为目标吧&#xff0c;你偏偏对目标很感兴趣&#xff0c;迫切想知道目标的位置&#xff0c;最好是经纬度坐标。你查找大疆Document&#xff0c;欣喜地发现大疆提供了定位机体本身的定…

2-基于单目视觉的目标定位

1-四种坐标系描述 一、世界坐标系 客观三维世界的绝对坐标系&#xff0c;也称客观世界坐标系&#xff0c;是以目标为原点建立起来的坐标系。 二、摄像机坐标系 摄像机坐标系是以摄像机的光心作为坐标系的原点&#xff0c;&#xff3a;c&#xff0e;轴与光轴重合&#xff0c;并…

复杂情况下,目标区域定位

复杂情况下&#xff0c;基于halcon的目标区域定位 原始图源代码处理结果 原始图 源代码 dev_close_window () read_image (Image, E:/Halcon_Learn/黑块提取_网络/1.bmp) get_image_size (Image, Width, Height) dev_open_window_fit_size (0, 0, Width, Height, -1, -1, Wind…

目标检测_精确定位_2020

Side-Aware Boundary Localization for More Precise Object Detection 论文&#xff1a;https://arxiv.org/pdf/1912.04260.pdf 代码&#xff1a; 关键文章&#xff1a;Faster R-CNN [37], RetinaNet [25], and Cascade R-CNN 提出问题&#xff1a; 传统的基于锚点和大小…

Opencv中关于特征点匹配定位的问题(二)单目标和多目标定位

单目标和多目标定位 单目标定位多目标定位 单目标定位 在opencv官方提供了一种定位的思路&#xff0c;就是通过匹配的点来获取透视变换矩阵&#xff0c;然后经过透视变换后就能够获得对应的目标的坐标了。 import cv2 import numpy as np# 打开两个文件 img1 cv2.imread(321…

目标定位和检测系列(1):一些基本概念

最近开始学习深度学习中的定位和检测任务。本来打算直接看论文&#xff0c;却发现文章中的的很多基本概念都搞不清楚&#xff0c;于是就自己先梳理了一些定位和检测任务的基本概念。&#xff08;内容主要来自斯坦福大学的CS231课程、吴恩达的deeplearning.ai卷积部分&#xff0…

OpenCV技巧篇——多目标视觉定位(以飞镖定位为例)

OpenCV技巧篇【1】——多目标视觉定位&#xff08;以飞镖定位为例&#xff09; 1、针对问题 多目标视觉定位是指通过计算机视觉技术对一张图片中的多个目标进行识别和定位的过程。本篇将以对飞镖定位为例&#xff0c;提出一个简单有效的多目标定位技巧&#xff0c;最终实现如…