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

입부테스트 문제 풀이 #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion java_test/a.java
Original file line number Diff line number Diff line change
@@ -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();
}

}
13 changes: 12 additions & 1 deletion java_test/b.java
Original file line number Diff line number Diff line change
@@ -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();
}

}
13 changes: 13 additions & 0 deletions java_test/c.java
Original file line number Diff line number Diff line change
@@ -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');
}

}
12 changes: 12 additions & 0 deletions java_test/d.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
17 changes: 17 additions & 0 deletions java_test/e.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

}
20 changes: 19 additions & 1 deletion java_test/f.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

}
41 changes: 40 additions & 1 deletion java_test/g1.java
Original file line number Diff line number Diff line change
@@ -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());
}

}
110 changes: 109 additions & 1 deletion java_test/g2.java
Original file line number Diff line number Diff line change
@@ -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();
}

}