본문 바로가기

TIL139

23.06.03 팀과제 메모장 만들기에서 memoList 클래스를 만들기로 했다. package memoList; import java.util.ArrayList; import java.util.Scanner; public class MemoList { // 입력한 순서대로 출력하기에는 ArrayList가 제일 깔끔한 것 같아 ArrayList를 활용했습니다. private ArrayList memos = new ArrayList(); // 메모 전체를 조회하고 입력, 수정하기 위한 필수 요구 사항 Gettr/Setter public ArrayList getMemos() { return memos; } public void setMemos(ArrayList memos) { this.memos = memos; } // 수.. 2023. 6. 5.
23.06.05 배열 두 배로 하기 배열의 각 값을 두 배로 만들어 다시 배열로 출력하는 메서드 package spartaAlgorithmSheet; import java.util.Arrays; public class _03_doubleArray { public static void main(String[] args) { int[] array = {1, 41, -23, 100, 452, -234}; for (int i = 0; i < array.length; i++) { array[i] *= 2; } System.out.println(Arrays.toString(array)); } } 배열의 형태로 출력하기 우해 Arrays 를 사용했다. 배열 뒤집기 배열의 각 값을 순서를 반대로 출력하는 메서드 package spar.. 2023. 6. 5.
23.06.03 1. 몫 구하기 public class _01_getQuotient { public static void main(String[] args) { _01_getQuotient get = new _01_getQuotient(); System.out.println(get.getQuotient()); } private int getQuotient() { Scanner sc = new Scanner(System.in); int firstNumber = sc.nextInt(); // 나눠지는 숫자 int secondNumber = sc.nextInt(); // 나눌 숫자 int quotient = firstNumber/secondNumber; // 타입이 int이므로 소수점을 버려진다. return quotient.. 2023. 6. 3.
23.06.02 옵션 추가 기능을 위해 새로운 클래스를 만들거나 기존의 자료형들을 다시 만들어야 하나 고민하던 중 총 결산 기능을 만들 때 기존의 메서드와 클래스, 변수들을 재활용했던 경험을 살려 옵션도 기존의 객체들을 재활용해서 구현하려고 한다. 더보기 public boolean addOption(String menuName) { // 메뉴 카테고리만 확인 boolean option = true; String optionName; int optionPrice = 0; int optionCount = 1; if (!menuCollection.menuList().get(6).getMenuName().equals(menuName)) { // 디저트가 아니라면 옵션 추가 if (menuCollection.menuList()... 2023. 6. 2.