From 9446ae86681bec06f67487e7a79d8e7865747d2f Mon Sep 17 00:00:00 2001 From: Chanwoo Kim Date: Wed, 26 Feb 2025 15:57:09 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9E=85=EB=B6=80=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EB=AC=B8=EC=A0=9C=20=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- java_test/a.java | 6 ++- java_test/b.java | 13 +++++- java_test/c.java | 13 ++++++ java_test/d.java | 12 +++++ java_test/e.java | 17 +++++++ java_test/f.java | 20 ++++++++- java_test/g1.java | 41 ++++++++++++++++- java_test/g2.java | 110 +++++++++++++++++++++++++++++++++++++++++++++- 8 files changed, 227 insertions(+), 5 deletions(-) diff --git a/java_test/a.java b/java_test/a.java index 88363b2..7e63d42 100644 --- a/java_test/a.java +++ b/java_test/a.java @@ -1,10 +1,14 @@ package java_test; +import java.util.Scanner; + public class a { public static void main(String[] args) { - // 이 부분에 code를 작성해주세요! + var sc = new Scanner(System.in); + System.out.println(new StringBuilder(String.valueOf(sc.nextInt())).reverse()); + sc.close(); } } \ No newline at end of file diff --git a/java_test/b.java b/java_test/b.java index 4225cb2..8843af1 100644 --- a/java_test/b.java +++ b/java_test/b.java @@ -1,10 +1,21 @@ package java_test; +import java.util.Scanner; + public class b { public static void main(String[] args) { // 이 부분에 code를 작성해주세요! - + var sc = new Scanner(System.in); + for (char t : sc.nextLine().toCharArray()) { + if (t == 'a' || t == 'e' || t == 'i' || t == 'o' || t == 'u') { + System.out.println('O'); + sc.close(); + return; + } + } + System.out.println('X'); + sc.close(); } } \ No newline at end of file diff --git a/java_test/c.java b/java_test/c.java index f9d081f..99530f3 100644 --- a/java_test/c.java +++ b/java_test/c.java @@ -1,10 +1,23 @@ package java_test; +import java.util.Scanner; + public class c { public static void main(String[] args) { // 이 부분에 code를 작성해주세요! + var sc = new Scanner(System.in); + + var age = sc.nextInt(); + var height = sc.nextInt(); + sc.close(); + + if (age >= 14 || height >= 155) { + System.out.println('X'); + return; + } + System.out.println('O'); } } \ No newline at end of file diff --git a/java_test/d.java b/java_test/d.java index 0137ce5..03c2984 100644 --- a/java_test/d.java +++ b/java_test/d.java @@ -1,10 +1,22 @@ package java_test; +import java.util.Scanner; + public class d { public static void main(String[] args) { // 이 부분에 code를 작성해주세요! + var sc = new Scanner(System.in); + long n = 0; + n = sc.nextLong(); + sc.close(); + + if (n < 1) { + System.out.println('X'); + return; + } + System.out.println(n * (n + 1) / 2); } } \ No newline at end of file diff --git a/java_test/e.java b/java_test/e.java index 6daa449..bf001db 100644 --- a/java_test/e.java +++ b/java_test/e.java @@ -1,10 +1,27 @@ package java_test; +import java.util.Scanner; + public class e { public static void main(String[] args) { // 이 부분에 code를 작성해주세요! + var sc = new Scanner(System.in); + int year = sc.nextInt(); + int month = sc.nextInt(); + sc.close(); + if (month == 2) { + if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) + System.out.println(29); + else + System.out.println(28); + } else { + if (month == 4 || month == 6 || month == 9 || month == 11) + System.out.println(30); + else + System.out.println(31); + } } } \ No newline at end of file diff --git a/java_test/f.java b/java_test/f.java index 1249954..26a8d24 100644 --- a/java_test/f.java +++ b/java_test/f.java @@ -1,12 +1,30 @@ package java_test; +import java.util.Scanner; + // 이부분에 class 선언 해도 괜찮습니다 public class f { public static void main(String[] args) { // 이 부분에 code를 작성해주세요! - + var sc = new Scanner(System.in); + int n = sc.nextInt(); + sc.close(); + for (int i = 1; i <= n; ++i) { + for (int j = 0; j < n - i; ++j) + System.out.print(' '); + for (int j = 0; j < 2 * i - 1; ++j) + System.out.print('*'); + System.out.println(); + } + for (int i = 1; i < n; ++i) { + for (int j = 0; j < i; ++j) + System.out.print(' '); + for (int j = 0; j < 2 * (n - i) - 1; ++j) + System.out.print('*'); + System.out.println(); + } } } diff --git a/java_test/g1.java b/java_test/g1.java index 3d071e0..96b63e1 100644 --- a/java_test/g1.java +++ b/java_test/g1.java @@ -1,12 +1,51 @@ package java_test; +import java.util.Scanner; + // 이부분에 class 선언 해도 괜찮습니다 +class Fan { + private char model; + private int price; + + public void setModel(char model) { + this.model = model; + } + + public void setPrice(int price) { + this.price = price; + } + + public char getModel() { + return model; + } + + public int getPrice() { + return price; + } + + public Fan compare(Fan fan) { + return this.getPrice() < fan.getPrice() ? this : fan; + } +} + public class g1 { public static void main(String[] args) { // 이 부분에 code를 작성해주세요! - + var sc = new Scanner(System.in); + Fan cheapest = new Fan(); + cheapest.setPrice(1001); + for (int i = 0; i < 3; ++i) { + char model = sc.next().charAt(0); + int price = sc.nextInt(); + Fan fan = new Fan(); + fan.setModel(model); + fan.setPrice(price); + cheapest = cheapest.compare(fan); + } + sc.close(); + System.out.println(cheapest.getModel()); } } \ No newline at end of file diff --git a/java_test/g2.java b/java_test/g2.java index 5f214d7..56e8b1c 100644 --- a/java_test/g2.java +++ b/java_test/g2.java @@ -1,12 +1,120 @@ package java_test; +import java.util.Scanner; + // 이부분에 class 선언 해도 괜찮습니다 +abstract class Book { + private String title; + private int price; + private double rating; + + public double getRating() { + return rating; + } + + public Book(String title, int price, double rating) { + this.title = title; + this.price = price; + this.rating = rating; + } + + public void printData() { + System.out.println("Highest rated book information:"); + System.out.println("Title: " + title); + System.out.println("Price: " + price); + System.out.println("Rating: " + rating); + } + + public Book compareHigherRating(Book other) { + return rating < other.getRating() ? other : this; + } +} + +class EBook extends Book { + private int fileSize; + + public EBook(String title, int price, double rating, int fileSize) { + super(title, price, rating); + this.fileSize = fileSize; + } + + @Override + public void printData() { + super.printData(); + System.out.println("File Size: " + fileSize); + } +} + +class PrintedBook extends Book { + private int pageCount; + + public PrintedBook(String title, int price, double rating, int pageCount) { + super(title, price, rating); + this.pageCount = pageCount; + } + + @Override + public void printData() { + super.printData(); + System.out.println("Page Count: " + pageCount); + } +} + +class BookManager { + Book highest; + + public void scanBook(Scanner input) { + while (true) { + String type = input.nextLine(); + + if (!EBook.class.getSimpleName().equals(type) && + !PrintedBook.class.getSimpleName().equals(type)) { + System.out.println("Invalid book type. Please enter 'EBook' or 'PrintedBook'."); + continue; + } + + try { + String title = input.nextLine(); + int price = Integer.parseInt(input.nextLine()); + double rating = Double.parseDouble(input.nextLine()); + int other = Integer.parseInt(input.nextLine()); + + if (EBook.class.getSimpleName().equals(type)) + this.compare(new EBook(title, price, rating, other)); + + if (PrintedBook.class.getSimpleName().equals(type)) + this.compare(new PrintedBook(title, price, rating, other)); + break; + + } catch (NumberFormatException e) { + System.out.println("잘못된 입력입니다. 처음부터 다시 입력하세요."); + continue; + } + } + } + + public Book getHighest() { + return highest; + } + + public void compare(Book book) { + if (highest == null) + highest = book; + else + highest = highest.compareHigherRating(book); + } +} public class g2 { public static void main(String[] args) { // 이 부분에 code를 작성해주세요! - + var sc = new Scanner(System.in); + BookManager bookManager = new BookManager(); + for (int i = 0; i < 3; ++i) + bookManager.scanBook(sc); + sc.close(); + bookManager.getHighest().printData(); } } \ No newline at end of file