1.编写并测试一个代表地址的Address类,地址信息由国家、省份、城市、街道、邮编组成,并可以返回完整的地址信息。

//=================================================
// File Name : Address_demo
//------------------------------------------------------------------------------
// Author : Common // 内部类名:Address
// 属性:
// 方法:
class Address{
private String country; //定义国家
private String province; //定义省份
private String city; //定义城市
private String street; //定义街道
private String zipcode; //定义邮编 public Address(String country,String province,String city,String street,String zipcode){ //构造方法设置地址
this.country = country;
this.province = province;
this.city = city;
this.street = street;
this.zipcode = zipcode;
} public String getCountry(){
return this.country;
} public void setCountry(String country) {
this.country = country;
} public String getProvince() {
return this.province;
} public void setProvince(String province) {
this.province = province;
} public String getCity() {
return this.city;
} public void setCity(String city) {
this.city = city;
} public String getStreet() {
return this.street;
} public void setStreet(String street) {
this.street = street;
} public String getZipcode() {
return this.zipcode;
} public void setZipcode(String zipcode) {
this.zipcode = zipcode;
} public void print(){ //1.定义全部输出方法
System.out.println("国家"+this.country+"\n"+"省份"+this.province+"\n"+"城市"+this.city+"\n"+"街道"+this.street+"\n"+"邮编"+this.zipcode);
}
} //主类
//Function : Address
public class Address_demo { public static void main(String[] args) {
// TODO 自动生成的方法存根
Address add = new Address("中国","福建","涵江","中山路","351111");
add.print();
} }

2.定义并测试一个代表员工的employee类。员工属性包括“编号”、“姓名”、“基本薪水”、“薪水增长额”,还包括计算薪水增长额及计算增长后的工资总额的操作方法

//=================================================
// File Name : Employee_demo
//------------------------------------------------------------------------------
// Author : Common // 类名:Employee
// 属性:
// 方法:
class Employee{
private String id;
private String name;
private int basic_Salary;
private int growth_Salary; public Employee(String id, String name, int basic_Salary, int growth_Salary) {
this.id = id;
this.name = name;
this.basic_Salary = basic_Salary;
this.growth_Salary = growth_Salary;
} public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getBasic_Salary() {
return basic_Salary;
}
public void setBasic_Salary(int basic_Salary) {
this.basic_Salary = basic_Salary;
}
public int getGrowth_Salary() {
return growth_Salary;
}
public void setGrowth_Salary(int growth_Salary) {
this.growth_Salary = growth_Salary;
} public void print(){
System.out.println("员工编号"+this.id+"\n"+"员工姓名"+this.name+"\n"+"基本工资"+this.basic_Salary+"\n"+"奖金"+this.growth_Salary+"\n"+"总额"+(this.basic_Salary+this.growth_Salary));
} } //主类
//Function : Employee
public class Employee_demo { public static void main(String[] args) {
// TODO 自动生成的方法存根
Employee emp = new Employee("1", "Jack", 10000, 5000);
emp.print();
} }

编写程序,统计处字符串“want you to know one thing”中字母n和字母o的出现次数

//=================================================
// File Name : string_Count_demo
//------------------------------------------------------------------------------
// Author : Common // 类名:string_Count
// 属性:
// 方法:
class string_Count{
private int num;
private char str[];
private char c; public string_Count(String str,char c){
this.str = str.toCharArray();
this.c = c;
} public void print(){
for(int i=0;i<this.str.length;i++){
if(str[i] == this.c){
this.num++;
}
}
System.out.println("有"+this.c+"的个数为:"+this.num+"\n");
this.num = 0; //对num清零
} } //主类
//Function : string_Count
public class string_Count_demo { public static void main(String[] args) {
// TODO 自动生成的方法存根
string_Count demo = new string_Count("want you to know one thing",'n');
demo.print();
string_Count demo_ = new string_Count("want you to know one thing",'o');
demo_.print();
} }

设计一个表示用户的user类,类中的变量有用户名/口令和记录用户个数的变量,定义类的3个构造方法(无参、为用户名赋值、为用户名和口令赋值)、获取和设置口令的方法和返回类信息的方法

