给丁丁的复习宝典

/**
1、定义一个整型的长度为5 x 4的二维数组k[5][4],并将数组中元素k[i][j] 值初始化为值i x j。然后,将元素k[2][3]打印出来。(本题8分)
*/
package cn.itcase.kaoshi;
public class test1 {
	public static void main(String[] args){
		int[][] k=new int[6][5];
		for(int i=1;i<=5;i++){
			for(int j=1;j<=4;j++){
				k[i][j]=i*j;
			}
		}
		System.out.println(k[2][3]);
	}
}


//创建二维数组 int[][] k=new int[6][5];
/**
2.从命令行输入几个字符串,统计并打印出输入字符串的个数、以及各字符串的字符个数。(提示:args.length / args[k].length() )
*/
public class test1{
	public static void main(String[] args){
		int n=args.length;
		System.out.println("字符串的个数是"+n);
		for(int i=0;i<n;i++){
			System.out.println("第"+(i+1)+"个字符串的长度为"+args[i].length());
		}
	}
}


//字符串的个数 args.length
//每个字符串的长度 args[i].length()
/**
3、编程:从键盘读取星号数,采用循环语句打印如下图形。如:从键盘输入10,则星号排列最大数是10。注意星号数每行需要为奇数。(本题12分)
*/
import java.util.Scanner;
public class test1{
	public static void main(String[] args){
		Scanner input=new Scanner(System.in);
		int n=input.nextInt();
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n-i;j++){
				System.out.print(" ");
			}
			for(int j=1;j<=2*i-1;j++){
				System.out.print("*");
			}
			System.out.println();
		}
	}
}

//import java.util.Scanner; 
//Scanner input=new Scanner(System.in);
//注意每一行之前有空行
//注意每一行后有回车
/**
4、编程:从键盘读取星号数,采用循环语句打印如下图形。如:从键盘输入10,则星号排列最大数是10。(12分)
*/

import java.util.Scanner;
public class test1{
	public static void main(String[] args){
		Scanner input=new Scanner(System.in);
		int n=input.nextInt();
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n-i;j++){
				System.out.print(" ");
			}
			for(int j=1;j<=i;j++){
				System.out.print("*");
			}
			System.out.println();
		}
	}
}
/**
5、在com.graphic包中定义一个圆柱体类Cylinder,其半径r,高h都为私有属性,有构造方法和求体积的方法volume()。在com.test包中定义一个测试类test,测试一个半径为5.34、高为2的圆柱体体积。(计算时π的值可以用Math.PI, 圆柱体体积公式为π*r *r *h)
*/
package com.graphic;
public class Cylinder {
	private double r;
	private double h;
	public Cylinder(double r,double h){
		this.r=r;
		this.h=h;
	}
	public double volume(){
		return Math.PI*r*r*h;
	}
}

package com.test;
import com.graphic.Cylinder;
public class test {
	public static void main(String[] args){
		Cylinder c=new Cylinder(5.34,2);
		System.out.println(c.volume());
	}
}

//用double
//import com.graphic.Cylinder;
/**
6、首先定义一个计算二维坐标系中圆面积的类CircleClass,要求类中有一个定义圆心座标,圆上一点座标的构造函数,以及一个通过圆上一点座标与圆心座标计算圆面积的方法area。然后,通过上述类生成两个圆对象circle1、circle2进行测试:一个圆心、圆上一点座标分别为(0,0)、(8.5,9),另一个圆心、圆上一点座标分别为(2,3.5)、(9,6),并分别显示各自面积。 (计算时π的值可以用Math.PI)
*/

package timu6;
public class test {
	public static void main(String[] args){
		CircleClass c1=new CircleClass(0,0,8.5,9);
		CircleClass c2=new CircleClass(2,3.5,9,6);
		System.out.println(c1.area());
		System.out.println(c2.area());
	}
}
class CircleClass {
	private double x0,y0,x,y;
  	public CircleClass(double x0,double y0,double x,double y){
  		this.x0=x0;
  		this.y0=y0;
  		this.x=x;
  		this.y=y;
  	}
  	public double area(){
  		return Math.PI*Math.sqrt((x-x0)*(x-x0)+(y-y0)*(y-y0));
  	}
}


//构造函数括号里不要忘记写变量类型
//可以直接放在同一个类里面 但是只有一个public(test那个)
/**
7、设计一个学生抽象类Student,其数据成员有name(姓名)、age(年龄)和degree(学位),以及一个抽象方法show()。然后由Student类派生出本科生类Undergraduate和研究生类Graduate,本科生类Undergraduate增加成员specialty(专业),研究生类增加成员direction(研究方向)。并且每个类都有show()方法,用于输出数据成员信息。最后请定义几个对象“张三”、“李四”、“王五”、“刘六”及其属性,并打印输出下列信息:(本题18分)
张三:20,本科,通信专业
李四:21,本科,电子专业
王五:25,硕士,无线通信
刘六:32,博士,光纤通信
*/

public class test1{ 
	public static void main(String[] args){
		Undergraduate s1=new Undergraduate("张三",20,"本科","通信专业");
		Undergraduate s2=new Undergraduate("李四",21,"本科","电子专业");
		Graduate s3=new Graduate("王五",25,"硕士","无线通信");
		Graduate s4=new Graduate("刘六",32,"博士后","光纤通信");
		s1.show();
		s2.show();
		s3.show();
		s4.show();
	}
}

abstract class Student {
	String name,degree;
	int age;
	public Student(String name,int age,String degree){
		this.name=name;
		this.age=age;
		this.degree=degree;
	}
	public abstract void show();
}

class Undergraduate extends Student{
	private String specialty;
	public Undergraduate(String name,int age,String degree,String specialty){
		super(name,age,degree);
		this.specialty=specialty;
	}
	public void show(){
		System.out.println(name+":"+age+","+degree+","+specialty);
	}
}

class Graduate extends Student{
	private String direction;
	public Graduate(String name,int age,String degree,String direction){
		super(name,age,degree);
		this.direction=direction;
	}
	public void show(){
		System.out.println(name+":"+age+","+degree+","+direction);
	}
}

//抽象类内不用private
//子类里的构造函数要用super
/**
8、设计一个Shape接口和它的两个实现类Square和Circle,要求如下:1)Shape接口中有一个抽象方法,方法名字是area,方法接收一个double类型的参数,返回一个double类型的结果。2)Square和Circle中实现了Shape接口,分别求正方形和圆形的面积并返回。在测试类中创建Square和Circle类的对象,计算边长为2的正方形面积和半径为3的圆面积。
*/

public class test1{
	public static void main(String[] args){
		Square s1=new Square(2);
		Circle s2=new Circle(3);
		System.out.println(s1.area(2));
		System.out.println(s2.area(3));
	}
}

interface Shape{
	double area(double x);
}

class Square implements Shape{
	double bc;
	public Square(double bc){
		this.bc=bc;
	}
	public double area(double x){
		return x*x;
	}
}

class Circle implements Shape{
	double r;
	public Circle(double r){
		this.r=r;
	}
	public double area(double x){
		return Math.PI*x*x;
	}
}

//用的是接口 interface Shape
//子类用 implements Shape
/**
9、定义一个接口RectangleInterface,要求接口中定义长方形的求面积的抽象方法void rectArea()和求周长的抽象方法void rectLen()。类RectangleClass实现该接口,并定义两个参数分别为长方形的长和宽的构造方法。通过上述RectangleClass类生成两个长宽分别为(7.8,4.5)和(10.1,2.8)的长方形对象rectangle1, rectangle2,并计算和打印出他们的面积和周长。
*/

