求解题目 我不会做了 JAVA新手

求解题目 我不会做了 JAVA新手,第1张

以下是我写的一些简单的源码,以防有些地方看不懂,我打了注释,有一些看起来一堆的好复杂的代码不用管,那个是IDE生成的。

Goodsjava

/

  

  @Title: Goods

  @Dscription: 商品类

  @author Deleter

  @date 2016年12月20日 下午12:23:14

  @version 10

 /

public class Goods {

public int id;

public String name;

public double price;

public int nums;

public int getId() {

return id;

}

public void setId(int id) {

thisid = id;

}

public String getName() {

return name;

}

public void setName(String name) {

thisname = name;

}

public double getPrice() {

return price;

}

public void setPrice(double price) {

thisprice = price;

}

public int getNums() {

return nums;

}

public void setNums(int nums) {

thisnums = nums;

}

@Override

public String toString() {

return "Goods [id=" + id + ", name=" + name + ", price=" + price

+ ", nums=" + nums + "]";

}

@Override

public int hashCode() {

final int prime = 31;

int result = 1;

result = prime  result + id;

result = prime  result + ((name == null)  0 : namehashCode());

result = prime  result + nums;

long temp;

temp = DoubledoubleToLongBits(price);

result = prime  result + (int) (temp ^ (temp >>> 32));

return result;

}

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != objgetClass())

return false;

Goods other = (Goods) obj;

if (id != otherid)

return false;

if (name == null) {

if (othername != null)

return false;

} else if (!nameequals(othername))

return false;

if (nums != othernums)

return false;

if (DoubledoubleToLongBits(price) != Double

doubleToLongBits(otherprice))

return false;

return true;

}

}

Applejava

/

  

  @Title: Apple

  @Dscription: 苹果

  @author Deleter

  @date 2016年12月20日 下午12:26:52

  @version 10

 /

public class Apple extends Goods {

}

ShoppingCarjava

/

  

  @Title: ShoppingCar

  @Dscription: 购物车

  @author Deleter

  @date 2016年12月20日 下午12:36:39

  @version 10

 /

public class ShoppingCar implements ShoppingCarInterface {

private static HashMap<Integer, Goods> lists = new HashMap<Integer, Goods>();

@Override

public void add(Goods goods) {

Goods g = goods;

// 如果购物车中已经存在该商品

if (listsget(goodsgetId()) != null) {

// 新加入的数量+原来在购物车中的数量

gsetNums(goodsgetNums() + listsget(goodsgetId())getNums());

listsput(goodsgetId(), g);

} else {

// 不存在则直接加入

listsput(goodsgetId(), goods);

}

}

@Override

public void del(int id) {

if (listsget(id) != null)

listsremove(id);

}

@Override

public double toTotal() {

double total = 0;

Set<Integer> keys = listskeySet();

for (Integer key : keys) {

// 单项总价 = 单价 x 数量

total += listsget(key)getPrice()  listsget(key)getNums();

}

return total;

}

@Override

public int size() {

return listssize();

}

@Override

public Set<Integer> ids() {

return listskeySet();

}

@Override

public String detail(int id) {

return listsget(id)toString();

}

}

ShoppingCarInterfacejava

/

  

  @Title: GoodsInterface

  @Dscription: 购物车接口方法

  @author Deleter

  @date 2016年12月20日 下午12:27:13

  @version 10

 /

public interface ShoppingCarInterface {

/

  添加商品

  

  @param goods

 /

public void add(Goods goods);

/

  移除商品

  

  @param goods

 /

public void del(int id);

/

  获取商品详情

  

  @return

 /

public String detail(int id);

/

  计算总价

  

  @return

 /

public double toTotal();

/

  取购物车大小

  

  @return

 /

public int size();

/

  返回所有ID

  

  @return

 /

public Set<Integer> ids();

}

Testjava

/

  

  @Title: Test

  @Dscription: 测试类

  @author Deleter

  @date 2016年12月20日 下午12:40:33

  @version 10

 /

