-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1주차 Assignment - 박연지 #3
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
### IntelliJ IDEA ### | ||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
bin/ | ||
!**/src/main/**/bin/ | ||
!**/src/test/**/bin/ | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package assignments; | ||
|
||
// 다음 조건을 만족하도록 Cylinder 클래스를 작성합니다. | ||
class Cylinder { | ||
|
||
// 원주율 3.14를 정적 상수 PI로 선언과 동시에 초기화 | ||
static final double PI = 3.14; | ||
|
||
// 정수형 원의 중심 좌표 x, y를 선언 | ||
int x, y; | ||
|
||
// 실수형 원의 반지름 r을 선언 | ||
double r; | ||
|
||
// 정수형 원기둥의 높이 height를 10으로 선언과 동시에 초기화 | ||
int height = 10; | ||
|
||
// 생성자1: 정수 인자 x, y 와 실수 인자 r을 전달 받아서 해당 필드 값을 초기화 | ||
public Cylinder(int x, int y, double r) { | ||
this.x = x; | ||
this.y = y; | ||
this.r = r; | ||
} | ||
|
||
// 생성자2: 정수 인자 x, y, height 와 실수 인자 r을 전달 받아서 해당 필드 값을 초기화 | ||
public Cylinder(int x, int y, double r, int height) { | ||
this.x = x; | ||
this.y = y; | ||
this.height = height; | ||
this.r = r; | ||
} | ||
|
||
// circleArea 메서드: PI를 이용하여 원의 면적 반환 | ||
double circleArea() { | ||
return r * r * PI; | ||
} | ||
|
||
// volume 메서드: 면적과 높이를 이용하여 부피를 반환 | ||
double volume() { | ||
return r * r * PI * height; | ||
} | ||
|
||
// surfaceArea 메서드: PI를 이용하여 원기둥의 겉넓이를 반환 | ||
double surfaceArea() { | ||
return (r * r * PI * 2) + (2 * PI * r * height); | ||
} | ||
|
||
// move 메서드: 정수 인자 dx, dy를 전달 받아서 원의 중심 좌표를 이동 | ||
// - 예: 필드 x가 1이고 dx가 10이면 x는 11로 변경되어야 함 | ||
// 객체 자신을 반환 | ||
Cylinder move(int dx, int dy) { | ||
this.x += dx; | ||
this.y += dy; | ||
|
||
return this; | ||
} | ||
|
||
void print() { | ||
System.out.println("<"+x+","+y+":"+r+">"); | ||
} | ||
} | ||
|
||
|
||
// 메인메서드 수행시 이렇게 출력되도록 | ||
//<13,15:6.0> | ||
//113.04 | ||
//1130.4 | ||
//602.88 | ||
//<17,25:10.0> | ||
//314.0 | ||
//1570.0 | ||
//942.0 | ||
public class Test1 { | ||
public static void main(String[] args) { | ||
Cylinder c1 = new Cylinder(3,5, 6); | ||
c1.move(10,10).print(); | ||
System.out.println(c1.circleArea()); | ||
System.out.println(c1.volume()); | ||
System.out.println(c1.surfaceArea()); | ||
|
||
Cylinder c2 = new Cylinder(5,8,10,5); | ||
c2.move(12,17).print(); | ||
System.out.println(c2.circleArea()); | ||
System.out.println(c2.volume()); | ||
System.out.println(c2.surfaceArea()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" packagePrefix="assignments" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package bj_10810; | ||
import java.util.Scanner; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
int N = scanner.nextInt(); | ||
int M = scanner.nextInt(); | ||
|
||
int i, j, k; | ||
|
||
int array[] = new int[N]; | ||
|
||
for(int x=0;x<M;x++) { | ||
i = scanner.nextInt(); | ||
j = scanner.nextInt(); | ||
k = scanner.nextInt(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scanner 잘 사용해주신거같은데 이 Scanner가 사용하기 쉽지만 대량의 데이터를 입력 받을 때 성능 문제가 생길 수 있습니다. 더 효율적인 코드를 위해서는 BufferedReader를 사용하는 것도 추천드립니다. 아래 블로그 참고해보시면 좋을 거같습니다~! |
||
|
||
for(int l=i-1;l<j;l++) { | ||
array[l] = k; | ||
} | ||
} | ||
|
||
for(int y=0;y<N;y++) { | ||
System.out.print(array[y] + " "); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package bj_11021; | ||
import java.util.Scanner; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
int T = scanner.nextInt(); | ||
int A,B; | ||
|
||
for(int i=1;i<=T;i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 간단한 자바코드 작성시에는 System.out.println()를 반복적으로 사용해도 좋지만 결과를 StringBuilder에 추가해두었다가 마지막에 한번에 출력하는 방식도 사용해볼 수 있습니다.
|
||
A = scanner.nextInt(); | ||
B = scanner.nextInt(); | ||
|
||
System.out.println("Case #" + i + ": " + (A+B)); | ||
} | ||
|
||
scanner.close(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package bj_2439; | ||
import java.util.Scanner; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
int num = scanner.nextInt(); | ||
|
||
for(int i=1;i<=num;i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 중첩 반복문을 활용하여 잘 구현해주셨습니다! 앞으로 코드 작성을 할 때 for(int i=1;i<=num;i++)이런식으로 붙여 사용하시는 것보다 가독성을 위해 for (int i = 1; i <= num; i++) 이런 식으로 작성하시는 것을 추천드립니다. 또한 별찍기 문제는 이것 외에도 많으니 반복문을 더 자세히 공부하고 싶으시다면 관련 문제를 더 풀어보시는 것도 좋을 거같습니다. |
||
for(int j=num;j>i;j--) { | ||
System.out.print(" "); | ||
} | ||
for(int k=0;k<i;k++) { | ||
System.out.print("*"); | ||
} | ||
System.out.println(); | ||
} | ||
|
||
scanner.close(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package bj_2588; | ||
import java.util.Scanner; | ||
public class Main { | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
int num1 = scanner.nextInt(); | ||
int num2 = scanner.nextInt(); | ||
|
||
System.out.println(num1 * (num2%10)); | ||
System.out.println(num1 * ((num2 % 100)/10)); | ||
System.out.println(num1 * (num2/100)); | ||
System.out.println(num1 * num2); | ||
|
||
scanner.close(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package bj_2884; | ||
import java.util.Scanner; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
int H = scanner.nextInt(); | ||
int M = scanner.nextInt(); | ||
|
||
if(M<45) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if(H==0) { | ||
H += 23; | ||
M += 60; | ||
M -= 45; | ||
System.out.println(H + " " + M); | ||
} | ||
else { | ||
H -= 1; | ||
M += 60; | ||
M -= 45; | ||
System.out.println(H + " " + M); | ||
} | ||
} | ||
else{ | ||
M -= 45; | ||
System.out.println(H + " " + M); | ||
} | ||
scanner.close(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package bj_9086; | ||
import java.util.Scanner; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
int T = scanner.nextInt(); | ||
scanner.nextLine(); | ||
|
||
for(int i=0;i<T;i++) { | ||
String str = scanner.nextLine(); | ||
System.out.println(str.charAt(0) + "" + str.charAt(str.length()-1)); | ||
} | ||
|
||
scanner.close(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
클래스의 필드를 아래와 같이 private으로 선언하는 것이 객체 지향 프로그래밍의 중요한 원칙 중 하나인 캡슐화를 구현하기 위한 좋은 방법입니다. 참고해주세요!