
我的思路:
1定义一个开关的接口(ISWitcher),用于设定开关的功能
2定义开关类实现开关接口的功能
3定义电器类,所有电器的父类
4对电灯,投影仪,风扇等电器进行定义
5进行测试
3. 下面是一个类的定义程序,请将程序补充完整。
public class Test4_3{
int x,y;
Test4_3 (int i,int j){
x=i;
y=j;
}
}
4
public class Test4_4 {
public static void main(String[] args) {
int n1=2,n2=3;
Test4_4 obj1_1=new Test4_4();
obj1_1method(n1,n2) ;
}
public void method(int x,int y){
Systemoutprintln("2/3="+2/3 );
Systemoutprintln("23="+23 );
}
}
6. 下面程序的功能是通过调用方法max()求给定的三个数的最大值,请将程序补充完整。
public class Test4_6 {
public static void main( String args[] ) {
int i1=1234,i2=456,i3=-987;
int MaxValue;
MaxValue= max(i1,i2,i3);
Systemoutprintln("三个数的最大值:"+MaxValue);
}
public static int max(int x,int y,int z) {
int temp1,max_value;
temp1=x>yx:y;
max_value=temp1>ztemp1:z;
return max_value;
}
5. 下面是一个java应用程序,它的功能是在屏幕上输出26个英文字母,其中每个字母相隔一个制表符, 请将程序补充完整。
public class Test4_5{
public static void main( args[] ) {
char c='a';
for (int i=1;i<=26;i++ ) {
Systemoutprint( c + " ");
c++;
}
}
}
/
编写一个学生类 Student ,要求:(1) 学生类 Student 属性有: id : long型,
代表学号 name : String类对象,代表姓名 age : int型,代表年龄
sex : boolen型,代表性别(其中:true表示男,false表示女)
phone : String类对象,代表联系电话(2)
学生类 Student的方法有:
Student(long i , String n , int a , boolean s , long p)
: 有参构造函数,形参表中的参数分别初始化学号、姓名、 年龄、性别和联系电话。
int getAge() ( ) : 获取年龄作为方法的返回值
boolean getSex( ) ( ) :
获取性别作为方法的返回值。 long getPhone ( ) : 获取联系电话作为方法的返回值。
/
public class Student {
long id;
String name;
int age;
boolean sex;
long phone;
Student(long i, String n, int a, boolean s, long p) {
id = i;
name = n;
age = a;
sex = s;
phone = p;
}
public long getId() {
return id;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public boolean getSex() {
return sex;
}
public long getPhone() {
return phone;
}
public static void main(String[] argu){
Student stu = new Student(123,"jing",24, true, 5083394);
Systemoutprintln("The student informaiton:\n\r"+
"id:"+stugetId()+
" name:"+stugetName()+
" age:"+stugetAge()+
" sex:"+stugetSex()+
" phone:"+stugetPhone());
}
}
以上就是关于JAVA程序题全部的内容,包括:JAVA程序题、JAVA的程序题目、java 程序题目等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)