public class Test {

public static void main(String[] args) {

ShoppingCar sc = new ShoppingCar();

for (int i = 1; i <= 10; i++) {

Apple apple = new Apple();

applesetId(i);

applesetName("苹果" + i);

applesetPrice(35);

applesetNums(i);

// 添加到购物车

scadd(apple);

}

// 统计总价

Systemoutprintln("总价:" + sctoTotal());

// 删除id=1的商品

scdel(1);

// 统计总价

Systemoutprintln("总价:" + sctoTotal());

// 显示详情

Set<Integer> ids = scids();

for (int id : ids) {

Systemoutprintln(scdetail(id));

}

}

}

程序员的表白代码

第一条语言:Java代码翻译:直到死之前,每天爱你多一点代码:while(lifeend){love++;}

第二条语言:C语言代码翻译:IcannotsayHellototheWorldwithoutu代码:#incldestdiohintmain(){printf(HelloWorldn);retrn0;}//IcannotsayHellototheWorldwithoutu

第三条语言:python代码翻译:山无陵,江水为竭,冬雷震震,夏雨雪,天地合,乃敢与君绝!代码:if(mountainarris==None):if(riverwater==None):if(winterthunder==True):if(summersnow==True):if(skyheight==groundheight):iwithyou=Falseelse:iwithyou=True

