给JAVASE初学者的一个例子:J2SE版本的 商家信息记录系统

功能基本实现完成,可以编译执行,来查看效果.

 

程序基本实现了 显示代码与业务逻辑相分离,并模拟了一个数据库的实现机制.

 

package cn.iamsese.product.custom.company;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
/**
 * 商家信息记录系统
 * cn.iamsese.product.custom.company
 * Author: vb2005xu [JAVA菜鸟]
 */
public class Main {
	
	public Main(){
		this.init();
	}
	
	private SellerOPInterface sellerOP ; 
	
	private void init(){
		this.sellerOP = new SellerOP();
		this.initSellersData(this.sellerOP) ;
		
	}
	
	private void initTellLineRecordData(Seller seller){
		TellLineRecordOPInterface tellLineRecordOP = this.sellerOP.getTellLineRecordOP(seller);
		tellLineRecordOP.addTellLineRecord( new TellLineRecord( 1 , MessageFormat.format("{0,date,full}",new Date()) , "抬高K钱1" ,"" +
				"虚太高价,故意坑人" ) ) ;
		tellLineRecordOP.addTellLineRecord( new TellLineRecord( 2 , MessageFormat.format("{0,date,full}",new Date()) , "抬高K钱2" ,"" +
		"虚太高价,故意坑人" ) ) ;
		tellLineRecordOP.addTellLineRecord( new TellLineRecord( 3 , MessageFormat.format("{0,date,full}",new Date()) , "抬高K钱3" ,"" +
		"虚太高价,故意坑人" ) ) ;
		tellLineRecordOP.addTellLineRecord( new TellLineRecord( 4 , MessageFormat.format("{0,date,full}",new Date()) , "抬高K钱4" ,"" +
		"虚太高价,故意坑人" ) ) ;
		//System.out.println(tellLineRecordOP.findAllTellLineRecords());
	}
	
	private void initSellersData(SellerOPInterface sellerOP){
		sellerOP.addSeller(new Seller(0,"商家1","鼎好111") ) ;
		
		Seller seller1 = new Seller(1,"商家2","鼎好112") ;
		sellerOP.addSeller(seller1) ;
		this.initTellLineRecordData(seller1);
		
		sellerOP.addSeller(new Seller(2,"商家3","鼎好103") ) ;
	}
	
	private void printSellersInfo(Enumeration<Seller> sellers){
		//列出所有商家信息
		String formatMSG = "| ID: {0} | Name: {1} | Adderss: {2} | Level: {3} |" ;
		while (sellers.hasMoreElements()){
			Seller seller = sellers.nextElement();
			System.out.println("----------Start-------------------------------------------------------------------------");
			System.out.println(MessageFormat.format(formatMSG, seller.getId(),seller.getName(),seller.getAddress(),this.sellerOP.getSellerLevel(seller)  ));
			
			this.printTellRecords(seller);
			System.out.println("----------Stop-----------------------------------------------------------------");
						
		}
	}
	
	private void printTellRecords(Seller seller){		
		int recordCount = this.sellerOP.getTellLineRecordOP(seller).getRecordsCount() ;
		System.out.println("记录: " + recordCount);
		
		int i = 0 ;
		String formatMSG = " ID: {0} Date: {1} Title: {2} \n 描述 {3} " ;
		for(TellLineRecord record : this.sellerOP.getTellLineRecordOP(seller).findAllTellLineRecords())
		{
			System.out.println( (i++) + "-----");
			System.out.println(MessageFormat.format(formatMSG,record.getId(),record.getDate(),record.getTitle(),record.getDescription()));
		}
	}
	
	private void buildWebUI(){
		this.printSellersInfo(this.sellerOP.findAllSeller());
	}
	
	public static void main(String[] args) {
		Main console = new Main();
		console.buildWebUI();
	}
}

/**
 * 商家所在的大楼
 * cn.iamsese.product.custom.zgcpzcompany
 * Author: vb2005xu [JAVA菜鸟]
 */
class Building {
	public final static int HAI_LONG = 0 ; //海龙 
	public final static int DING_HAO = 0 ; //鼎好 
	public final static int E_WORLD = 0 ; //E世界 
}

/**
 * 商家
 * cn.iamsese.product.custom.zgcpzcompany
 * Author: vb2005xu [JAVA菜鸟]
 */
class Seller {
	private int id ; //公司ID
	private String name ;//公司名称
	private String address ;//办公地点
	
