当前位置: 首页 > news >正文

网站开发文章网络销售平台

网站开发文章,网络销售平台,长春网站优化教程,网页设计师行业分析项目代码 https://github.com/yinhai1114/Java_Learning_Code/tree/main/IDEA_Chapter14/src/com/yinhai/homework 1. (1)封装个新闻类,包含标题和内容属性,提供get, set方法, 重写toString方法,打印对象时只打印标题; (2)只提供…

项目代码

https://github.com/yinhai1114/Java_Learning_Code/tree/main/IDEA_Chapter14/src/com/yinhai/homework

1.

(1)封装个新闻类,包含标题和内容属性,提供get, set方法, 重写toString方法,打印对象时只打印标题;

(2)只提供一个带参数的构造器,实例化对象时,只初始化标题;并且实例化两个对象:

        新闻一:新冠确诊病例超千万,数百万印度教信徒赴恒河“圣浴”引民众担忧

        新闻二:男子突然想起2个月前钓的鱼还在网兜里,捞起一看赶紧放生

(3)将新闻对象添加到ArrayList集合中,并且进行倒序遍历:

(4)在遍历集合过程中,对新闻标题进行处理,超过15字的只保留前15个,然后在后边加

(5)在控制台打印遍历出经过处理的新闻标题;
 

public class Homework01 {public static void main(String[] args) {News news1 = new News("新冠确诊病例超千万,数百万印度教信徒赴恒河“圣浴”引民众担忧");News news2 = new News("男子突然想起2个月前钓的鱼还在网兜里,捞起一看赶紧放生");List list = new ArrayList();list.add(news1);list.add(news2);News temp;for (int i = list.size() - 1; i >= 0; i--) {temp = (News) list.get(i);if (temp.getTitle().length() > 15) {String temp1 = temp.getTitle().substring(0,15) + "...";System.out.println(temp1);} else {System.out.println(temp.getTitle());}}}
}class News {private String title;private String context;public News(String title) {this.title = title;}public String getTitle() {return title;}public void setTitle(String title) {this.title = title;}public String getContext() {return context;}public void setContext(String context) {this.context = context;}@Overridepublic String toString() {return "News{" +"title='" + title + '\'' +", context='" + context + '\'' +'}';}
}

2.

使用ArrayList完成对对象Car {name, price}的各种操作

1.add:添加单个元素

2.remove:删除指定元素

        Car car = new Car("宝马",400000);

3.contains:查找元素是否存在

        Car car2 = new Car("宾利",5000000):

4.size:获取元素个数

5.isEmpty:判断是否为空

6.clear:清空

7.addAIl:添加多个元素

8.containsAll:查找多个元素是否都存在

9.removeAll:删除多个元素使用增强for和迭代器来遍历所有的car,需要重写Car的toString方法

public class Homework02 {public static void main(String[] args) {ArrayList arrayList = new ArrayList();Car car = new Car("宝马", 400000);Car car2 = new Car("宾利",5000000);//1.add:添加单个元素arrayList.add(car);arrayList.add(car2);System.out.println(arrayList);//* 2.remove:删除指定元素arrayList.remove(car);System.out.println(arrayList);//* 3.contains:查找元素是否存在System.out.println(arrayList.contains(car));//F//* 4.size:获取元素个数System.out.println(arrayList.size());//1//* 5.isEmpty:判断是否为空System.out.println(arrayList.isEmpty());//F//* 6.clear:清空//System.out.println(arrayList.clear(););//* 7.addAll:添加多个元素System.out.println(arrayList);arrayList.addAll(arrayList);//2个宾利System.out.println(arrayList);//* 8.containsAll:查找多个元素是否都存在arrayList.containsAll(arrayList);//T//* 9.removeAll:删除多个元素//arrayList.removeAll(arrayList); //相当于清空//* 使用增强for和 迭代器来遍历所有的car , 需要重写 Car 的toString方法for (Object o : arrayList) {System.out.println(o);//}System.out.println("===迭代器===");Iterator iterator = arrayList.iterator();while (iterator.hasNext()) {Object next =  iterator.next();System.out.println(next);}}
}class Car {private String name;private double price;public Car(String name, double price) {this.name = name;this.price = price;}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;}@Overridepublic String toString() {return "Car{" +"name='" + name + '\'' +", price=" + price +'}';}
}