第四条语言:Erlang代码代码翻译:深圳相遇,至死不渝代码:-module(you_and_me)-export([start/1])-record(person,{name,address,status})start(Name)-one_world(Name)one_world(Name)keep_to_love_you(Person)say_goodbye(Person)-io:format(~p:seeyounextworld!~n,[Person#personname])see_you_next_world(Name)-one_world(Name)

第五条语言:Java语言代码翻译:爱你到天荒地老代码:while(!worlddestroy){Systemoutprintln(iloveyou);}

Attention !!!

再过几天,

就到了恩爱秀满天的日子了!

七夕!中国情人节!

很多单身汪都在绞尽脑汁

买什么礼物给TA?

鲜花?包包?

还是请TA一起去看场**?

用什么方式告诉对方

内心最想对TA说的话

不能跟这个哥们一样

原本想对TA说

结果嘴巴一哆嗦

说成了

每当想起你这张丑脸,我就泛起了微笑……

结果可想而知?

一开始我以为这样的悲剧

只会发生在程序员身上

因为外界都认为

程序员不浪漫、木内

但我错了

程序员的表白方式更加的特别

NO1

把以下代码保存为html后缀文件在浏览器中打开,

Happy

结果就是这样的

喜欢吗?

NO2

某公司程序员对小编说

于是就有了

有没有暖到你的内心呢?

温馨告白

程序员,也许不善言辞

但总是默默地在行动

用行动去诠释他们对你的爱

值此七夕佳节

雅腾教育祝愿

每一个程序员

和即将成为程序员的朋友

七夕快乐!

永远幸福!

物车的逻辑业务的实现(MyCartBOjava),能够满足用户的添加,删除,修改,清空,查看购物车的信息!

ConnDBjava(这只是一个得到数据库连接和类)

01 //连接数据库

02 package cnfqfxmodel;

03

04 import javasql;

05

06 public class ConnDB

07 {

08 //定义一个连接

09 private Connection ct = null;

10

11 //得到连接

12 public Connection getConn()

13 {

14 try {

15 //加载驱动

16 ClassforName("commicrosoftjdbcsqlserverSQLServerDriver");

17 //得到连接

18 ct = DriverManagergetConnection

19 ("jdbc:microsoft:sqlserver://localhost:1433;databaseName=whdb2","sa","sa");

20 } catch (Exception e) {

21 eprintStackTrace();

22 // TODO: handle exception

23 }

24 return ct;

25 }

26 }

GoodsBeanjava(这个文件主要用来保存从数据库的goods表中取得的信息)

01 //这是一个与Goods表对应的java bean

02 //表的信息可以保存在这里面

03 package cnfqfxmodel;

04

05 public class GoodsBean

06 {

07 //分别与goods表的各个字段相对应

08 private int goodsId = 0;

09 private String goodsName = "";

10 private String goodsInfo = "";

11 private String goodsPlace = "";

12

13

14 public int getGoodsId() {

15 return goodsId;

16 }

17 public void setGoodsId(int goodsId) {

18 thisgoodsId = goodsId;

19 }

20

21

22 public String getGoodsName() {

23 return goodsName;

24 }

25 public void setGoodsName(String goodsName) {

26 thisgoodsName = goodsName;

27 }

28

29

30 public String getGoodsInfo() {

31 return goodsInfo;

32 }

33 public void setGoodsInfo(String goodsInfo) {

34 thisgoodsInfo = goodsInfo;

35 }

36

37

38 public String getGoodsPlace() {

39 return goodsPlace;

40 }

41 public void setGoodsPlace(String goodsPlace) {

42 thisgoodsPlace = goodsPlace;

43 }

44 }

MyCartBOjava(这个就是购物车,主要以HashMap实现存放用户想买的商品id,商品数量然后,通过方法的调用把购物车中的信息返回到界面让用户看)

001 //这是一个业务对象,相当于一个购物车!!

002 //-->使用说明:这个购物车最好是在session中使用,因为一个用户一辆购物车,这样东西才不会一直丢

003 package cnfqfxmodel;

004

005 import javasql;

006 import javautil;

007

008 public class MyCartBO

009 {

010 //定义几个数据库的连接

011 private Connection ct = null;

012 private PreparedStatement ps = null;

013 private ResultSet rs = null;

014

015 //定义一个HashMap充当购物车,第一个用来存放goodsId,值就是goods的数量

016 HashMap<String, String> hm = new HashMap<String, String>();

017

018 //当用户想购买的时候,就加入 购物车里面

019 public void addGoods(String goodsId, String goodsNumber)

020 {

021 hmput(goodsId, goodsNumber);

022 }

023

024 //当用户不想要东西的时候,就把它删除

025 public void delGoods(String goodsId)

026 {

027 hmremove(goodsId);

028 }

029

030 //当用户什么也不想要的时候,就清空它

031 public void clearGoods()

032 {

033 hmclear();

034 }

035

036 //当用户想更换物品的数量的时候,就更新一下

037 public void upGoods(String goodsId, String newNumber)

038 {

039 //还是用加入物品的方法,因为会自动替换掉它,如果货物名字想换,那说明用户想删除了

040 hmput(goodsId, newNumber);

041 }

042

043 //得到单个物品的数量,要用的话把它转成int型再使用

044 public String getGoodsNumberByGoodsId(String goodsId)

045 {

046 return hmget(goodsId);

047 }

048

049 //把购物车的东西全部取出来,放入ArrayList里面

050 public ArrayList<GoodsBean> getAllGoods()

051 {

052 //要知道这个ArrayList是用来放GoodsBean,因为GoodsBean与表相对应,所以可以保存物品的信息

053 ArrayList<GoodsBean> al = new ArrayList<GoodsBean>();

054 try {

055 //得到连接

056 ct = new ConnDB()getConn();

057

058 //想一个sql语句,主要是取得goodsId,就可以全部取出来给外面的使用

059 String sql = "select from goods where goodsId in (";

060 Iterator<String> it = hmkeySet()iterator();

061 while(ithasNext())

062 {

063 //把goodsId取出来

064 String goodsId = itnext();

065 if(ithasNext()){

066 sql += goodsId+",";

067 }else{

068 sql += goodsId+")";

069 }

070 }

071

072 //创建ps,上面把sql语句组织好

073 ps = ctprepareStatement(sql);

074

075 //执行

076 rs = psexecuteQuery();

077

078 //取出来,放在GoodsBean,再把GoodsBean一个个放入ArrayList中,显示的页面就可以调用了

079 while(rsnext())

080 {

081 GoodsBean gb = new GoodsBean();

082 gbsetGoodsId(rsgetInt(1));

083 gbsetGoodsName(rsgetString(2));

084 gbsetGoodsInfo(rsgetString(3));

085 gbsetGoodsPlace(rsgetString(4));

086

087 //把gb放入al,相当于保存了从数据库中获得的数据

088 aladd(gb);

089 }

090 } catch (Exception e) {

091 eprintStackTrace();

092 // TODO: handle exception

093 }finally{

094 thiscloseDBResource();

095 }

096 return al;

097 }

098

099 //关闭数据库资源

100 public void closeDBResource()

101 {

102 try {

103 if(rs != null){

104 rsclose();

105 rs = null;

106 }

107 } catch (Exception e2) {

108 e2printStackTrace();

109 // TODO: handle exception

110 }

111 try {

112 if(ps != null){

113 psclose();

114 ps = null;

115 }

116 } catch (Exception e2) {

117 e2printStackTrace();

118 // TODO: handle exception

119 }

120 try {

121 if(ct != null){

122 ctclose();

123 ct= null;

124 }

125 } catch (Exception e2) {

126 e2printStackTrace();

127 // TODO: handle exception

128 }

129 }

130 }

1发送xoxO(会出现满屏亲亲) 2发送mi manchi(会出现满屏小星星) 3发送ohh(翻译:留在我身边) 4发送ch will mit dir S wim(翻译:我想和你在一起) 5发送Voce e meu bebe(翻译:你是我的宝贝) 6发送 RUYDUAautrinuU(翻译我只喜欢你) 7发送 love at first sight(翻译:—见钟情) 8发送We will be happy(我们会幸福) 9发送missu(会出现星星雨) 10发送u621u7231u460(翻译:爱你) 11发送u5728u4e0Ou8d7Nu5427(翻译在一起) 12发送Milji pouze jednu osobu, ta osoba jste vy我只爱一个人,那个人就是你) 13发送 yax you(翻译我跟你说)发送yyyax you翻译我喜欢你)发送 yox you!(我爱死你了) 14n 55 iw!(倒过来是i miss you我想你。) 15我想要两颗西柚("1 wanttoseeyou"我想要见你) 16962464(用九宫格输入试试) 17Mg+Znso4==MgSo4+zn(你的镁夺走了我的锌) 18Te echo de menos(微信翻译:我想你) 19双木非林田下有心(相思) 20nnggui(倒过来看就是ineedyoy我需要你) 表白代码大全可复制免费2  程序员的表白代码 第一条语言:Java代码翻译:直到死之前,每天爱你多一点代码:while(lifeend){love++;} 第二条语言:C语言代码翻译:IcannotsayHellototheWorldwithoutu代码:#incldestdiohintmain(){printf(HelloWorldn);retrn0;}//IcannotsayHellototheWorldwithoutu 第三条语言:python代码翻译:山无陵,江水为竭,冬雷震震,夏雨雪,天地合,乃敢与君绝!代码:if(mountainarris==None):if(riverwater==None):if(winterthunder==True):if(summersnow== True):if(skyheight==groundheight):iwithyou=Falseelse:iwithyou=True 第四条语言:Erlang代码代码翻译:深圳相遇,至死不渝代码:-module(you_and_me)-export([start/1])-record(person,{name,address,status})start(Name)-one_world(Name)one_world(Name)keep_to_love_you(Person)say_goodbye(Person)-io:format(~p:seeyounextworld!~n,[Person#personname])see_you_next_world(Name)-one_world(Name) 第五条语言:Java语言代码翻译:爱你到天荒地老代码:while(!worlddestroy){Systemoutprintln(iloveyou);} 表白代码大全可复制免费3  第一条 语言:Java 代码翻译: 直到死之前,每天爱你多一点 代码: while (life < end) { love++; } // I can not say Hello to the World without u  第二条 语言:python 代码翻译: 山无陵, 江水为竭, 冬雷震震, 夏雨雪, 天地合, 乃敢与君绝! 代码: if(mountainarris==None): if(riverwater==None): if(winterthunder==True): if(summersnow==True): if(skyheight==groundheight): iwithyou=False else: iwithyou=True one_world(Name)  第三条 语言:Java语言 代码翻译: 爱你到天荒地老 代码: while(!worlddestroy){ Systemoutprintln("i love you"); }  第四 条 语言:C语言 代码翻译: 两隔的`世界; 无名的信件; 短暂的停留; 长久的记忆; 说这么多,只是想说:我想你了。 代码: #include int main() { double world; unsigned letter; short stay; long memories; printf("I miss you "); return 0; }

欢迎分享,转载请注明来源:表白网

原文地址:https://h5.hunlipic.com/biaobai/2816320.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2024-01-14
下一篇2024-01-14

发表评论

登录后才能评论

评论列表(0条)

    保存