과제 곱하기 절차
package org.javaro.lecture;
public class P1_1 {
public static void main(String[] args) {
System.out.println("조병수-20191016-객체");
System.out.println("\n[절차 프로그램]");
double x, y;
x=10;
y=20;
System.out.println("곱하기="+x*y);
}
}
실행창

과제 곱하기 함수
package org.javaro.lecture;
public class P1_2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("조병수-20191016-객체");
System.out.println("\n[함수 프로그램]");
double x, y;
x=10;
y=20;
System.out.println("곱하기="+mul(x,y));
}
static double mul(double a, double b) {
return a*b;
}
}
실행창

과제 곱하기 객체
package org.javaro.lecture;
public class P1_3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("조병수-20191016-객체");
System.out.println("\n[객체 프로그램]");
double x, y;
x=10;
y=20;
P7_1_1 pr1 = new P7_1_1();
pr1.b = x;
pr1.c = y;
System.out.println("곱하기="+pr1.mul());
}
}
class P7_1_1{
int a ;
double b, c;
public double mul() {
return b*c;
}
}
실행창

과제 곱하기 자바빈
package org.javaro.lecture;
public class P1_4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("조병수-20191016-객체");
System.out.println("\n[자바빈 프로그램]");
double x, y;
x=10;
y=20;
P7_1_2 pr2 = new P7_1_2();
pr2.setB(x); pr2.setC(y);
System.out.println("곱하기="+pr2.mul());
}
}
class P7_1_2{
int a ;
double b, c;
void setA(int x) {
a = x;
}
void setB(double y) {
b = y;
}
void setC(double z) {
c = z;
}
public double mul() {
return b*c;
}
}
실행창
