상세 컨텐츠

본문 제목

헬로자바

카테고리 없음

by 펀오락실 2018. 6. 19. 19:11

본문


기말고사.txt


 다운로드



1. ----------------------------------------------------------------



public class HellowJava {

static int var = 100;

public static void main(String[] args) {

int num1 = 100, num2 = 0;

try {

System.out.println(num1/num2);

}

catch(java.lang.ArithmeticException e) {

System.out.println("계산에 문제가 있습니다");

}

}

}


/*

* int var = 0;

System.out.println(var);

int sum = addFunction(10,20);

System.out.println(sum);

* static int addFunction(int num1, int num2) {

int hap;

hap = num1 + num2 + var;

return hap;

}

*

* // TODO Auto-generated method stub

* int one[] = new int[3];

for(int i = 0; i<one.length; i++) {

one[i] = 10 *i;

System.out.println(one[i]);

}

String two[] = {"하나","둘","셋","넷","다섯"};

for(String str : two) {

System.out.println(str);

}


int j = 0;

while(j<one.length) {

System.out.println(one[j]);

j++;


}


}


}

*/


/*

int var1 = 10;

float var2 = 10.1f;

double var3 = 10.2;

char var4 = '안';

String var5 = "안드로이드";


System.out.println(var1);

System.out.println(var2);

System.out.println(var3);

System.out.println(var4);

System.out.println(var5);




int count = 85;

if(count >= 90) {

System.out.println(" 합격(장학생)");

}else if(count >= 60) {

System.out.println("합격");

}else {

System.out.println(" 불합격");

}

int jumsu = (count/10)*10;

switch(jumsu) {

case 100:

case 90:

System.out.println(" 합격(장학생)");

break;

case 80:

System.out.println(" 80점 합격");

break;

case 70:

System.out.println(" 70점 합격");

break;

case 60:

System.out.println(" 60점 합격");

break;

default:

System.out.println(" 불합격");

}

*/




2. ----------------------------------------------------------------


----------------------------------------------------------------




public class Car {


String color;

int speed = 0;

static int carCount = 0;

final static int MAXSPEED = 200;

final static int MINSPEED = 0;

static int currentCarCount() {

return carCount;

}

Car(String color, int speed) {

this.color = color;

this.speed = speed;

carCount ++;

}

Car(int speed){

this.speed = speed;

}

Car(){

}

int getSpeed() {

return speed;

}

void upSpeed(int value) {

if(speed + value >= 200)

speed = 200;

else

speed = speed +value;

}

void downSpeed(int value) {

if(speed-value <=0)

speed=0;

else

speed = speed-value;

}


String getColor() {

return color;

}

}



3. ----------------------------------------------------------------


----------------------------------------------------------------


----------------------------------------------------------------

public class exam07 {

//public static void main(String[] args) {

Automobile auto = new Automobile();

auto.upSpeed(3000);

System.out.println("승용차의 속도는" 

+ auto.getSpeed()+"km 입니다");

}

}

/*

Car myCar1 = new Car("빨강",0);

Car myCar2 = new Car("파랑",0);

Car myCar3 = new Car("초록",0);

System.out.println("생산된 차의 대수-->"

+Car.carCount);

System.out.println("생산된 차의 대수-->"

+Car.currentCarCount());

System.out.println("차의 최고 제한속도-->"

+Car.MAXSPEED);

public class exam07 {


public static void main(String[] args) {

Car myCar1 = new Car("빨강",0);

Car myCar2 = new Car("파랑",0);

Car myCar3 = new Car("초록",0);

//Car myCar4 = new Car(0);

//Car myCar5 = new Car();


Car myCar1 = new Car();

myCar1.color = "빨강";

myCar1.speed = 0;

Car myCar2 = new Car();

myCar2.color = "파랑";

myCar2.speed = 0;

Car myCar3 = new Car();

myCar3.color = "초록";

myCar3.speed = 0;


myCar1.upSpeed(50);

System.out.println("자동차1의 색상은 " 

+ myCar1.getColor()

+"이며, 속도는"

+ myCar1.getSpeed() + "km 입니다");

myCar2.upSpeed(20);

System.out.println("자동차2의 색상은" 

+ myCar2.getColor()

+"이며, 속도는"

+ myCar2.getSpeed() + "km 입니다");

myCar3.upSpeed(250);

System.out.println("자동차3의 색상은" 

+ myCar3.getColor()

+"이며, 속도는"

+ myCar3.getSpeed() + "km 입니다");

myCar4.upSpeed(150);

System.out.println("자동차3의 색상은없으며  속도는"

+ myCar4.getSpeed() + "km 입니다");

}


}

*/




4. ----------------------------------------------------------------


----------------------------------------------------------------


----------------------------------------------------------------


----------------------------------------------------------------


public class Automobile extends Car {

int seatNum;

int getseatNum() {

return seatNum;

}

void upSpeed(int value) {

if(speed + value >= 300)

speed = 300;

else

speed = speed + (int)value;

}

}

댓글 영역