public class test1{
	public static void main(String[] args){
		RectangleClass r1=new RectangleClass(7.8,4.5);
		RectangleClass r2=new RectangleClass(10.1,2.8);
		r1.rectArea();
		r1.rectLen();
		r2.rectArea();
		r2.rectLen();
	}
}

interface RectangleInterface{
	public void rectArea();
	public void rectLen();	
}

class RectangleClass implements RectangleInterface{
	double x,y;
	public RectangleClass(double x,double y){
		this.x=x;
		this.y=y;
	}
	public void rectArea(){
		System.out.println(x*y);
	}
	public void rectLen(){
		System.out.println(2*(x+y));
	}
}
/**
10、对字符串“23 10 -8 0 3 7 108”中的数值进行升序排序,生成一个数值有序的字符串 “-8 0 3 7 10 23 108”。
*/
import java.util.*;
public class test1{
	public static void main(String[] args){
		String a="23 10 -8 0 3 7 108";
		String[] b=a.split(" ");
		int[] c=new int[b.length];
		for(int i=0;i<b.length;i++){
			c[i]=Integer.parseInt(b[i]);
		}
		Arrays.sort(c);
		String ans="";
		ans=ans+c[0];
		for(int i=1;i<b.length;i++){
			ans=ans+" "+c[i];
		}
		System.out.println(ans);
	}
}
//数组排序要用到 import java.util.*;
//字符串分开到数组 String[] b=a.split(" ");
//c[i]=Integer.parseInt(b[i]); 字符变成数字
/**
11、编写程序统计一个字符子串在一个字符串中出现的次数和位置。打印子字符串“nba”在字符串“asfasfnabaasdfnbasdnbasnbasdnbadfasdf”中出现的次数和出现的位置。
*/

public class test1{
	public static void main(String[] args){
		String s1="nba";
		String s2="asfasfnabaasdfnbasdnbasnbasdnbadfasdf";
		int cnt=0;
		for(int i=0;i<s2.length()-s1.length();i++){
			if(s2.substring(i,i+s1.length()).equals(s1)){
				System.out.print(i+1+" ");
				cnt++;
			}
		}
		System.out.println("\n共出现了"+cnt+"次");
	}
}
//子串相等 s2.substring(i,i+s1.length()).equals(s1)
/**
12.从命令行输入一个数字,判断它是奇数还是偶数。(提示:利用%;三元条件 或 if/else ; int a=Integer.parseInt(args[0])  //数据输入)  
*/
public class test1{
	public static void main(String[] args){
		int n=Integer.parseInt(args[0]);
		if(n%2==0) System.out.println(n+"是偶数");
		else System.out.println(n+"是奇数");
	}
}
//获取命令行数字 int n=Integer.parseInt(args[0]);
/**
13.从命令行输入两个数字,判断两个数谁大谁小。(提示:读输入参数args[];三元条件 或 if/else )
*/

public class test1{
	public static void main(String[] args){
		int n=Integer.parseInt(args[0]);
		int m=Integer.parseInt(args[1]);
		if(n>m) System.out.println(n+">"+m);
		else if(n<m) System.out.println(n+"<"+m);
		else System.out.println(n+"="+m);
	}
}
/**
14. 设计二维数组,输出、处理杨辉三角形,显示10行的杨辉三角形:
*/

public class test1{
	public static void main(String args[]){
		int[][] a=new int[11][11];
		for(int i=1;i<=10;i++){
			a[i][1]=1;
			a[i][i]=1;
		}
		for(int i=3;i<=10;i++){
			for(int j=2;j<i;j++){
				a[i][j]=a[i-1][j-1]+a[i-1][j];
			}
		}
		for(int i=1;i<=10;i++){
			for(int j=1;j<=i;j++){
				if(j!=1) System.out.print(" ");
				System.out.print(a[i][j]);
			}
			System.out.println();
		}
	}
}

//先对1赋值 再对3到10行 第2列到i-1赋值
/**
15. 猜数字游戏:
编写一个猜数字游戏的程序,预先生成一个0-9的随机数,用户键盘录入一个所猜的数字,如果输入的数字和后台预先生成的数字相同,则表示猜对了,这时,程序会打印“恭喜您,答对了!”如果不相同,则比较输入的数字和后台预先生成的数字大小,如果大了,打印“sorry,您猜大了!”如果小了,打印“sorry,您猜小了!”如果一直猜错,则游戏一直继续,直到数字猜对为止。(教材任务2-2)

*/

import java.util.Scanner;
public class test1{
	public static void main(String[] args){
		int num=(int)(Math.random()*10);
		Scanner input=new Scanner(System.in);
		int n=input.nextInt();
		while(num!=n){
			if(num>n) System.out.println("sorry,您猜小了!");
			else if(num<n) System.out.println("sorry,您猜大了!");
			n=input.nextInt();
		}
		System.out.println("恭喜您,答对了!");
	}
}

//随机数 int num=(int)(Math.random()*10);
/**
17. 设计一个表示图书的Book类,它包含图书的书名、作者、月销售量等属性,另有两个构造方法(一个不带参数,另一个带参数),成员方法setBook( ) 和printBook()分别用于设置和输出书名、作者、月销售量等数据。并设计相应的测试Book类的应用程序主类,测试并显示输出提供所有功能的结果。
*/

public class test1{
	public static void main(String[] args){
		Book b=new Book("西游记","吴承恩",200);
		b.printBook();
	}
}

class Book{
	private String name,author;
	int sale;
	public Book(){}
	public Book(String name,String author,int sale){
		this.name=name;
		this.author=author;
		this.sale=sale;
	}
	public void setBook(String name,String author,int sale){
		this.name=name;
		this.author=author;
		this.sale=sale;
	}
	public void printBook(){
		System.out.println("书名"+name+" 作者"+author+" 月销量"+sale);
	}
}

// 有参和无参的构造函数
/**
public Book(){}
public Book(String name,String author,int sale){
	this.name=name;
	this.author=author;
	this.sale=sale;
}
*/
/**
18. 请创建一个银行帐户类,要求如下:(1)类包括帐户名、帐户号、存款额等属性;(2)可实现余额查询,存款和取款的操作。(3)创建该类的对象,验证以上两项。
*/

public class test1{
	public static void main(String[] args){
		Account a=new Account("abc","123",100);
		a.show();
		a.add(100);
		a.show();
		a.qu(150);
		a.show();
		a.qu(100);
		a.show();
	}
}

class Account{
	String name,id;
	double money;
	public Account(String name,String id,double money){
		this.name=name;
		this.id=id;
		this.money=money;
	}
	public void show(){
		System.out.println("余额为"+money);
	}
	public void add(double x){
		money=money+x;
	}
	public void qu(double x){
		if(money<x){
			System.out.println("余额不足,操作失败");
		}
		else money=money-x;
	}
}

//注意取款时要判断余额是否充足
/**
19. 在biology包中的animal包中有human类,它具有name,height,weight的属性,还具有eat(),sleep()和work()的行为,在biology包中的plant包中有flower类,它具有name,color,smell的属性,还具有drink()和blossom()的行为.现在在一个school包中的garden包中一个张三的人,他是一个human类的对象,种植的rose是一个flower类对象,编程实现并测试各自的方法.
*/

package school.garden;

import biology.animal.human;
import biology.plant.flower;

public class test {
	public static void main(String[] args){
		human h=new human("张三",175,55);
		flower f=new flower("rose","res","wonderful");
		h.eat();
		h.sleep();
		h.work();
		f.drink();
		f.blossom();
	}
}

package biology.animal;

public class human {
	private String name;
	double height,weight;
	public human(String name,double height,double weight){
		this.name=name;
		this.height=height;
		this.weight=weight;
	}
	public void eat(){
		System.out.println("eat");
	}
	public void sleep(){
		System.out.println("sleep");
	}
	public void work(){
		System.out.println("work");
	}
}

