인공지능/JAVA

5.6 인공지능 JAVA

bibibig_data 2021. 6. 5. 21:17

오전 9-10

전반적인 목차에 대한 설명

오전 10-12 미적분

다음주에 연습문제 쪽지시험 . . . . . . .^^

오후 1-2

https://www.geeksforgeeks.org/association-composition-aggregation-java/

- Association.java

- Aggregation.java

- Composition.java

- CarWithEngine.java

직접 코드 연습해보기

 

--------------------

> Association.java <

--------------------

package com.java.association;

class Bank {

private String name;

Bank(String name) {

this.name = name;

}

public String getBankName() {

return this.name;

}

}

class Employee {

private String name;

Employee(String name) {

this.name = name;

}

public String getEmployeeName() {

return this.name;

}

}

// Association between both the classes in main method

public class Association {

public static void main(String[] args) {

Bank bank = new Bank("Axis");

Employee emp = new Employee("Neha");

System.out.println(emp.getEmployeeName() + " is employee of " + bank.getBankName());

}

}


--------------------

> Aggregation.java <

--------------------

package com.java.association;

import java.util.ArrayList;

import java.util.List;

class Student {

String name;

int id;

String dept;

Student(String name, int id, String dept) {

this.name = name;

this.id = id;

this.dept = dept;

}

}

class Department {

String name;

private List<Student> students;

Department(String name, List<Student> students) {

this.name = name;

this.students = students;

}

public List<Student> getStudents() {

return students;

}

}

class Institute {

String instituteName;

private List<Department> departments;

Institute(String instituteName, List<Department> departments) {

this.instituteName = instituteName;

this.departments = departments;

}

public int getTotalStudentsInInstitute() {

int noOfStudents = 0;

List<Student> students;

for (Department dept : departments) {

students = dept.getStudents();

for (Student s : students) {

noOfStudents++;

}

}

return noOfStudents;

}

}

public class Aggregation {

public static void main(String[] args) {

Student s1 = new Student("Mia", 1, "CSE");

Student s2 = new Student("Priya", 2, "CSE");

Student s3 = new Student("John", 1, "EE");

Student s4 = new Student("Rahul", 2, "EE");

// making a List of CSE Students.

List<Student> cse_students = new ArrayList<Student>();

cse_students.add(s1);

cse_students.add(s2);

// making a List of EE Students

List<Student> ee_students = new ArrayList<Student>();

ee_students.add(s3);

ee_students.add(s4);

Department CSE = new Department("CSE", cse_students);

Department EE = new Department("EE", ee_students);

List<Department> departments = new ArrayList<Department>();

departments.add(CSE);

departments.add(EE);

// creating an instance of Institute.

Institute institute = new Institute("BITS", departments);

System.out.print("Total students in institute: ");

System.out.print(institute.getTotalStudentsInInstitute());

}

}


--------------------

> Composition.java <

--------------------

package com.java.association;

import java.util.ArrayList;

import java.util.List;

class Book {

public String title;

public String author;

Book(String title, String author) {

this.title = title;

this.author = author;

}

}

class Library {

private final List<Book> books;

Library(List<Book> books) {

this.books = books;

}

public List<Book> getTotalBooksInLibrary() {

return books;

}

}

public class Composition {

public static void main(String[] args) {

// Creating the Objects of Book class.

Book b1 = new Book("EffectiveJ Java", "Joshua Bloch");

Book b2 = new Book("Thinking in Java", "Bruce Eckel");

Book b3 = new Book("Java: The Complete Reference", "Herbert Schildt");

// Creating the list which contains the no. of books.

List<Book> books = new ArrayList<Book>();

books.add(b1);

books.add(b2);

books.add(b3);

Library library = new Library(books);

List<Book> bks = library.getTotalBooksInLibrary();

for (Book bk : bks) {

System.out.println("Title : " + bk.title + " and " + " Author : " + bk.author);

}

}

}


----------------------

> CarWithEngine.java <

----------------------

package com.java.association;

// Engine class which will be used by car.

// so 'Car' class will have a field of Engine type.

class Engine {

public void work() {

System.out.println("Engine of car has been started ");

}

}

final class Car {

// for a car to move, it need to have a engine.

private final Engine engine; // Composition

// private Engine engine; // Aggregation

Car(Engine engine) {

this.engine = engine;

}

// car start moving by starting engine

public void move() {

if (engine != null) {

engine.work();

System.out.println("Car is moving ");

}

}

}

public class CarWithEngine {

public static void main(String[] args) {

// making an engine by creating

// an instance of Engine class.

Engine engine = new Engine();

// making a car with engine.

// so we are passing a engine instance

// as an argument while creating instance of Car.

Car car = new Car(engine);

car.move();

}

}


Class A {

B b ;

public A(){

b = new B();

}

A가 사라지면 b, B도 사라진다 . = composition 관계

영향을 받지 않음 = aggregation

애매 = association

그냥 받기만 하고 영향엑스 ,, ? ex) 문자로 그냥 출력 = dependency


2-3시

UML 서브노트 유튜브영상 시청

1) 연관관계

-연관관계 ex) 댓글 목록과 게시글 실선

-직접연관관계 ex )게시물과 댓글 화살표

-집합연관관계 ex )빈 마름모

-합성연관관계 ex) 속이 찬 마름모 강한연관관계 게시물이 삭제되면 댓글도 삭제

2) 의존관계

-확장의존관계 ex) 점섬화살표, <Extend>표기

-포함 의존관계 ex) 점선화살표 , <Include>표기

3) 일반화관계

부모와 자식 클래스

4) 실체화 관계

점선에 빈 화살표

실제 작업은 자식클래스에서


- https://mobilenweb.tistory.com/112 : AmaterasUML 다운로드 및 설치하기

- https://mobilenweb.tistory.com/113 : Class Diagram

- https://mobilenweb.tistory.com/114 : Usecase Diagram

- https://mobilenweb.tistory.com/115 : Sequence Diagram

링크에서 zip파일 다운받아서 압축 푼 후 복사해서 dev 이클립스폴더에 붙여넣기

그럼 이클립스에서 new -> other 가면 다운받은거 있어연


3-4시

이것이 자바다 공부

# 단항 연산자

- 부호 연산자 : +, -

- 증감 연산자 : ++, --

- 논리 부정 연산자 : !

- 비트 반전 연산자 : ~

# 이항 연산자

- 산술 연산자 : + , -, *, /, %

- 문자열 연결 연산자 : +

- 비교 연산자 : >, >=, <, <=, ==, !=

- 논리 연산자 : &&, ||, &, |

- 비트 논리 연산자 : &, |, ^,

- 비트 이동 연산자 : >>, <<, >>>

- 대입 연산자 : =, +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=, >>>=

# 삼항 연산자

- 삼항 연산자 : A ? B : C

10장 예외처리