public class Language {
static String w="英文"; // 定义静态变量a,赋值
public static void Aq() {// 构造静态方法
System.out.println("智能手机默认语言为"+a);// 用第一个对象调用类成员方法
}
public static void B(String a){//构造静态方法
a="中文";
System.out.println("将智能手机的默认语言设置为:"+a);// 用第二个对象调用类成员方法
}
public static void main(String[] args) {
Language string=new Language();// 创建一个类对象string
string.Aq();// 使用对象调用该静态方法 英文
string.B(w);// 使用对象调用静态方法 中文
}
}
public class Card{
static String cardnumber="4013735633800642";//定义静态string型变量cardnumber卡号
static String n1="123456";// 定义静态string型变量name默认密码
static String n2="168779";// 定义静态string型变量name重置后的密码
public void defualt() { //定义一个defualt(默认)方
System.out.println("信用卡"+cardnumber+"的默认密码为"//使用对象调用类成员方法输出
+n1);
}
public void change() { // 定义change方法
System.out.println("重置信用卡"+cardnumber+"的密码为"+n2);//使用对象调用类成员方法输出
}
public static void main(String[] args) {//主方法
Card cc1=new Card();//创建一个类对象为cc1
c1.defualt();// 使用对象调用defualt方法
c1.change();// 使用对象调用change方法
}
}
class train{ // 定义火车类
double train2; //定义一个double型的变量
public trian(double train2){ // 构造个方法传入参数double train2
this.train2=train2; //调用构造方法参数
System.out.println("火车速度"+train2+"公里/小时"); //输出语句
}
}
class high{ //定义高铁类
double speed; //定义一个double型的变量speed
public high(double speed){ //构造个方法传入参数double型变量speed
this.speed=speed; //调用构造方法参数
System.out.println("高铁的速度为"+speed+"公里/小时");//输出语句
}
}
public class Speed {
public static void main(String[] args) {
final double train2=145.8; //定义个double型变量train2且赋值
double a=train2*2;//定义个double型变量a且赋值
train n new train(train2);// 创建train类对象n存放train2数据
high h=new high (a);//创建high类对象h存入a数据
}
}
class Mechine{//机械类
double price;//定义个double型变量price
public Mechine(double price){ //构造个方法传入参数double price
this.price=price; //调用构造方法参数
System.out.println("机械钟价格为"+price+"RMB");//输出
}
}
class Quartz{//石英类
double price1;//定义个double型变量price
public Quartz(double price1){//构造个方法传入参数double price1
this.price1=price1; //调用构造方法参数
System.out.println("石英表价格为"+price1+"RMB");//输出
}
}
public class Clock {//手表类
final static String time="10点10分"; //定义静态string型变量time
static double price=189.99; //定义静态double变量price
static double price1=69.0; //定义静态double变量price1
public static void main(String[] args) {
Mechine m1=new Mechine(price); //创建Mechine类对象m1存放price数据
System.out.println("当前时间:"+time);//输出语句
Quartz q1= new Quartz(price1); //创建Quartz类对象q1存放price1数据
System.out.println("当前时间:"+time); //输出语句
}
}
public class Graph {//图形类
public static double rectangle(double x, double y) {//构造矩形方法
double a1 = 0;//定义double型变量a
a1 = x * y;//
return a;//返回a1
}
public static double circle(double r){ //构造圆形方法
double PI=3.1415926; //定义double型变量PI且赋值
double a1=PI*r*r; //定义double型变量a1
return a1; //返回a1的值
}
public static double notnull(double PI){
double PI=3.1415926;//定义double型变量PI且赋值
return PI; //返回PI
}
public static void main(String[] args) {//主方法
double N1=notnull(0);//double型变量N调取notnull类且输入参数
double A=rectangle(3.0,4.0);//double型变量A调取rectangle类且输入参数
double S=circle(4);;//double型变量Y调取circle且输入参数
System.out.println(N1);
System.out.println(S);
System.out.println(A);
}
}
class circle{ //定义圆形类
public circle(double r,double PI) { //构造圆方法
double s=r*r*PI;// 定义double型变量s
System.out.println("圆形面积:"+s);
}
}
class Rectangle{//定义矩形类
public Rectangle(double a,double b) {//构造矩形方法
double s3=a*b; //定义个double型变量s3
System.out.println("矩形的面积:"+s3);//输出语句
}
}
public class Shape {
final static double PI=3.1415926; //定义double变量PI赋值
public static void main(String[] args) { //主方法
circle c1=new circle(1.5000000,3.1415926); //创建圆类对象输出
Rectangle r1=new Rectangle(1,11); //创建矩形类对象输出
}
}
public class Boys{ //创建类
private void age(int age) {//age方法传入参数
return ;//返回
}
public static void main(String[] args) {
System.out.println("输入年龄");//
Scanner sc=new Scanner(System.in);//创建扫描器,键盘录入数值
int age=sc.nextInt();//定义int型变量age
if(age>=18) {//
System.out.println("我"+age+"岁了,我成年人");//
}else {//不成立执行
System.out.println("我"+age+"岁了,我未成年人");//
}
Boys b=new Boys();//创建Boys类对象
b.age(age);//对象调用age方法返回age参数
public class Login {//创建Login类
void Disemvark(String a,String b){//构造方法且传入参数
if(a.equals("张三")) {//输入张三
if(b.equals("123456")) {//输入密码
System.out.println("---------");//输出语句
System.out.println("登录成功!");//输出语句
}
}
}
public static void main(String[] args) {//主方法
Login n1=new Login(); //创建Login类对象n1
System.out.println("请输入用户名");
Scanner sc=new Scanner(System.in);
String name=sc.next(); //定义string型name
System.out.println("请输入密码");//输出语句
Scanner sc1=new Scanner(System.in);
String password=sc1.next();//定义string型password
Login m1=new Login(); //创建Login类对象m1
m1.Disemvark(name, password);//对象m1调取方法输入参数控制输出
}
}
class Past{
double a[]=new double[]{1.98,5.0,0.0,9.9}; //定义一个一维数组并给该数组传入元素
}
public class Fruit extends Past { //定义一个类并继承Past类
public static void main(String[]args){//主方法
double b[]=new double[]{
2.98,5.0,1.0,14.9}; //定义一个一维数组并给该数组传入元素
System.out.println("水果名称 水果价格(元/千克)水果重量(千克) 包装费(元/千克) 总价 \n"+"———————————————————————");
System.out.print("苹果\t");
Fruit w=new Fruit(); //在Friut类里创建一个对象
for(int i=0;i<w.length;i++){ //遍历a数组里每一个元素
System.out.print(w.a[i]); //输出数组中每一个元素
System.out.print("\t\t");
}
System.out.println();
System.out.print("精装苹果");
for(int i=0;i<b.length;i++){ //遍历b数组中每一个元素
System.out.print(b[i]); //输出数组中的每一个元素
System.out.print("\t\t");
}
System.out.println();
System.out.print("———————————————————————————");/
System.out.println();
System.out.print("差价\t\t\t\t\t\t\t");//输出信息
double j=b[b.length-1]-w.a[w.a.length-1];//计算精装苹果与普通苹果价格差
System.out.print(j);//输出
}
十
interface hello{
public void draw();
}
interface work{
public void draw();
}
class student implements hello{
public void draw() {
System.out.println("peter:老师好");
System.out.println("mike:同学们好");
}
}
class teacher implements work{
public void draw() {
System.out.println("mike:老师开始上课");
System.out.println("peter:同学开始记笔记");
}
}
public class Main{
public static void main(String[] args) {
student st = new student();
st.draw();
teacher te = new teacher();
te.draw();
}
}
class mother{
public void hobby() {
System.out.println("看电视");
System.out.println("做饭");
}
}
interface father{
public void hobby();
}
class son extends mother implements father{
public void hoppy1() {
System.out.println("抽烟");
System.out.println("钓鱼");
}
}
public class Main {
public static void main(String[] args) {
son s = new son();
System.out.println("儿子的爱好:");
sr.hobby();
sr.hobby1();
}
}