package biology.plant;

public class flower {
	private String name,color,smell;
	public flower(String name,String color,String smell){
		this.name=name;
		this.color=color;
		this.smell=smell;
	}
	public void drink(){
		System.out.println("drink");
	}
	public void blossom(){
		System.out.println("blossom");
	}
}

/**
20.设计一个接口circleInterface,要求接口中有一个定义PI的常量以及一个计算圆面积的空方法circleArea()。然后设计一个类circleClass实现该接口,通过构造函数circleClass(double r)定义圆半径,并增加一个显示圆面积的方法。最后,通过上述类生成两个半径分别为3.5、5.0的圆对象circle1、circle2进行测试。
*/

package cn.itcase.kaoshi;


//public class test1 {
//	public static void main(String[] args){
//		int[][] k=new int[6][5];
//		for(int i=1;i<=5;i++){
//			for(int j=1;j<=4;j++){
//				k[i][j]=i*j;
//			}
//		}
//		System.out.println(k[2][3]);
//	}
//}

//public class test1{
//	public static void main(String[] args){
//		int n=args.length;
//		System.out.println("字符的个数是"+n);
//		for(int i=0;i<n;i++){
//			System.out.println("第"+(i+1)+"个字符串的长度为"+args[i].length());
//		}
//	}
//}

//import java.util.Scanner;
//public class test1{
//	public static void main(String[] args){
//		Scanner input=new Scanner(System.in);
//		int n=input.nextInt();
//		for(int i=1;i<=n;i++){
//			for(int j=1;j<=n-i;j++){
//				System.out.print(" ");
//			}
//			for(int j=1;j<=2*i-1;j++){
//				System.out.print("*");
//			}
//			System.out.println();
//		}
//	}
//}

//import java.util.Scanner;
//public class test1{
//	public static void main(String[] args){
//		Scanner input=new Scanner(System.in);
//		int n=input.nextInt();
//		for(int i=1;i<=n;i++){
//			for(int j=1;j<=n-i;j++){
//				System.out.print(" ");
//			}
//			for(int j=1;j<=i;j++){
//				System.out.print("*");
//			}
//			System.out.println();
//		}
//	}
//}



///777777777777777777777777777777777777
//public class test1{ 
//	public static void main(String[] args){
//		Undergraduate s1=new Undergraduate("张三",20,"本科","通信专业");
//		Undergraduate s2=new Undergraduate("李四",21,"本科","电子专业");
//		Graduate s3=new Graduate("王五",25,"硕士","无线通信");
//		Graduate s4=new Graduate("刘六",32,"博士后","光纤通信");
//		s1.show();
//		s2.show();
//		s3.show();
//		s4.show();
//	}
//}

//abstract class Student {
//	String name,degree;
//	int age;
//	public Student(String name,int age,String degree){
//		this.name=name;
//		this.age=age;
//		this.degree=degree;
//	}
//	public abstract void show();
//}
//
//class Undergraduate extends Student{
//	private String specialty;
//	public Undergraduate(String name,int age,String degree,String specialty){
//		super(name,age,degree);
//		this.specialty=specialty;
//	}
//	public void show(){
//		System.out.println(name+":"+age+","+degree+","+specialty);
//	}
//}
//
//class Graduate extends Student{
//	private String direction;
//	public Graduate(String name,int age,String degree,String direction){
//		super(name,age,degree);
//		this.direction=direction;
//	}
//	public void show(){
//		System.out.println(name+":"+age+","+degree+","+direction);
//	}
//}


///8888888888888888888888888888888
//public class test1{
//	public static void main(String[] args){
//		Square s1=new Square(2);
//		Circle s2=new Circle(3);
//		System.out.println(s1.area(2));
//		System.out.println(s2.area(3));
//	}
//}
//
//interface Shape{
//	double area(double x);
//}
//
//class Square implements Shape{
//	double bc;
//	public Square(double bc){
//		this.bc=bc;
//	}
//	public double area(double x){
//		return x*x;
//	}
//}
//
//class Circle implements Shape{
//	double r;
//	public Circle(double r){
//		this.r=r;
//	}
//	public double area(double x){
//		return Math.PI*x*x;
//	}
//}

//99999999999999999999999
//public class test1{
//	public static void main(String[] args){
//		RectangleClass r1=new RectangleClass(7.8,4.5);
//		RectangleClass r2=new RectangleClass(10.1,2.8);
//		r1.rectArea();
//		r1.rectLen();
//		r2.rectArea();
//		r2.rectLen();
//	}
//}
//
//interface RectangleInterface{
//	public void rectArea();
//	public void rectLen();	
//}
//
//class RectangleClass implements RectangleInterface{
//	double x,y;
//	public RectangleClass(double x,double y){
//		this.x=x;
//		this.y=y;
//	}
//	public void rectArea(){
//		System.out.println(x*y);
//	}
//	public void rectLen(){
//		System.out.println(2*(x+y));
//	}
//}

10 10 10 10 10 10 10 10 10 10 10 10 10 
//import java.util.*;
//public class test1{
//	public static void main(String[] args){
//		String a="23 10 -8 0 3 7 108";
//		String[] b=a.split(" ");
//		int[]  c=new int[b.length];
//		for(int i=0;i<b.length;i++){
//			c[i]=Integer.parseInt(b[i]);
//		}
//		Arrays.sort(c);
//		String ans="";
//		ans=ans+c[0];
//		for(int i=1;i<b.length;i++){
//			ans=ans+" "+c[i];
//		}
//		System.out.println(ans);
//	}
//}

//111111111111111111111111
//public class test1{
//	public static void main(String[] args){
//		String s1="nba";
//		String s2="asfasfnabaasdfnbasdnbasnbasdnbadfasdf";
//		int cnt=0;
//		for(int i=0;i<s2.length()-s1.length();i++){
//			if(s2.substring(i,i+s1.length()).equals(s1)){
//				System.out.print(i+1+" ");
//				cnt++;
//			}
//		}
//		System.out.println("\n共出现了"+cnt+"次");
//	}
//}

//12 12 12 12 12 12 12 12 12 12 12 12 12 12
//public class test1{
//	public static void main(String[] args){
//		int n=Integer.parseInt(args[0]);
//		if(n%2==0) System.out.println(n+"是偶数");
//		else System.out.println(n+"是奇数");
//	}
//}

//13 13 13 13 13 13 13 13 13 13 13 13 13 13
//public class test1{
//	public static void main(String[] args){
//		int n=Integer.parseInt(args[0]);
//		int m=Integer.parseInt(args[1]);
//		if(n>m) System.out.println(n+">"+m);
//		else if(n<m) System.out.println(n+"<"+m);
//		else System.out.println(n+"="+m);
//	}
//}

14 14 14 14 14 14 14 14 14 14 14 14 14 14
//public class test1{
//	public static void main(String args[]){
//		int[][] a=new int[11][11];
//		for(int i=1;i<=10;i++){
//			a[i][1]=1;
//			a[i][i]=1;
//		}
//		for(int i=3;i<=10;i++){
//			for(int j=2;j<i;j++){
//				a[i][j]=a[i-1][j-1]+a[i-1][j];
//			}
//		}
//		for(int i=1;i<=10;i++){
//			for(int j=1;j<=i;j++){
//				if(j!=1) System.out.print(" ");
//				System.out.print(a[i][j]);
//			}
//			System.out.println();
//		}
//	}
//}