	public Seller(int id,String name,String address)
	{
		this.id = id ;
		this.name = name ;
		this.address = address ;
	}
	
	//public ArrayList<TellLineRecord> records ;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	
}

/**
 * 记录
 * cn.iamsese.product.custom.zgcpzcompany
 * Author: vb2005xu [JAVA菜鸟]
 */
class TellLineRecord {
	private int id ; //ID
	private String date ; //时间
	private String title ; //标题 
	private String description ; //描述
	
	public TellLineRecord(int id,String date,String title,String description){
		this.id = id ;
		this.date = date ;
		this.title = title ;
		this.description = description ;
	}
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	
}


//逻辑层

/**
 * 商家 操作接口
 */
interface SellerOPInterface {
	public Enumeration<Seller> findAllSeller();
	public boolean addSeller(Seller seller) ;
	public Seller findSellerByName(String name);
	public boolean removeSellerByName(String name) ;
	public void removeAllSeller();
	
	public int getSellerLevel(Seller seller) ; // 获取商家的级别
	public TellLineRecordOPInterface getTellLineRecordOP(Seller seller);
}

/**
 * 记录集 操作接口
 * cn.iamsese.product.custom.zgcpzcompany
 * Author: vb2005xu [JAVA菜鸟]
 */
interface TellLineRecordOPInterface {
	public int getRecordsCount() ;
	public ArrayList<TellLineRecord> findAllTellLineRecords();
	public boolean addTellLineRecord(TellLineRecord tellLineRecord) ;
	public TellLineRecord findTellLineRecordByID(int id);
	public boolean removeTellLineRecordByID(int id);
	public void removeAllTellLineRecord();
}


class SellerOP implements SellerOPInterface {	
	
	public SellerOP(){}
	
	public Enumeration<Seller> findAllSeller() {		
		return DBStore.getDBStoreInstance().getSellerRecordStore().elements();
	}

	public Seller findSellerByName(String name) {
		return DBStore.getDBStoreInstance().getSellerRecordStore().get(name);
	}

	public void removeAllSeller() {
		DBStore.getDBStoreInstance().getSellerRecordStore().clear();
	}

	public boolean removeSellerByName(String name) {
		boolean state = false ;
		try {
			DBStore.getDBStoreInstance().getSellerRecordStore().remove(name) ;
			state = true ;
		} catch (NullPointerException e) {
		}
		return state;
	}
	public boolean addSeller(Seller seller) {
		boolean state = false ;
		try {
			DBStore.getDBStoreInstance().getSellerRecordStore().put(seller.getName(),seller) ;
			//为seller的记录对象初始化操作
			DBStore.getDBStoreInstance().getTellLineRecordStore().put(seller.getName() , new ArrayList<TellLineRecord>() ) ;
			state = true ;
		} catch (NullPointerException e) {
		}
		return state;
	}
	public TellLineRecordOPInterface getTellLineRecordOP(Seller seller) {		
		return new TellLineRecordOP(seller);
	}

	public int getSellerLevel(Seller seller) {
		//每两次加一个级别
		//System.out.println(this.getTellLineRecordOP(seller));
		return this.getTellLineRecordOP(seller).getRecordsCount() / 2 + 1;
	}

	
}

class TellLineRecordOP implements TellLineRecordOPInterface {
	private Seller seller ;	
	public TellLineRecordOP(Seller seller) {
		this.seller = seller;
	}	
	
	public ArrayList<TellLineRecord> findAllTellLineRecords() {
		return DBStore.getDBStoreInstance().getTellLineRecordStore().get(this.seller.getName());		
	}

	public TellLineRecord findTellLineRecordByID(int id) {
		return DBStore.getDBStoreInstance().getTellLineRecordStore().get(this.seller.getName()).get(id);
	}

	public void removeAllTellLineRecord() {
		DBStore.getDBStoreInstance().getTellLineRecordStore().get(this.seller.getName()).clear();
	}

	public boolean removeTellLineRecordByID(int id) {
		boolean state = false ;
		try {
			DBStore.getDBStoreInstance().getTellLineRecordStore().get(this.seller.getName()).remove(id) ;
			state = true ;
		} catch (NullPointerException e) {
		}
		return state;
	}