//=================================================
// File Name : User_demo
//------------------------------------------------------------------------------
// Author : Common // 类名:user
// 属性:
// 方法:
class user{
private String name;
private String pwd;
private static int user_num; //声明成static的时候产生多个对象的时候,修改一个对象就行修改所有的对象 public user() { //构造方法无参
user_num++; //用静态方式访问
} public user(String name) { //构造方法,为用户名赋值
this.name = name;
user_num++;
} public user(String name, String pwd) { //构造方法,为用户名和口令赋值
this.name = name;
this.pwd = pwd;
user_num++;
} public String getPwd() {
return this.pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
} public void print(){
System.out.println("用户名:"+this.name+"\n"+"密码:"+this.pwd+"\n"+"用户个数"+user_num);
} } //主类
//Function : user
public class User_demo { public static void main(String[] args) {
// TODO 自动生成的方法存根
user zhangsan = new user();
zhangsan.print();
user lisi = new user("李四");
lisi.print();
user wangwu = new user("王五","12345");
wangwu.print();
wangwu.setPwd("12345678");
System.out.println("password:"+wangwu.getPwd());
wangwu.print();
} }

字符串操作

//=================================================
// File Name : String_operation_demo
//------------------------------------------------------------------------------
// Author : Common public class String_operation_demo { public static void main(String[] args) {
// TODO 自动生成的方法存根
String str = "Java技术学习班 20070326";
System.out.println(str.substring(11)); String str1 = "MLDN JAVA";
String str2 = str1.replace("JAVA", "J2EE");
System.out.println(str2); System.out.println(str.charAt(8)); System.out.println(str.replace("0", "")); System.out.println(str.replace(" ", "")); String str3 = "350101199302147777";
System.out.println("birthday:"+str3.substring(6, 14));
} }

编写一个公司员工类

//=================================================
// File Name : Cooperation_employee_demo
//------------------------------------------------------------------------------
// Author : Common // 类名:Cooperation_employee
// 属性:
// 方法:
class Cooperation_employee{
private String id;
private String name;
private int salary;
private String department; public Cooperation_employee(){ //无参 } public Cooperation_employee(String id){ //单参
this.id = id;
this.name = "无名氏";
this.salary = 0;
this.department = "未定";
} public Cooperation_employee(String id,String name){ //双参
this.id = id;
this.name = name;
this.salary = 1000;
this.department = "后勤";
} public Cooperation_employee(String id,String name,int salary,String department){ //4参
this.id = id;
this.name = name;
this.salary = salary;
this.department = department;
} public void print(){
System.out.println("员工号"+this.id+"\n"+"姓名"+this.name+"\n"+"薪水"+this.salary+"\n"+"部门"+this.department);
}
} public class Cooperation_employee_demo { public static void main(String[] args) {
// TODO 自动生成的方法存根
Cooperation_employee no_1 = new Cooperation_employee();
no_1.print();
Cooperation_employee no_2 = new Cooperation_employee("001");
no_2.print();
Cooperation_employee no_3 = new Cooperation_employee("001","张三");
no_3.print();
Cooperation_employee no_4 = new Cooperation_employee("002","李四",1000,"开发");
no_4.print();
} }

声明一个图书类、其数据成员位书名、编号(利用静态变量实现自动编号)、书价,并拥有静态数据成员册数、记录图书的总册数,在构造方法中利用此静态变量为对象的编号赋值,在主方法中定义对象数组,并求出总册数

//=================================================
// File Name : book_demo
//------------------------------------------------------------------------------
// Author : Common // 类名:book
// 属性:
// 方法:
class book{
private String name;
private String id;
private double price;
private static int count; public book(String name,double price){
count++;
this.name = name;
this.price = price;
this.id = "000"+count;
} public void print(){
System.out.println("书名:"+this.name+"\n"+"ID:"+this.id+"\n"+"价格:"+this.price+"\n"+"书的总数"+count);
} } public class book_demo { public static void main(String[] args) {
// TODO 自动生成的方法存根
book[] book_array = new book[10];
for(int i=0;i<book_array.length;i++){
book_array[i] = new book("JAVA编程思想",19.8);
}
book_array[1].print();
} }