15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 
//import java.util.Scanner;
//public class test1{
//	public static void main(String[] args){
//		int num=(int)(Math.random()*10);
//		Scanner input=new Scanner(System.in);
//		int n=input.nextInt();
//		while(num!=n){
//			if(num>n) System.out.println("sorry,您猜小了!");
//			else if(num<n) System.out.println("sorry,您猜大了!");
//			n=input.nextInt();
//		}
//		System.out.println("恭喜您,答对了!");
//	}
//}

/17 17 17 17 17 17 17 17 17 17 17 17
//public class test1{
//	public static void main(String[] args){
//		Book b=new Book("西游记","吴承恩",200);
//		b.printBook();
//	}
//}
//
//class Book{
//	private String name,author;
//	int sale;
//	public Book(){}
//	public Book(String name,String author,int sale){
//		this.name=name;
//		this.author=author;
//		this.sale=sale;
//	}
//	public void setBook(String name,String author,int sale){
//		this.name=name;
//		this.author=author;
//		this.sale=sale;
//	}
//	public void printBook(){
//		System.out.println("书名"+name+" 作者"+author+" 月销量"+sale);
//	}
//}

/18 18 18 18 18 18 18 18 18 18 18 18
//public class test1{
//	public static void main(String[] args){
//		Account a=new Account("abc","123",100);
//		a.show();
//		a.add(100);
//		a.show();
//		a.qu(150);
//		a.show();
//		a.qu(100);
//		a.show();
//	}
//}
//
//class Account{
//	String name,id;
//	double money;
//	public Account(String name,String id,double money){
//		this.name=name;
//		this.id=id;
//		this.money=money;
//	}
//	public void show(){
//		System.out.println("余额为"+money);
//	}
//	public void add(double x){
//		money=money+x;
//	}
//	public void qu(double x){
//		if(money<x){
//			System.out.println("余额不足,操作失败");
//		}
//		else money=money-x;
//	}
//}

///20 20 20 20 20 20 20 20 20
public class test1{
	public static void main(String[] args){
		circleClass c1=new circleClass(3.5);
		circleClass c2=new circleClass(5.0);
		c1.show();
		c2.show();
	}
}

interface circleInterface{
	static final double PI=Math.acos(-1.0);
	double circleArea();
}

class circleClass implements circleInterface{
	private double r;
	public circleClass(double r){
		this.r=r;
	}
	public double circleArea() {
		return PI*r*r;
	}
	public void show(){
		System.out.println("圆的面积为"+circleArea());
	}
}

//注意计算PI  static final double PI=Math.acos(-1.0);
/**
维护有序的图书列表(注意学习并使用字符串的比较方法)
*/

package cn.itcase.chapter01;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	    Scanner input = new Scanner(System.in);
	    String[] books= new String[]{"Computer","Hibernate","Java","Struts"};
	    String[] newbook= new String[books.length+1];
	    System.out.println("插入前的数组为:Computer Hibernate Java Struts");
	    System.out.print("请输入新书名称:");
	    String book=input.next();
	    int index=0;
	    for(int i=0;i<books.length;i++){
	    	newbook[i]=books[i];
	    }
	    for(int i=0;i<books.length;i++){
	    	if(books[i].compareToIgnoreCase(book)>0){
	    		index=i;
	    		break;
	    	}
	    }
	    for(int i=newbook.length-1;i>index;i--){
	    	newbook[i]=newbook[i-1];
	    }
	    newbook[index]=book;
	    System.out.print("插入后的数组为:");
	    for(int i=0;i<newbook.length;i++){
	    	if(i!=0){
	    		System.out.print(" ");
	    	}
	    	System.out.print(newbook[i]);
	    }
	    System.out.println("\n");
    }
}


//字符串比较 books[i].compareToIgnoreCase(book)>0 
//字符串比较 compareTo( ) :不忽略大小写;
//compareToIgnoreCase( ):忽略大小写 

/**
1、角谷猜想:任何一个正整数n,如果它是偶数则除以2,如果是奇数则乘3加1,这样得到一个新的整数,如此继续进行上述处理,则最后得到的数一定是1。编写应用程序证明:在3~10000之间的所有正整数都符合上述规则。
*/

package cn.itcase.chapter01;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	    Scanner input = new Scanner(System.in);
	    int cnt=0;
	    for(int i=3;i<=10000;i++){
	    	int x=i;
	    	while(x!=1){
	    		if(x%2==0){
	    			x=x/2;
	    		}
	    		else{
	    			x=x*3+1;
	    		}
	    	}
	    	cnt++;
	    }
	    System.out.println("3-10000之间的所有正整数(共9998个)中有" + cnt + "个数符合角谷猜想");
    }
}

/**
2、编写一个模拟同时掷骰子的程序。要用Math.random()模拟产生两个骰子,将两个结果相加,相加的和等于7的可能性最大,等于2和12的可能性最小。程序模投掷3600次,判断求和的结果是否合理。
*/

package cn.itcase.chapter01;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	    Scanner input = new Scanner(System.in);
	    int[] a = new int[13];
	    for(int i=1;i<=3600;i++){
	    	int num1=(int)(Math.random()*6+1);
		    int num2=(int)(Math.random()*6+1);
		    int sum=num1+num2;
		    a[sum]++;
	    } 
	    for(int i=2;i<=12;i++){
	    	System.out.println("3600次中和为"+i+"的个数为"+a[i]);
	    }
    }
}

/**
1. 定义一个复数类complex,它的内部具有两个实例变量:realPart和imagPart,分别代表复数的实部和虚部,编程实现要求的数学运算:1)实现两个复数相加;2)实现两个复数相减;3)输出运算的结果。然后,调用上述方法实现两个复数18+2i、19-13i的相加、相减,并打印出结果。
*/

package cn.itcase.kaoshi;


//public class test1 {
//	public static void main(String[] args){
//		int[][] k=new int[6][5];
//		for(int i=1;i<=5;i++){
//			for(int j=1;j<=4;j++){
//				k[i][j]=i*j;
//			}
//		}
//		System.out.println(k[2][3]);
//	}
//}

//public class test1{
//	public static void main(String[] args){
//		int n=args.length;
//		System.out.println("字符的个数是"+n);
//		for(int i=0;i<n;i++){
//			System.out.println("第"+(i+1)+"个字符串的长度为"+args[i].length());
//		}
//	}
//}

//import java.util.Scanner;
//public class test1{
//	public static void main(String[] args){
//		Scanner input=new Scanner(System.in);
//		int n=input.nextInt();
//		for(int i=1;i<=n;i++){
//			for(int j=1;j<=n-i;j++){
//				System.out.print(" ");
//			}
//			for(int j=1;j<=2*i-1;j++){
//				System.out.print("*");
//			}
//			System.out.println();
//		}
//	}
//}

//import java.util.Scanner;
//public class test1{
//	public static void main(String[] args){
//		Scanner input=new Scanner(System.in);
//		int n=input.nextInt();
//		for(int i=1;i<=n;i++){
//			for(int j=1;j<=n-i;j++){
//				System.out.print(" ");
//			}
//			for(int j=1;j<=i;j++){
//				System.out.print("*");
//			}
//			System.out.println();
//		}
//	}
//}



///777777777777777777777777777777777777
//public class test1{ 
//	public static void main(String[] args){
//		Undergraduate s1=new Undergraduate("张三",20,"本科","通信专业");
//		Undergraduate s2=new Undergraduate("李四",21,"本科","电子专业");
//		Graduate s3=new Graduate("王五",25,"硕士","无线通信");
//		Graduate s4=new Graduate("刘六",32,"博士后","光纤通信");
//		s1.show();
//		s2.show();
//		s3.show();
//		s4.show();
//	}
//}