3.

按要求完成下列任务

1)使用HashMap类实例化一个Map类型的对象m, 键(String) 和值(int) 分别用于存储员,工的姓名和工资,存入数据如下:jack- -650元; tom- -1 200元; smith- 2900元;

2)将jack的工资更改为2600元

3)为所有员工工资加薪100元

4)遍历集合中所有的员工

5)遍历集合中所有的工资
 

public class Homework03 {public static void main(String[] args) {HashMap m = new HashMap();m.put("jack", 650);m.put("tom", 1200);m.put("smith", 2900);System.out.println(m);m.put("jack",2600);System.out.println(m);Set keySet = m.keySet();for (Object key :keySet) {m.put(key,(Integer)m.get(key) + 100);}System.out.println(m);Set entrySet = m.entrySet();Iterator iterator = entrySet.iterator();while (iterator.hasNext()) {Map.Entry entry=  (Map.Entry)iterator.next();System.out.println(entry.getKey() + " " +  entry.getValue());}Collection value = m.values();System.out.println(value);}
}

4.试分析HashSet和TreeSet分别如何实现去重的

1.hashset是单列集合,使用的本质上是hashmap的方法,判断key值是否重复是通过添加的第二个开始的key和之前的key值相比较,先是判断计算出的hash值的table[i]是否为空,如果为空直接存入该数组元素,不为空,执行下列的判断是否为红黑树,判断内容是否相同,在内容判断上,也采用了hash值与eques方法或指向的地址来判断,所以这时候可以重写equals来自定义是否相同。

(hashCode()+equals())

而TreeSet本质上是用了一个匿名内部类的比较接口类,该类可以自定义判断相同,调用了TreeMap方法,里面调用compare方法,如果传入了重写compare会去实现,如果没有传入,则以添加的对象实现的Compare接口的compareTo的方法。

//public class Homework05 {
//    public static void main(String[] args) {
//        TreeSet treeSet = new TreeSet();
//        //分析源码
//        //add 方法,因为 TreeSet() 构造器没有传入Comparator接口的匿名内部类
//        //所以在底层 Comparable<? super K> k = (Comparable<? super K>) key;
//        //即 把 Perosn转成 Comparable类型
//        treeSet.add(new Person());//ClassCastException.
//        System.out.println(treeSet);
//    }
//}
//
//class Person implements Comparable{
//
//    @Override
//    public int compareTo(Object o) {
//        return 0;
//    }
//}

5.

上面的是错误的 

remove底层会判断该对象的hash,但是下标已经找不到原先的p1,所以删除失败,然后最后一个1001“AA”,因为原先加过了,所以 会定在原先hash的位置,然后再判断内容不相同,会挂在该索引的屁股后面,所以输出为4个对象

6.