JAVA 5.17习题的更多相关文章

  1. Java SE 17 新增特性

    Java SE 17 新增特性 作者:Grey 原文地址:Java SE 17 新增特性 源码 源仓库: Github:java_new_features 镜像仓库: GitCode:java_new ...

  2. Java Hour 17 来个CURD吧(二)

    有句名言,叫做10000小时成为某一个领域的专家.姑且不辩论这句话是否正确,让我们到达10000小时的时候再回头来看吧. 突然想到我最近一直在追的小说,作者每天都会更新两章,而且质量挺高.所以从这篇开 ...

  3. JAVA进阶17

    ---恢复内容开始--- 间歇性混吃等死,持续性踌躇满志系列-------------第17天 1.递归结构 递归是一种常见的解决问题的方法,即把问题逐渐简单化.递归的基本思想就是自己就是“自己调用自 ...

  4. JAVA多线程17个问题

    1.Thread 类中的start() 和 run() 方法有什么区别? Thread.start()方法(native)启动线程,使之进入就绪状态,当cpu分配时间该线程时,由JVM调度执行run( ...

  5. Java程序设计17——多线程-Part-A

    1 多线程 1.1 简介 大部分时候,我们编写的程序都是单线程的.也就是都只有一条顺序执行流:程序从main方法开始执行,依次向下执行每行代码,如果程序执行某行代码遇到了阻塞,则程序会停滞在该处.如果 ...

  6. Java程序设计17——多线程-Part-B

    5 改变线程优先级 每个线程执行都具有一定的优先级,优先级高的线程获得较多的执行机会,而优先级低的线程则获得较少的执行机会. 每个线程默认的优先级都与创建它的父线程具有相同的优先级,在默认情况下,ma ...

  7. Java程序设计17——多线程-Part-C

    11 使用管道流 前面介绍的两种方式与其称为线程之间的通信,还不如称为线程之间协调运行的控制策略.如果需要在两条线程之间进行更多的信息交互,则可以考虑使用管道流进行通信. 管道流有3中存在形式:Pip ...

  8. 《Think in Java》17~18

    chapter 17 容器深入研究 填充容器 package cn.test; import java.util.ArrayList; import java.util.Collections; im ...

  9. java核心技术 - 17个重要的知识点

    1.Java中没有多继承,而是用接口来代替多继承 2.运行一个已经编译的程序时,Java解释器总是从指定类的main方法中的代码开始执行,因此,执行代码中必须有一个main函数. 3.Java是典型的 ...

随机推荐

  1. jquery渐渐的显示、隐藏效果

    <!DOCTYPE html> <html> <head> <meta charset="gb2312" /> <title& ...

  2. 使用D3绘制图表(3)--添加坐标轴和文本标签

    上一篇是曲线的绘制,这样仅仅只是有一条线,完全先是不出数据想要表现的内容,于是我们要添加坐标系,添加坐标系和画线类似. 1.还是没有变化的html页面 <!DOCTYPE html> &l ...

  3. Android中图片的处理(放大缩小,去色,转换格式,增加水印等)(转)

    原文地址:http://menxu.lofter.com/post/164b9d_3ebf79 package com.teamkn.base.utils; import java.io.ByteAr ...

  4. 95C

    跑dijiestra每个点的最短路径 #include<iostream> #include<Vector> #include<cstring> #include& ...

  5. mysql-删除日志文件命令详解

    装载 在mysql中会生大量的如mysq-bin.000001这类日志文件了,这些都是二进制文件了,如果我们是普通的日志没有进行主从配置就可以直接使用reset master进行删除了这个方法很简单, ...

  6. cygwin-使用介绍

    cygwin使用: 使用上的方便性很是不错,启动Cygwin以后,会在Windows下得到一个Bash Shell,由于Cygwin是以Windows下的服务运行的,所以很多情况下和在Linux下有很 ...

  7. Ext-设置form表单不可编辑

    1. var formEach = win.down('form').items.items; Ext.each(formEach,function(item){ console.log(item); ...

  8. VS2015 安装mvc4安装包以及vs2010 sp1后导致Razor语法失效代码不高亮(能正常运行)/视图页面无法智能提示(.cshtml)解决办法

    VS2015默认asp.net mvc 版本为5.0以上,默认不支持创建5.0以下的版本.所以想要使用mvc 4.0只能单独安装.在网上搜了几篇教程后在微软官网下载了Visual Studio 201 ...

  9. 【Codeforces 707C】Pythagorean Triples(找规律)

    一边长为a的直角三角形,a^2=c^2-b^2.可以发现1.4.9.16.25依次差3.5.7.9...,所以任何一条长度为奇数的边a,a^2还是奇数,那么c=a^2/2,b=c+1.我们还可以发现, ...

  10. bzoj4401: 块的计数

    首先,块的大小确定的话,可以发现方案最多只有1种 然后就可以O(nsqrt(n))搞,不过会TLE 接着我们又发现,一个节点可以作一个块的根,当且仅当该节点的size能被块的大小整除 然后就可以O(n ...