	public boolean addTellLineRecord(TellLineRecord tellLineRecord) {
		boolean state = false ;
		try {
			//首先取得TellLineRecordStore,并判断其中是否存在this.seller.getName()
			if (DBStore.getDBStoreInstance().getTellLineRecordStore().containsKey(this.seller.getName())){
				DBStore.getDBStoreInstance().getTellLineRecordStore().get(this.seller.getName()).add(tellLineRecord) ;
				state = true ;
			}
				
//			else { // -- 这个在调用addSeller时已经初始化了
//				DBStore.getDBStoreInstance().getTellLineRecordStore().put(this.seller.getName() , new ArrayList<TellLineRecord>() ) ;
//			}
//			state = true ;
		} catch (NullPointerException e) {
			//e.printStackTrace();
		}
		return state;
	}

	public int getRecordsCount() {
		try {
			return this.findAllTellLineRecords().size();
		}catch (NullPointerException e) {
			//如果this.findAllTellLineRecords()返回null的话
			return 0 ;
		}
		
	}
	
}

//实体层,这里没有使用到数据库,所以缺少了Dao层的实现

/**
 * 模拟的记录存储器存储器
 * cn.iamsese.product.custom.zgcpzcompany
 * Author: vb2005xu [JAVA菜鸟]
 */
class DBStore {
	private static DBStore instance = null ;
	
	/**
	 * < sellerName,ArrayList<TellLineRecord> >
	 */
	private Hashtable<String, ArrayList<TellLineRecord>> tellLineRecordStore ;
	/**
	 * <sellerName,Seller>
	 */
	private Hashtable<String, Seller> sellerRecordStore ;
	
	/*
	 * 仅能使用单态实例对象
	 */
	private DBStore(){
		this.setSellerRecordStore(new Hashtable<String, Seller> ());
		this.setTellLineRecordStore(new Hashtable<String, ArrayList<TellLineRecord>>()) ;
	}
	
	public static DBStore getDBStoreInstance(){
		if (instance == null)
			instance = new DBStore();
		return instance ;
	}
	
	public Hashtable<String, ArrayList<TellLineRecord>> getTellLineRecordStore() {
		return tellLineRecordStore;
	}

	public void setTellLineRecordStore(
			Hashtable<String, ArrayList<TellLineRecord>> tellLineRecordStore) {
		this.tellLineRecordStore = tellLineRecordStore;
	}

	public Hashtable<String, Seller> getSellerRecordStore() {
		return sellerRecordStore;
	}

	public void setSellerRecordStore(Hashtable<String, Seller> sellerRecordStore) {
		this.sellerRecordStore = sellerRecordStore;
	}
	
}

 

标题基于SpringBoot+Vue的学生交流互助平台研究AI更换标题第1章引言介绍学生交流互助平台的研究背景、意义、现状、方法与创新点。1.1研究背景与意义分析学生交流互助平台在当前教育环境下的需求及其重要性。1.2国内外研究现状综述国内外在学生交流互助平台方面的研究进展与实践应用。1.3研究方法与创新点概述本研究采用的方法论、技术路线及预期的创新成果。第2章相关理论阐述SpringBoot与Vue框架的理论基础及在学生交流互助平台中的应用。2.1SpringBoot框架概述介绍SpringBoot框架的核心思想、特点及优势。2.2Vue框架概述阐述Vue框架的基本原理、组件化开发思想及与前端的交互机制。2.3SpringBoot与Vue的整合应用探讨SpringBoot与Vue在学生交流互助平台中的整合方式及优势。第3章平台需求分析深入分析学生交流互助平台的功能需求、非功能需求及用户体验要求。3.1功能需求分析详细阐述平台的各项功能需求,如用户管理、信息交流、互助学习等。3.2非功能需求分析对平台的性能、安全性、可扩展性等非功能需求进行分析。3.3用户体验要求从用户角度出发,提出平台在易用性、美观性等方面的要求。第4章平台设计与实现具体描述学生交流互助平台的架构设计、功能实现及前后端交互细节。4.1平台架构设计给出平台的整体架构设计,包括前后端分离、微服务架构等思想的应用。4.2功能模块实现详细阐述各个功能模块的实现过程,如用户登录注册、信息发布与查看、在线交流等。4.3前后端交互细节介绍前后端数据交互的方式、接口设计及数据传输过程中的安全问题。第5章平台测试与优化对平台进行全面的测试,发现并解决潜在问题,同时进行优化以提高性能。5.1测试环境与方案介绍测试环境的搭建及所采用的测试方案,包括单元测试、集成测试等。5.2测试结果分析对测试结果进行详细分析,找出问题的根源并
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值