第四次实训作业
01.电表管理
<em>
package
disici;
public
class
dianbiao {
private
int
last;
private
int
now;
public
dianbiao(){
}
public
dianbiao(
int
last,
int
now) {
this
.last=last;
this
.now=now;
}
public
int
getlast(
int
last) {
return
last;
}
public
int
getnow(
int
now) {
return
now;
}
public
void
setlast(
int
last) {
this
.last=last;
}
public
void
setnow(
int
now) {
this
.now=now;
}<br>
public
void
print(){<br></em>
01.1电表测试
package
disici;
import
java.util.*;
public
class
dianbiaotest {
public
static
void
main(String []args) {
dianbiao e1=
new
dianbiao();
Scanner n=
new
Scanner(System.in);
System.out.println(
"请输入上月的用电情况:"
);
int
last=n.nextInt();
n.nextLine();
System.out.println(
"请输入本月的用电情况:"
);
int
now=n.nextInt();
e1.setlast(last);
e1.setnow(now);
int
mon=
0
;
mon=(
int
) (now*
1.2
);
System.out.println(
"本月的电费为:"
+mon);
}
}
02.圆柱体
package
disici;
import
java.util.*;
public
class
yuanzhu {
private
int
r;
private
int
h;
public
yuanzhu(
int
r,
int
h){
this
.h=h;
this
.r=r;
}
public
void
setr(
int
r) {
this
.r=r;
}
public
int
getr() {
return
r;
}
public
void
seth(
int
h) {
this
.h=h;
}
public
int
geth() {
return
h;
}
public
static
double
s(
int
r) {
return
r*r*
3.14
;
}
public
static
double
V(
int
r,
int
h) {
return
r*r*
3.14
*h;
}
public
static
void
main(String []args) {
System.out.println(
"请输入半径:"
);
Scanner in=
new
Scanner(System.in);
int
r=in.nextInt();
in.nextLine();
System.out.println(
"请输入高:"
);
int
h=in.nextInt();
in.nextLine();
yuanzhu e1=
new
yuanzhu(r,h);
e1.setr(r);
e1.seth(h);
System.out.println(
"底面积:"
+s(r)+
"体积:"
+V(r, h));
}
}
3.运算法则
package
disici;
import
java.util.*;
public
class
yunsuan {
private
int
a;
private
int
b;
public
yunsuan(
int
a,
int
b){
this
.a=a;
this
.b=b;
}
public
void
seta(
int
a) {
this
.a=a;;
}
public
int
geta(){
return
a;
}
public
void
setb(
int
b) {
this
.b=b;
}
public
int
getb() {
return
b;
}
public
static
int
jia(
int
a,
int
b) {
return
a+b;
}
public
static
int
jian(
int
a,
int
b) {
return
a-b;
}
public
static
int
cheng(
int
a,
int
b) {
return
a*b;
}
public
static
int
chu(
int
a,
int
b) {
return
a/b;
}
public
static
void
main(String []args) {
System.out.println(
"请输入数值1:"
);
Scanner in=
new
Scanner(System.in);
int
a=in.nextInt();
in.nextLine();
System.out.println(
"请输入数值2:"
);
int
b=in.nextInt();
in.nextLine();
yunsuan e1=
new
yunsuan(a,b);
e1.seta(a);
e1.setb(b);
System.out.println(
"加:"
+jia(a,b)+
"减:"
+jian( a, b)+
"乘:"
+cheng(a, b)+
"除:"
+chu(a,b));
}
}