JAva 4回目の搭乗
7084 ワード
第一歩「電気料金管理」クラスの作成
私有属性:先月の電気メーターの読み取り、今月の電気メーターの読み取り
構築方法:パラメータなし、2パラメータ
メンバーメソッド:getXXX()メソッド、setXXX()メソッド
メンバーメソッド:先月、今月の電気メーターの読み取りを表示
ステップ2テストクラスの作成
作成対象1:先月の電気メーターの読み取り数は1000で、今月の電気メーターの読み取り数は1200です.
要件:非パラメトリック構築メソッドを呼び出してオブジェクトを作成します.
setXXX()メソッドを呼び出してオブジェクトを初期化します.
1度あたりの電気料金を1.2元と仮定し、今月の電気料金を計算して表示します.
作成対象2:先月の電気メーターの読み取り1200、今月の電気メーターの読み取り1450.
要件:2つのパラメータの構築方法を呼び出してオブジェクトを作成して初期化します.
setXXX()メソッドを呼び出して今月の電気メーターの読み取り数を1500に変更します(シミュレーションの読み取りが間違っているので修正する必要があります).
1度あたりの電気料金を1.2元と仮定し、今月の電気料金を計算して表示します.
円柱クラスとそのテストクラスを作成します.
3.1「円柱」クラス
プライベート属性:円底半径、高さ、
構築方法:2つのパラメータ付き
方法1:底面積の計算
方法2:ボリュームの計算
方法3:円底半径、高さ、底面積、体積を印刷します.
3.2テストクラス
2つのオブジェクトを作成し、メソッドを呼び出します.
私有属性:先月の電気メーターの読み取り、今月の電気メーターの読み取り
構築方法:パラメータなし、2パラメータ
メンバーメソッド:getXXX()メソッド、setXXX()メソッド
メンバーメソッド:先月、今月の電気メーターの読み取りを表示
ステップ2テストクラスの作成
作成対象1:先月の電気メーターの読み取り数は1000で、今月の電気メーターの読み取り数は1200です.
要件:非パラメトリック構築メソッドを呼び出してオブジェクトを作成します.
setXXX()メソッドを呼び出してオブジェクトを初期化します.
1度あたりの電気料金を1.2元と仮定し、今月の電気料金を計算して表示します.
作成対象2:先月の電気メーターの読み取り1200、今月の電気メーターの読み取り1450.
要件:2つのパラメータの構築方法を呼び出してオブジェクトを作成して初期化します.
setXXX()メソッドを呼び出して今月の電気メーターの読み取り数を1500に変更します(シミュレーションの読み取りが間違っているので修正する必要があります).
1度あたりの電気料金を1.2元と仮定し、今月の電気料金を計算して表示します.
package bbb;
public class ccc {
private int month,lastmonth;
public ccc(){
}
/*public ccc(int month,int lastmonth){
this.month=month;
this.lastmonth=lastmonth;
}
*/
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getLastmonth() {
return lastmonth;
}
public void setLastmonth(int lastmonth) {
this.lastmonth = lastmonth;
}
public void month(){
System.out.println(" :"+this.month+"
"+" :"+month*1.2);
}
public void lastmonth(){
System.out.println(" :"+this.lastmonth+"
"+" :"+lastmonth*1.2);
}
}
package bbb;
import java.util.Scanner;
public class Testccc {
public static void main(String[] args) {
ccc aa=new ccc();
/*@SuppressWarnings("resource")
Scanner sc=new Scanner(System.in);
aa.setMonth(sc.nextInt());
aa.setLastmonth(sc.nextInt());
aa.month();
aa.lastmonth();*/
aa.setMonth(1000);
aa.setLastmonth(1200);
aa.month();
aa.lastmonth();
}
}
円柱クラスとそのテストクラスを作成します.
3.1「円柱」クラス
プライベート属性:円底半径、高さ、
構築方法:2つのパラメータ付き
方法1:底面積の計算
方法2:ボリュームの計算
方法3:円底半径、高さ、底面積、体積を印刷します.
3.2テストクラス
2つのオブジェクトを作成し、メソッドを呼び出します.
package bbb;
public class circle {
private int h, r;;
public circle(){
}
public int getH(){
return h;
}
public void setH(int h){
this.h=h;
}
public int getR(){
return r;
}
public void setR(int r){
this.r=r;
}
void S(){
System.out.println(" :"+3.14*r*r);
}
void V(){
System.out.println(" :"+3.14*r*r*h);
}
}
package bbb;
public class Testcircle {
public static void main(String[] args) {
circle aa=new circle();
aa.setH(4);
aa.setR(2);
aa.S();
aa.V();
}
}