Skip to content
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 - 강두오 #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions kangduoh/first-java-assignment/.gitignore
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
8 changes: 8 additions & 0 deletions kangduoh/first-java-assignment/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions kangduoh/first-java-assignment/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions kangduoh/first-java-assignment/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions kangduoh/first-java-assignment/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions kangduoh/first-java-assignment/first-java-assignment.iml
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>
82 changes: 82 additions & 0 deletions kangduoh/first-java-assignment/src/assigns/Test1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package assigns;

// 다음 조건을 만족하도록 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을 전달 받아서 해당 필드 값을 초기화
Cylinder(int x, int y, double r) {
this.x = x;
this.y = y;
this.r = r;
}

// 생성자1: 정수 인자 x, y, height 와 실수 인자 r을 전달 받아서 해당 필드 값을 초기화
Cylinder(int x, int y, double r, int height) {
this.x = x;
this.y = y;
this.r = r;
this.height = height;
}

// circleArea 메서드: PI를 이용하여 원의 면적 반환
public double area() {
return PI * Math.pow(r, 2);
}

// volume 메서드: 면적과 높이를 이용하여 부피를 반환
public double volume() {
return area() * height;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

피드백
알고리즘이나 코드 상 문제가 없으나,
public double volume() { return this.area() * height; }
처럼 this 키워드를 추가해주는 것이 현재 객체의 area 메서드임을 명시하여 것으로 가독성 측면에서 조금 더 좋을 수 있다는 생각을 합니다!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗.. 그렇네요!
전체적으로 상세한 피드백 남겨주셔서 감사드립니다 😊


// surfaceArea 메서드: PI를 이용하여 원기둥의 겉넓이를 반환
public double surfaceArea() {
return 2 * PI * r * (r + height);
}

// move 메서드: 정수 인자 dx, dy를 전달 받아서 원의 중심 좌표를 이동
// - 예: 필드 x가 1이고 dx가 10이면 x는 11로 변경되어야 함
// 객체 자신을 반환
public 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.area());
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.area());
System.out.println(c2.volume());
System.out.println((float) c2.surfaceArea());
}
}
35 changes: 35 additions & 0 deletions kangduoh/first-java-assignment/src/bj_10810/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package bj_10810;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();

StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());

int[] basket = new int[N];

for (int l = 0; l < M; l++) {
st = new StringTokenizer(br.readLine());
int i = Integer.parseInt(st.nextToken());
int j = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());

for (int idx = i - 1; idx < j; idx++)
basket[idx] = k;
}

for (int l = 0; l < N; l++)
sb.append(basket[l]).append(' ');

System.out.println(sb);
br.close();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions kangduoh/first-java-assignment/src/bj_11021/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package bj_11021;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();

int T = Integer.parseInt(br.readLine());
StringTokenizer st = null;
int a, b;

for (int i = 1; i <= T; i++) {
st = new StringTokenizer(br.readLine());
a = Integer.parseInt(st.nextToken());
b = Integer.parseInt(st.nextToken());

sb.append("Case #").append(i).append(": ").append(a + b).append('\n');
}

System.out.println(sb);
br.close();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions kangduoh/first-java-assignment/src/bj_2439/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package bj_2439;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();

int N = Integer.parseInt(br.readLine());

for (int i = 0; i < N; i++) {
for (int j = 0; j < N - i - 1; j++)
sb.append(' ');

for (int k = 0; k <= i; k++)
sb.append('*');

sb.append('\n');
}

System.out.println(sb);
br.close();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions kangduoh/first-java-assignment/src/bj_2588/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package bj_2588;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

피드백
이렇게 StringBuilder를 사용하여 append 하신 게 평소 알고리즘에서 메모리에 대해 신경을 많이 쓰고 계신 것 같아 멋집니다 😎


int num1 = Integer.parseInt(br.readLine());
int num2 = Integer.parseInt(br.readLine());

sb.append(num1 * (num2 % 10)).append('\n');
sb.append(num1 * (num2 / 10 % 10)).append('\n');
sb.append(num1 * (num2 / 100)).append('\n');
sb.append(num1 * num2);

System.out.println(sb);
br.close();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions kangduoh/first-java-assignment/src/bj_2884/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package bj_2884;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();

StringTokenizer st = new StringTokenizer(br.readLine());
int h = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());

if (m < 45) {
h = (h + 23) % 24;
m += 15;
}
else
m -= 45;
Comment on lines +17 to +22
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

피드백
저는 중첩 if로 입력된 시간에 따라 나눌 생각을 하였는데, 이렇게 풀이한 걸 보고 놀랐습니당! 새로운 사고 방식 배워갑니다


sb.append(h).append(' ').append(m);
System.out.println(sb);
br.close();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions kangduoh/first-java-assignment/src/bj_9086/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package bj_9086;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();

int T = Integer.parseInt(br.readLine());
String in;

for (int i = 0; i < T; i++) {
in = br.readLine();
sb.append(in.charAt(0)).append(in.charAt(in.length() - 1)).append('\n');
}

System.out.println(sb);
br.close();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.