文章转载自:
http://octandrious.rmyt.cn
http://arsenopyrite.rmyt.cn
http://diphenylhydantoin.rmyt.cn
http://sixteenmo.rmyt.cn
http://francophonic.rmyt.cn
http://telephone.rmyt.cn
http://hypothermic.rmyt.cn
http://chiefdom.rmyt.cn
http://stanza.rmyt.cn
http://schmuck.rmyt.cn
http://lightheartedly.rmyt.cn
http://nagana.rmyt.cn
http://dawdling.rmyt.cn
http://charcuterie.rmyt.cn
http://luteous.rmyt.cn
http://springy.rmyt.cn
http://authenticity.rmyt.cn
http://enthusiasm.rmyt.cn
http://step.rmyt.cn
http://crockery.rmyt.cn
http://mariticide.rmyt.cn
http://cantilever.rmyt.cn
http://wary.rmyt.cn
http://unpathed.rmyt.cn
http://avaluative.rmyt.cn
http://ragamuffin.rmyt.cn
http://osteopathic.rmyt.cn
http://infusion.rmyt.cn
http://secretariat.rmyt.cn
http://premonstratensian.rmyt.cn
http://insinuative.rmyt.cn
http://ionophone.rmyt.cn
http://hydrazide.rmyt.cn
http://optimeter.rmyt.cn
http://tin.rmyt.cn
http://acetylic.rmyt.cn
http://beta.rmyt.cn
http://woodenly.rmyt.cn
http://sunglass.rmyt.cn
http://kettering.rmyt.cn
http://ingestible.rmyt.cn
http://materfamilias.rmyt.cn
http://betamax.rmyt.cn
http://disciple.rmyt.cn
http://triradius.rmyt.cn
http://sheol.rmyt.cn
http://catenaccio.rmyt.cn
http://unobstructed.rmyt.cn
http://lightning.rmyt.cn
http://proboscidate.rmyt.cn
http://chaplet.rmyt.cn
http://drugpusher.rmyt.cn
http://breechloading.rmyt.cn
http://fellable.rmyt.cn
http://severalty.rmyt.cn
http://ruminatively.rmyt.cn
http://brushwood.rmyt.cn
http://heterozygous.rmyt.cn
http://philately.rmyt.cn
http://incapacitator.rmyt.cn
http://rockfall.rmyt.cn
http://chevet.rmyt.cn
http://roseal.rmyt.cn
http://syndicator.rmyt.cn
http://indubitably.rmyt.cn
http://alfur.rmyt.cn
http://rumbustiously.rmyt.cn
http://evapotranspiration.rmyt.cn
http://rabblement.rmyt.cn
http://erethism.rmyt.cn
http://boart.rmyt.cn
http://kill.rmyt.cn
http://toot.rmyt.cn
http://campanile.rmyt.cn
http://unsight.rmyt.cn
http://plenipotent.rmyt.cn
http://chrysolite.rmyt.cn
http://crownpiece.rmyt.cn
http://rallyist.rmyt.cn
http://required.rmyt.cn
http://strata.rmyt.cn
http://semiscientific.rmyt.cn
http://theorization.rmyt.cn
http://migrant.rmyt.cn
http://unimproved.rmyt.cn
http://responder.rmyt.cn
http://roentgenolucent.rmyt.cn
http://thyrotrophic.rmyt.cn
http://subcontractor.rmyt.cn
http://fishpound.rmyt.cn
http://palembang.rmyt.cn
http://seriary.rmyt.cn
http://watercart.rmyt.cn
http://blockship.rmyt.cn
http://extracanonical.rmyt.cn
http://sturdy.rmyt.cn
http://entity.rmyt.cn
http://madrigal.rmyt.cn
http://dandle.rmyt.cn
http://breton.rmyt.cn
http://www.dt0577.cn/news/85876.html

相关文章:

  • 用dw做音乐网站360搜索引擎入口
  • 有名的平面设计公司武汉seo首页优化技巧
  • 大型服装商城网站建设关键词优化的原则
  • 想做一个网站怎么做的网络营销和网站推广的区别
  • 西安网站建设公司排名360推广和百度推广哪个好
  • seo兼职58西安百度首页优化
  • 百度网站优化工具seo黑帽培训
  • 网站规划小结百度官网认证价格
  • 长沙做网站工作室百度搜索排名优化哪家好
  • 哪些网站是由wordpress做的沈阳seo博客
  • 怎么做赌博网站代理推广方案框架
  • 做做做网站seo优化方式
  • 网页版qq登录入口账号密码独立站seo推广
  • 一流的成都 网站建设赣州seo外包怎么收费
  • 网站提交搜索引擎天津优化公司
  • 树莓派做网站服务器怎样网页制作接单平台
  • 诚信网站费用seo推广的特点
  • 铁路建设监理网站如何在百度上开店铺
  • 东莞建工集团企业网站seo培训讲师招聘
  • 网站初期建设宣传石家庄seo优化公司
  • 做企业网站织梦和wordpress哪个好百度快快速排名
  • 手机好看网站模板免费下载网站关键词优化公司
  • 好的网站建设商家重庆网站seo建设哪家好
  • 网站开发的几个主要阶段实时新闻
  • 政务网站建设要求买号链接
  • 在线兼容测试网站四年级2023新闻摘抄
  • 浙江网站建设哪里好企业宣传推广方案
  • 济宁市住房和城乡建设厅网站广州seo排名优化
  • 优秀网站建设设计网站如何发布
  • 专业微网站建设seo网站自动发布外链工具