//abstract class Student {
//	String name,degree;
//	int age;
//	public Student(String name,int age,String degree){
//		this.name=name;
//		this.age=age;
//		this.degree=degree;
//	}
//	public abstract void show();
//}
//
//class Undergraduate extends Student{
//	private String specialty;
//	public Undergraduate(String name,int age,String degree,String specialty){
//		super(name,age,degree);
//		this.specialty=specialty;
//	}
//	public void show(){
//		System.out.println(name+":"+age+","+degree+","+specialty);
//	}
//}
//
//class Graduate extends Student{
//	private String direction;
//	public Graduate(String name,int age,String degree,String direction){
//		super(name,age,degree);
//		this.direction=direction;
//	}
//	public void show(){
//		System.out.println(name+":"+age+","+degree+","+direction);
//	}
//}


///8888888888888888888888888888888
//public class test1{
//	public static void main(String[] args){
//		Square s1=new Square(2);
//		Circle s2=new Circle(3);
//		System.out.println(s1.area(2));
//		System.out.println(s2.area(3));
//	}
//}
//
//interface Shape{
//	double area(double x);
//}
//
//class Square implements Shape{
//	double bc;
//	public Square(double bc){
//		this.bc=bc;
//	}
//	public double area(double x){
//		return x*x;
//	}
//}
//
//class Circle implements Shape{
//	double r;
//	public Circle(double r){
//		this.r=r;
//	}
//	public double area(double x){
//		return Math.PI*x*x;
//	}
//}

//99999999999999999999999
//public class test1{
//	public static void main(String[] args){
//		RectangleClass r1=new RectangleClass(7.8,4.5);
//		RectangleClass r2=new RectangleClass(10.1,2.8);
//		r1.rectArea();
//		r1.rectLen();
//		r2.rectArea();
//		r2.rectLen();
//	}
//}
//
//interface RectangleInterface{
//	public void rectArea();
//	public void rectLen();	
//}
//
//class RectangleClass implements RectangleInterface{
//	double x,y;
//	public RectangleClass(double x,double y){
//		this.x=x;
//		this.y=y;
//	}
//	public void rectArea(){
//		System.out.println(x*y);
//	}
//	public void rectLen(){
//		System.out.println(2*(x+y));
//	}
//}

10 10 10 10 10 10 10 10 10 10 10 10 10 
//import java.util.*;
//public class test1{
//	public static void main(String[] args){
//		String a="23 10 -8 0 3 7 108";
//		String[] b=a.split(" ");
//		int[]  c=new int[b.length];
//		for(int i=0;i<b.length;i++){
//			c[i]=Integer.parseInt(b[i]);
//		}
//		Arrays.sort(c);
//		String ans="";
//		ans=ans+c[0];
//		for(int i=1;i<b.length;i++){
//			ans=ans+" "+c[i];
//		}
//		System.out.println(ans);
//	}
//}

//111111111111111111111111
//public class test1{
//	public static void main(String[] args){
//		String s1="nba";
//		String s2="asfasfnabaasdfnbasdnbasnbasdnbadfasdf";
//		int cnt=0;
//		for(int i=0;i<s2.length()-s1.length();i++){
//			if(s2.substring(i,i+s1.length()).equals(s1)){
//				System.out.print(i+1+" ");
//				cnt++;
//			}
//		}
//		System.out.println("\n共出现了"+cnt+"次");
//	}
//}

//12 12 12 12 12 12 12 12 12 12 12 12 12 12
//public class test1{
//	public static void main(String[] args){
//		int n=Integer.parseInt(args[0]);
//		if(n%2==0) System.out.println(n+"是偶数");
//		else System.out.println(n+"是奇数");
//	}
//}

//13 13 13 13 13 13 13 13 13 13 13 13 13 13
//public class test1{
//	public static void main(String[] args){
//		int n=Integer.parseInt(args[0]);
//		int m=Integer.parseInt(args[1]);
//		if(n>m) System.out.println(n+">"+m);
//		else if(n<m) System.out.println(n+"<"+m);
//		else System.out.println(n+"="+m);
//	}
//}

14 14 14 14 14 14 14 14 14 14 14 14 14 14
//public class test1{
//	public static void main(String args[]){
//		int[][] a=new int[11][11];
//		for(int i=1;i<=10;i++){
//			a[i][1]=1;
//			a[i][i]=1;
//		}
//		for(int i=3;i<=10;i++){
//			for(int j=2;j<i;j++){
//				a[i][j]=a[i-1][j-1]+a[i-1][j];
//			}
//		}
//		for(int i=1;i<=10;i++){
//			for(int j=1;j<=i;j++){
//				if(j!=1) System.out.print(" ");
//				System.out.print(a[i][j]);
//			}
//			System.out.println();
//		}
//	}
//}

15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 
//import java.util.Scanner;
//public class test1{
//	public static void main(String[] args){
//		int num=(int)(Math.random()*10);
//		Scanner input=new Scanner(System.in);
//		int n=input.nextInt();
//		while(num!=n){
//			if(num>n) System.out.println("sorry,您猜小了!");
//			else if(num<n) System.out.println("sorry,您猜大了!");
//			n=input.nextInt();
//		}
//		System.out.println("恭喜您,答对了!");
//	}
//}

/17 17 17 17 17 17 17 17 17 17 17 17
//public class test1{
//	public static void main(String[] args){
//		Book b=new Book("西游记","吴承恩",200);
//		b.printBook();
//	}
//}
//
//class Book{
//	private String name,author;
//	int sale;
//	public Book(){}
//	public Book(String name,String author,int sale){
//		this.name=name;
//		this.author=author;
//		this.sale=sale;
//	}
//	public void setBook(String name,String author,int sale){
//		this.name=name;
//		this.author=author;
//		this.sale=sale;
//	}
//	public void printBook(){
//		System.out.println("书名"+name+" 作者"+author+" 月销量"+sale);
//	}
//}

/18 18 18 18 18 18 18 18 18 18 18 18
//public class test1{
//	public static void main(String[] args){
//		Account a=new Account("abc","123",100);
//		a.show();
//		a.add(100);
//		a.show();
//		a.qu(150);
//		a.show();
//		a.qu(100);
//		a.show();
//	}
//}
//
//class Account{
//	String name,id;
//	double money;
//	public Account(String name,String id,double money){
//		this.name=name;
//		this.id=id;
//		this.money=money;
//	}
//	public void show(){
//		System.out.println("余额为"+money);
//	}
//	public void add(double x){
//		money=money+x;
//	}
//	public void qu(double x){
//		if(money<x){
//			System.out.println("余额不足,操作失败");
//		}
//		else money=money-x;
//	}
//}

///20 20 20 20 20 20 20 20 20
//public class test1{
//	public static void main(String[] args){
//		circleClass c1=new circleClass(3.5);
//		circleClass c2=new circleClass(5.0);
//		c1.show();
//		c2.show();
//	}
//}
//
//interface circleInterface{
//	static final double PI=Math.acos(-1.0);
//	double circleArea();
//}
//
//class circleClass implements circleInterface{
//	private double r;
//	public circleClass(double r){
//		this.r=r;
//	}
//	public double circleArea() {
//		return PI*r*r;
//	}
//	public void show(){
//		System.out.println("圆的面积为"+circleArea());
//	}
//}


public class test1{
	public static void  main(String[] args){
		complex p1=new complex();
		complex p2=new complex();
		p1.setrealPart(18);
		p1.setimagPart(2);
		p2.setrealPart(19);
		p2.setimagPart(-13);
		complex resultplus=p1.add(p2);
		complex resultminus=p1.minus(p2);
		System.out.print("两个复数相加的结果为:");
		resultplus.print();
		System.out.print("两个复数相减的结果为:");
		resultminus.print();
	}
}

