方法调用类练习题
一、
User.Java
package com.jereh.practice;
public class User {
/**
* @param args
*/
String name;
long pw;
boolean sex;
int age;
int Time;
String level;
public User(String name,long pw,boolean sex,int age, int Time,String level){
// this.name=name;
// this.age=age;
// this.Time=Time;
// this.level=level;
System.out.println("大家好!我是"+name+"今年"+age+"岁,我是"+Time+"注册的,目前等级是:"+level);
}
}
run.Java
package com.jereh.practice;
public class run {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
User lucy=new User("lucy", 111111, false, 21, 20110108, "无敌小菜鸟");
}
}
二、
ScoreCalc.java
package com.jereh.practice2;
public class ScoreCalc {
int java;
int c;
int db;
public ScoreCalc(int java, int c, int db) {
super();
this.java = java;
this.c = c;
this.db = db;
}
public void sum(){
System.out.println("总成绩"+(double)(java+c+db));
}
public void avg(){
System.out.println("平均值"+(double)(java+c+db)/3);
}
}
run.java
package com.jereh.practice2;
import java.util.Scanner;
import com.sun.org.apache.xalan.internal.xsltc.compiler.sym;
public class run {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
int java;
int c;
int db;
ScoreCalc why=new ScoreCalc(100, 98, 98);
why.sum();
why.avg();
}
}