Java面向对象编程+jdbc连接MySQL+日志Log4j 《项目搜搜移动大厅》

这篇博客详细介绍了如何使用Java进行面向对象编程,包括创建数据库连接类DBHelp,实现JDBC连接MySQL,以及配置和使用Log4j进行日志记录。此外,还涵盖了消费信息、移动卡、套餐类和服务接口的设计,如ConsumInfo、MobileCard、ServicePackge、CallService、NetService和SendService等。通过这些类和接口,实现了移动大厅业务的模拟操作。同时,提供了测试类Test用于验证代码的正确性。
摘要由CSDN通过智能技术生成
数据库连接类:DBHelp
package DBHelp;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBHelp {
		 /**驱动程序名*/
		private static final   String driver = "com.mysql.jdbc.Driver";
		//访问数据库
		private static final String url = "jdbc:mysql://localhost:3306/food_db?"
		  		+ "useUnicode=true&characterEncoding=UTF8";//防止乱码出现
		  /**MySQL配置时的用户名*/
		private static final  String user = "root";
		   //MySQL配置时的密码
		private static final  String password = "443650890";
		//声明Connection对象
		private static Connection con = null;
		/**
		 * 连接数据库
		 * @return 返回Connection对象
		 * */
	 public static Connection mysqlConn() {
			   try {
				Class.forName(driver); //加载驱动程序
				 /**1.getConnection()方法,连接MySQL数据库!!*/
				   con = (Connection) DriverManager.getConnection(url,user,password);
			} catch (ClassNotFoundException e) {
				System.out.println("加载驱动失败!");
				e.printStackTrace();
			} catch (SQLException e) {
				System.out.println("连接数据库异常!");
				e.printStackTrace();
			}
			  
		 return con;
		 }

}

消费信息类:ConsumInfo
package impl;
/**消费信息类ConsumInfo*/
public class ConsumInfo {
			/**通话时长*/
			int talkTime;
			/**短信条数*/
			int smsCount;
			/**上网流量*/
			int flow;
			/**套餐月资费*/
			double price;
			public int getTalkTime() {
				return talkTime;
			}
			public void setTalkTime(int talkTime) {
				this.talkTime = talkTime;
			}
			public int getSmsCount() {
				return smsCount;
			}
			public void setSmsCount(int smsCount) {
				this.smsCount = smsCount;
			}
			public int getFlow() {
				return flow;
			}
			public void setFlow(int flow) {
				this.flow = flow;
			}
			public double getPrice() {
				return price;
			}
			public void setPrice(double price) {
				this.price = price;
			}
			public ConsumInfo() {
				super();
				// TODO Auto-generated constructor stub
			}
			public ConsumInfo(int talkTime, int smsCount, int flow, double price) {
				super();
				this.talkTime = talkTime;
				this.smsCount = smsCount;
				this.flow = flow;
				this.price = price;
			}
			
}

嗖移动卡类:MobileCard
package impl;

import impl_ServicePackge.ServicePackge;

/**嗖嗖移动卡类MobileCard*/
public class MobileCard {
		 /**卡号*/
		 String cardNumber;
		 /**用户名*/
		 String userName;
		 /**密码*/
		 String passWord;
		 /**所属套餐*/
		 ServicePackge serPackge;
		 /**当月消费金额*/
		 double consumAmount;
		 /**账户余额*/
		 double money ;
		 /**当月实际通话时长*/
		 int realTalkTims;
		 /**当月实际发短信条数*/
		 int realSMSCount;
		 /**当月实际上网流量*/
		 int realFlow;
		 
		 
		 public String getCardNumber() {
			return cardNumber;
		}

		public void setCardNumber(String cardNumber) {
			this.cardNumber = cardNumber;
		}


		public String getUserName() {
			return userName;
		}


		public void setUserName(String userName) {
			this.userName = userName;
		}


		public String getPassWord() {
			return passWord;
		}


		public void setPassWord(String passWord) {
			this.passWord = passWord;
		}


		public ServicePackge getSerPackge() {
			return serPackge;
		}


		public void setSerPackge(ServicePackge serPackge) {
			this.serPackge = serPackge;
		}


		public double getConsumAmount() {
			return consumAmount;
		}


		public void setConsumAmount(double consumAmount) {
			this.consumAmount = consumAmount;
		}


		public double getMoney() {
			return money;
		}


		public void setMoney(double money) {
			this.money = money;
		}


		public int getRealTalkTims() {
			return realTalkTims;
		}


		public void setRealTalkTims(int realTalkTims) {
			this.realTalkTims = realTalkTims;
		}


		public int getRealSMSCount() {
			return realSMSCount;
		}


		public void setRealSMSCount(int realSMSCount) {
			this.realSMSCount = realSMSCount;
		}


		public int getRealFlow() {
			return realFlow;
		}


		public void setRealFlow(int realFlow) {
			this.realFlow = realFlow;
		}


		public MobileCard(String cardNumber, String userName, String passWord, ServicePackge serPackge,
				double consumAmount, double money, int realTalkTims, int realSMSCount, int realFlow) {
		
			this.cardNumber = cardNumber;
			this.userName = userName;
			this.passWord = passWord;
			this.serPackge = serPackge;
			this.consumAmount = consumAmount;
			this.money = money;
			this.realTalkTims = realTalkTims;
			this.realSMSCount = realSMSCount;
			this.realFlow = realFlow;
		}


		public MobileCard() {
			
			
		}
			
			
		/**注册成功后显示信息的方法*/
		public void showMege(){
			System.out.println("卡号:"+this.cardNumber+"用户名:"+this.userName+"当前余额:"
					+this.money+"元。&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值