class complex{
	private int realPart;
	private int imagPart;
	public int getrealPart(){
		return realPart;
	}
	public void setrealPart(int realPart){
		this.realPart=realPart;
	}
	public int getimagPart(){
		return imagPart;
	}
	public void setimagPart(int imagPart){
		this.imagPart=imagPart;
	}
	public complex add(complex c){
		int real=this.realPart+c.realPart;
		int imag=this.imagPart+c.imagPart;
		complex result=new complex();
		result.setrealPart(real);
		result.setimagPart(imag);
		return result;
	}
	public complex minus(complex c){
		int real=this.realPart-c.realPart;
		int imag=this.imagPart-c.imagPart;
		complex result=new complex();
		result.setrealPart(real);
		result.setimagPart(imag);
		return result;
	}
	public void print(){
		if(imagPart>0){
			System.out.println(realPart+"+"+imagPart+"i");
		}
		else if(imagPart<0){
			System.out.println(realPart+"-"+(-imagPart)+"i");
		}
		else{
			System.out.println(realPart);
		}
	}
}
/**
首先定义一个计算长方形面积的类rectangleClass,要求类中有一个定义长方形左上角和右下角座标的构造函数,以及一个通过长方形右下角座标与左上角座标计算长方形面积,并实例化两个长方形进行测试.
*/

import java.util.Scanner;
public class test1{
	public static void main(String[] args){
		Scanner input = new Scanner(System.in);
		System.out.println("请输入长方形左上角坐标");
		double x1=input.nextDouble();
		double y1=input.nextDouble();
		System.out.println("请输入长方形右下角坐标");
		double x2=input.nextDouble();
		double y2=input.nextDouble();
		rectangleClass r1 =new rectangleClass(x1,y1,x2,y2);
		r1.area();
	}
}

class rectangleClass{
	private double x1,x2,y1,y2;
	public rectangleClass(double x1,double y1,double x2,double y2){
		this.x1=x1;
		this.y1=y1;
		this.x2=x2;
		this.y2=y2;
	}
	public void area(){
		System.out.println("以("+x1+","+y1+")为左上角顶点坐标,以("+x2+","+y2+")在右下角顶点坐标的长方形的面积为:"+(x2-x1)*(y1-y2));
	}
}
/**
设计一个学生类Student,其数据成员有name(姓名)、age(年龄)和degree(学位)。由Student类派生出本科生类Undergraduate和研究生类Graduate,本科生类Undergraduate增加成员specialty(专业),研究生类增加成员direction(研究方向)。每个类都有show()方法,用于输出数据成员信息。最后请输出下列信息:
*/

package cn.itcase.chapter08;

public class Student {
	private String name;
	private int age;
	private String degree;
	public Student(String name, int age, String degree) {
		super();
		this.name = name;
		this.age = age;
		this.degree = degree;
	}
	public Student(){
		super();
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public String getDegree() {
		return degree;
	}
	public void setDegree(String degree) {
		this.degree = degree;
	}
	public void show(){
		System.out.print("姓名:"+this.name+"\t年龄:"+this.age+"\t学位:"+this.degree);
	}
}
package cn.itcase.chapter08;

class Undergraduate extends Student{
	private String specialty;

	public String getSpecialty() {
		return specialty;
	}
	public void setSpecialty(String specialty) {
		this.specialty = specialty;
	}
	public Undergraduate(String name, int age, String degree, String specialty) {
		super(name, age, degree);
		this.specialty = specialty;
	}
	public void show(){
		super.show();
		System.out.println("\t专业:"+this.specialty);
	}
	
}
package cn.itcase.chapter08;

class Graduate extends Student{
	private String direction;
	public String getDirection() {
		return direction;
	}
	public void setDirection(String direction) {
		this.direction = direction;
	}
	public Graduate(String name, int age, String degree, String direction) {
		super(name, age, degree);
		this.direction = direction;
	}
	public void show(){
		super.show();
		System.out.println("\t研究方向:"+this.direction);
	}
}
package cn.itcase.chapter08;

public class test {
	public static void main(String[] ages){
		Undergraduate stu1=new Undergraduate("张三",20,"本科","通信");
		Undergraduate stu2=new Undergraduate("李四",21,"本科","电子");
		Graduate stu3=new Graduate("王五",25,"硕士","通信");
		Graduate stu4=new Graduate("刘六",36,"博士","通信");
		stu1.show();
		stu2.show();
		stu3.show();
		stu4.show();
	}
}

/**
编程实现有一个电话类Phone,它有号码的属性number,是一个12位的字符数组,它有四个功能,设置电话号码setNumber(),显示电话号码getNumber(),接电话answer(),拨打电话dial();移动电话mobilePhone和固定电话fixPhone是电话的两个子类, 但移动电话号码为11位, 并且移动电话和固定电话接听和拨打电话的方式不同.固定电话又有一个子类:无绳电话cordlessPhone,无绳电话号码为4位,它相对固定电话还多一个移动功能move().实现这几个类,并且测试它们的功能.
*/

package cn.itcase.chapter09;

public class Phone {
	char[] number=new char[12];
	public char[] getNumber() {
		System.out.print("本机号码是:");
		for(int i=0;i<number.length;i++){
			System.out.print(number[i]);
		}
		System.out.println();
		return number;
	}
	public void setNumber(char[] number) {
		this.number = number;
	}
}
package cn.itcase.chapter09;

class mobilePhone extends Phone{
	public void answer(){
		System.out.println("正通过移动网络接听电话....");
	}
	public void dail(){
		System.out.println("正通过电信固网拨打电话....");
	}
}
package cn.itcase.chapter09;

class fixPhone extends Phone{
	public void answer(){
		System.out.println("正通过电信固网接听电话....");
	}
	public void dail(){
		System.out.println("正通过电信固网拨打电话....");
	}
}
package cn.itcase.chapter09;

class cordlessPhone extends fixPhone{
	public void move(){
		System.out.println("正在移动通话....");
	}
}
package cn.itcase.chapter09;

public class test {
	public static void main(String[] args){
		fixPhone fp=new fixPhone();
		mobilePhone mp=new mobilePhone();
		cordlessPhone cp=new cordlessPhone();
		fp.setNumber(new char[]{'0','5','7','4','8','8','2','2','2','0','9','6'});
		fp.getNumber();
		fp.dail();
		fp.answer();
		mp.setNumber(new char[]{'1','3','7','8','8','8','8','6','6','6','6'});
		mp.getNumber();
		mp.dail();
		mp.answer();
		cp.setNumber(new char[]{'2','0','9','6'});
		cp.getNumber();
		cp.dail();
		cp.answer();
		cp.move();
	}
}

/**
首先设计一个学生抽象类Student,其数据成员有name(姓名)、age(年龄)和degree(学位),以及一个抽象方法show()。然后由Student类派生出本科生类Undergraduate和研究生类Graduate,本科生类Undergraduate增加成员specialty(专业),研究生类增加成员direction(研究方向)。并且每个类都有show()方法,用于输出数据成员信息。请定义对象,并打印输出下列信息:
*/

package cn.itcase.chapter08; 
public abstract class Student {
	private String name;
	private int age;
	private String degree;
	public Student(String name, int age, String degree) {
		super();
		this.name = name;
		this.age = age;
		this.degree = degree;
	}
	public Student(){
		super();
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public String getDegree() {
		return degree;
	}
	public void setDegree(String degree) {
		this.degree = degree;
	}
	public void show1(){
		System.out.print("姓名:"+this.name+"\t年龄:"+this.age+"\t学位:"+this.degree);
	}
	public abstract void show();
}
package cn.itcase.chapter08;

class Undergraduate extends Student{
	private String specialty;

	public String getSpecialty() {
		return specialty;
	}
	public void setSpecialty(String specialty) {
		this.specialty = specialty;
	}
	public Undergraduate(String name, int age, String degree, String specialty) {
		super(name, age, degree);
		this.specialty = specialty;
	}
	public void show(){
		super.show1();
		System.out.println("\t专业:"+this.specialty);
	}	
}
package cn.itcase.chapter08;

class Graduate extends Student{
	private String direction;
	public String getDirection() {
		return direction;
	}
	public void setDirection(String direction) {
		this.direction = direction;
	}
	public Graduate(String name, int age, String degree, String direction) {
		super(name, age, degree);
		this.direction = direction;
	}
	public void show(){
		super.show1();
		System.out.println("\t研究方向:"+this.direction);
	}
}
package cn.itcase.chapter08;

public class test {
	public static void main(String[] ages){
		Student stu1=new Undergraduate("张三",20,"本科","计算机科学");
		Student stu2=new Undergraduate("李四",21,"本科","物联网");
		Student stu3=new Graduate("王五",25,"硕士","软件工程");
		Student stu4=new Graduate("刘六",36,"博士","通信工程");
		stu1.show();
		stu2.show();
		stu3.show();
		stu4.show();
	}
}

/**
1、设计一个接口circle Interface,要求接口中有一个定义PI的常量以及一个计算圆面积的空方法circleArea()。然后设计一个类circleClass实现该接口,通过构造函数circleClass(double r)定义圆半径,并增加一个显示圆面积的方法。最后,通过上述类生成两个半径分别为3.5、5.0的圆对象circle1、circle2进行测试。
*/

package cn.itcase.chapter15;

public interface Circlelnterface {
	final double PI=3.14;
	public double circleArea(double r);
}
package cn.itcase.chapter15;

public class CircleClass implements Circlelnterface{
	double r;
	public CircleClass(double r) {
		super();
		this.r = r;
	}
	public double circleArea(double r) {
		return (double)(PI*r*r);
	}
	public void printcircle(){
		System.out.println("半径为"+r+"的圆面积为:"+circleArea(r));
	}
}
package cn.itcase.chapter15;

public class test {
	public static void main(String[] args){
		CircleClass c1=new CircleClass(3.5);
		CircleClass c2=new CircleClass(5.0);
		c1.printcircle();
		c2.printcircle();
	}
}

/**
2. 设计一个Shape接口和它的两个实现类Square和Circle,要求如下:1)Shape接口中有一个抽象方法area(),方法接收一个double类型的参数,返回一个double类型的结果。2)Square和Circle中实现了Shape接口的area()抽象方法,分别求正方形和圆形的面积并返回。在测试类中创建Square和Circle对象,计算边长为2的正方形面积和半径为3的园面积。
*/

package cn.itcase.chapter16;

public interface Shape {
	double area(double l);
}
package cn.itcase.chapter16;

public class Square implements Shape{
	public double area(double l){
		return l*l;
	}
}
package cn.itcase.chapter16;

public class Circle {
	public double area(double r){
		return Math.PI*r*r;
	}
}
package cn.itcase.chapter16;

public class test {
	public static void main(String[] args){
		Shape square= new Square();
		Circle circle= new Circle();
		System.out.println("边长为2的正方形的面积为:"+square.area(2));
		System.out.println("半径为3的圆的面积为"+circle.area(3));
	}
}

/**
2. 在biology包中的animal包中有human类,它具有name,height,weight的属性,还具有eat(),sleep()和work()的行为,在biology包中的plant包中有flower类,它具有name,color,smell的属性,还具有drink()和blossom()的行为.现在在一个school包中的garden包中一个张三的人,他是一个human类的对象,种植的rose是一个flower类对象,编程实现并测试各自的方法.
*/

package human;

public class Human {
	String name;
	double height,weight;
	public Human(String name) {
		super();
		this.name = name;
	}
	public void eat(){
		System.out.println(name+"正在吃");
	}
	public void sleep(){
		System.out.println(name+"正在睡觉");
	}
	public void work(){
		System.out.println(name+"正在工作");
	}
}
package plant;

public class Flower {
	String name,color,smell;
	public Flower(String name) {
		super();
		this.name = name;
	}
	public void drink(){
		System.out.println(name+"正在吸收水分");
	}
	public void blossom(){
		System.out.println(name+"正在开花");
	}
}
package school;

import human.Human;
import plant.Flower;

public class Garden {
	public static void main(String[] args){
		Human human=new Human("张三");
		Flower flower=new Flower("rose");
		human.eat();
		human.sleep();
		human.work();
		flower.drink();
		flower.blossom();
	}
}

/**
汽车总租金
*/
package cn.itcase.chapter10;

public abstract class MotoVehicle {
	private String No;
	private String Brand;
	public MotoVehicle(){
		
	}
	public MotoVehicle(String no, String brand) {
		super();
		No = no;
		Brand = brand;
	}
	public MotoVehicle(String no) {
		super();
		No = no;
	}
	public String getNo() {
		return No;
	}
	public void setNo(String no) {
		No = no;
	}
	public String getBrand() {
		return Brand;
	}
	public void setBrand(String brand) {
		Brand = brand;
	}
	public abstract int calcRent(int day);
}
package cn.itcase.chapter10;

public class  Bus extends MotoVehicle{
	private int seatcount;
	public Bus(){
		
	}	
	public Bus(String No,String Brand,int seatcount) {
		super(No,Brand);
		this.seatcount = seatcount;
	}
	
	public int getSeatcount() {
		return seatcount;
	}
	public void setSeatcount(int seatcount) {
		this.seatcount = seatcount;
	}

	public int calcRent(int day){
		if(seatcount>16){
			return 1500*day;
		}
		else{
			return 800*day;
		}
	}
}
package cn.itcase.chapter10;

public class Car extends MotoVehicle{
	private String Brand;
	public Car(){
		
	}
	public Car(String No,String Brand) {
		super(No);
		this.Brand=Brand;
	}
	public String getBrand() {
		return Brand;
	}
	public void setBrand(String brand) {
		Brand = brand;
	}
	public int calcRent(int day){
		if(Brand.equals("别克商务舱GL8")){
			return 600*day;
		}
		else if(Brand.equals("宝马550i")){
			return 500*day;
		}
		else if(Brand.equals("别克林荫大道")){
			return 300*day;
		}
		else{
			System.out.println("输入错误");
			return 0;
		}
	}
}
package cn.itcase.chapter10;

public class Customer {
	private String name;
	public Customer(String name) {
		super();
		this.name = name;
	}
	public static double CalcTotalRent(MotoVehicle[] motos){
	    double totalRent = 0; 
	    for(int i=0;i<motos.length;i++){
	        totalRent += motos[i].calcRent(5);
	    } 
	    return totalRent;
	}
}
package cn.itcase.chapter10;

import java.util.Scanner;

public class test {

	public static void main(String[] args) {
		MotoVehicle[] motos=new MotoVehicle[4];
		motos[0] = new Car("京NY28588","宝马550i");
		motos[1] = new Car("京NNN3288","宝马550i");
		motos[2] = new Car("京NY28588","别克林荫大道");
		motos[3] = new Bus("京NY28589","金龙",34);
		Customer cust=new Customer("AAA");
		double total=cust.CalcTotalRent(motos);
		System.out.println("客户名为AAA的某客户"+"租用以下车辆:");
		for(int i=0;i<4;i++){
			System.out.println(motos[i].getNo()+ "\t" +motos[i].getBrand());
		}
		System.out.println("总租金为:"+total);
	}
}

/**
调色板
*/

package cn.itcase.chapter0527;

import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;


public class test1{
	public static void main(String[] args){
		TiaoSe tiaose=new TiaoSe();
	}
}
class TiaoSe extends Frame{
	Label l1,l2,l3;
	Button b1,b2,b3,b4,b5,b6;
	TextField tf1,tf2,tf3;
	int count1,count2,count3;
	Color c;
	private class changeText implements ActionListener,TextListener{
		public void actionPerformed(ActionEvent e){
			if(e.getSource()==b1) tf1.setText((count1++)+"");
			if(e.getSource()==b2) tf2.setText((count2++)+"");
			if(e.getSource()==b3) tf3.setText((count3++)+"");
			if(e.getSource()==b4) tf1.setText((count1--)+"");
			if(e.getSource()==b5) tf2.setText((count2--)+"");
			if(e.getSource()==b6) tf3.setText((count3--)+"");
			int c1=Integer.parseInt(tf1.getText());
			int c2=Integer.parseInt(tf2.getText());
			int c3=Integer.parseInt(tf3.getText());
			if(c1>=255){c1=0;count1=0;}
			if(c2>=255){c2=0;count2=0;}
			if(c3>=255){c3=0;count3=0;}
			if(c1==-1){c1=0;count1=0;}
			if(c2==-1){c2=0;count2=0;}
			if(c3==-1){c3=0;count3=0;}
			c=new Color(c1,c2,c3);
			p1.setBackground(c);
		}
		public void textValueChanged(TextEvent e) {
			c=new Color(Integer.parseInt(tf1.getText()),Integer.parseInt(tf2.getText()),Integer.parseInt(tf3.getText()));
			p1.setBackground(c);
		}
	}
	Panel p=new Panel();
	Panel p1=new Panel();
	GridBagLayout gbl=new GridBagLayout();
	GridBagConstraints gbc=new GridBagConstraints();
	public TiaoSe(){
		setSize(500,400);
		p.setLayout(gbl);
		gbc.fill=GridBagConstraints.BOTH;
		this.setLabel();
		this.setButton_add();
		this.setTextField();
		this.setButton_sub();
		this.setPanel();
		add(p);
		setVisible(true);
		this.addWindowFocusListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e){
				System.exit(0);
			}
		});
	}
	private void setPanel(){
		gbc.weightx=10;
		gbc.weighty=10;
		gbc.gridx=0;
		gbc.gridy=4;
		gbc.gridwidth=4;
		gbc.insets=new Insets(10,10,10,10);
		p1.setBackground(new Color(220,220,220));
		gbl.setConstraints(p1, gbc);
		p.add(p1);
	}
	private void setButton_sub(){
		b4=new Button("-");
		b5=new Button("-");
		b6=new Button("-");
		b4.setFont(new Font("宋体",Font.PLAIN,20));
		b5.setFont(new Font("宋体",Font.PLAIN,20));
		b6.setFont(new Font("宋体",Font.PLAIN,20));
		gbc.gridx=3;
		gbc.gridy=0;
		gbl.setConstraints(b4, gbc);
		gbc.gridy=1;
		gbl.setConstraints(b5, gbc);
		gbc.gridy=2;
		gbl.setConstraints(b6, gbc);
		p.add(b4);
		p.add(b5);
		p.add(b6);
		b4.addActionListener(new changeText());
		b5.addActionListener(new changeText());
		b6.addActionListener(new changeText());
	}
	private void setTextField(){
		tf1=new TextField(5);
tf1.setText("220");
count1=Integer.parseInt(tf1.getText());
		tf2=new TextField(5);
		tf2.setText("220");
count2=Integer.parseInt(tf2.getText());
tf3=new TextField(5);
		tf3.setText("220");
		count3=Integer.parseInt(tf3.getText());
		gbc.weightx=1;
		gbc.weighty=1;
		gbc.gridx=2;
		gbc.gridy=0;
		gbl.setConstraints(tf1, gbc);
		gbc.gridy=1;
		gbl.setConstraints(tf2, gbc);
		gbc.gridy=2;
		gbl.setConstraints(tf3, gbc);
		p.add(tf1);
		p.add(tf2);
		p.add(tf3);
		tf1.addTextListener(new changeText());
		tf2.addTextListener(new changeText());
		tf3.addTextListener(new changeText());
		this.setKeyPress(tf1);
		this.setKeyPress(tf2);
		this.setKeyPress(tf3);
	}
	private void setKeyPress(TextField tf){
		tf.addKeyListener(new KeyAdapter(){ 
			public void keyPressed(KeyEvent e){
				char ch = e.getKeyChar(); 
				if(!(ch>='0'&&ch<='9')){
					e.consume();
				}
			}
		});
	}
	private void setButton_add(){	
		b1=new Button("+");
		b2=new Button("+");
		b3=new Button("+");
		gbc.insets=new Insets(10,80,10,10);
		gbc.gridx=1;
		gbc.gridy=0;
		gbc.weightx=1;
		gbc.weighty=1;
		gbl.setConstraints(b1, gbc);
		gbc.gridy=1;
		gbl.setConstraints(b2, gbc);
		gbc.gridy=2;
		gbl.setConstraints(b3, gbc);
		p.add(b1);
		p.add(b2);
		p.add(b3);
		b1.addActionListener(new changeText());
		b2.addActionListener(new changeText());
		b3.addActionListener(new changeText());
	}
	private void setLabel(){	
		l1=new Label("红色",Label.CENTER);
		l2=new Label("绿色",Label.CENTER);
		l3=new Label("蓝色",Label.CENTER);
		l1.setBackground(Color.RED);
		l2.setBackground(Color.GREEN);
		l3.setBackground(Color.BLUE);
		gbc.gridx=0;
		gbc.gridy=0;
		gbc.weightx=1;
		gbc.weighty=1;
		gbc.insets=new Insets(10,10,10,10);
		gbl.setConstraints(l1, gbc);
		gbc.gridy=1;
		gbl.setConstraints(l2, gbc);
		gbc.gridy=2;
		gbl.setConstraints(l3, gbc);
		p.add(l1);
		p.add(l2);
		p.add(l3);
	}
}

package cn.itcase.chapter0527;

import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;

class Chuangkou extends JFrame implements ActionListener{
	JButton b1=new JButton("红色");
	JButton b2=new JButton("绿色");
	JButton b3=new JButton("蓝色");
	int count1=0;
	int count2=0;
	int count3=0;
	Container con = this.getContentPane();
	public Chuangkou(){
		super("按钮和框架");
		this.setSize(320,240);
		this.setLocation(220,160);
		this.setLayout(null);
		b1.setSize(80,40);
		b2.setSize(80,40);
		b3.setSize(80,40);
		b1.setLocation(20, 80);
		b2.setLocation(120,80);
		b3.setLocation(220,80);
		b1.setBackground(Color.red);
		b2.setBackground(Color.green);
		b3.setBackground(Color.blue);
		con.add(b1);
		con.add(b2);
		con.add(b3);
		b1.addActionListener(this);
		b2.addActionListener(this);
		b3.addActionListener(this);
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if(e.getSource()==b1){
			count1+=10;
			if(count1>255) count1=0;
			Color c=new Color(count1,count2,count3);
			con.setBackground(c);
		}
		if(e.getSource()==b2){
			count2+=10;
			if(count2>255) count2=0;
			Color c=new Color(count1,count2,count3);
			con.setBackground(c);
		}
		if(e.getSource()==b3){
			count3+=10;
			if(count3>255) count3=0;
			Color c=new Color(count1,count2,count3);
			con.setBackground(c);
		}
	}	
}

public class test2 {
	public static void main(String args[]){
		Chuangkou ck=new Chuangkou();
		ck.setVisible(true);
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值