과제1

Person

package ch01;

public class Person {

	public int heigth;
	public int weight;
	public int age;
	public String name;
	
	public Person() {
		
	}
	public Person(int heigth, int weight, int age, String name) {
		
		this.heigth=heigth;
		this.age = age;
		this.weight=weight;
		this.name=name;
		
	}
	public void printinfo() {
		System.out.println("키는 "+heigth);
		System.out.println("몸무게는 "+weight);
		System.out.println("나이는 "+age);
		System.out.println("이름은 "+name);
		
	}
	
}

PersonTest

package ch01;

public class PersonTest {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Person tomasInfo = new Person(180,78,20,"Tomas");
		
		tomasInfo.printinfo();
	}

}

과제2

Delivary

package ch01;

public class Delivary {
	public String orderNum;
	public String orderPhoneNum;
	public String address;
	public int date;
	public int price;
	public int menuNum;
	
	public Delivary() {
		
	}
	public Delivary(String orderNum, String orderPhoneNum,String address, int date, int price, int menuNum) {
		this.orderNum=orderNum;
		this.orderPhoneNum=orderPhoneNum;
		this.address=address;
		this.date=date;
		this.price=price;
		this.menuNum=menuNum;
	}
	public void printInfo() {
		System.out.println("주문 접수 번호: "+orderNum);
		System.out.println("주문 핸드폰 번호: "+orderPhoneNum);
		System.out.println("주문 집 주소: "+address);
		System.out.println("주문 날짜: "+date);
		System.out.println("주문 가격: "+price);
		System.out.println("메뉴 번호: "+menuNum);
		
	}
	
}

DelivaryOrder

package ch01;

public class DelivaryOrder {

	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Delivary order1 = new Delivary("202011020003","01023450001","서울 강남시 역삼동 111-333", 20201102,35000,3);
		order1.printInfo();
		
	}

}
package ch01;


public class Student {
	public int studentNumber;
	public String studentName;
	public int grade;
	
	public Student() {
		//client code에서 default생성자를 사용하고 싶을 때 따로 생성해주기
	}
	public Student(int studentNumber, String studentName) {
		//매개변수로 정보를 받아 생성자에서 초기화 시키고자 할 때
		
		//가장 가까운 곳에서 변수를 받아오기 때문에 매개변수에 매개변수를 대입하는 꼴이 됨
		studentNumber= studentNumber;
		// 하지만 원하는 건 매개변수를 멤버변수에 대입하는 것
		// this를 사용해 멤버변수임을 지정해주기
		this.studentNumber=studentNumber;
		this.grade=grade;
		this.studentName=studentName;
		
		//생성자는 객체가 생성될떄 실행되는 함수
		System.out.println("student 생성");
	}
	public String showStudentInfo() {
		
		return studentName+"학생의 학번은 "+studentNumber+", "+grade+"학년입니다.";
	}
	
	}
package ch01;

public class StudentTest {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
			Student StudentLee= new Student();
			
			System.out.println(StudentLee.showStudentInfo());
			
			Student studentKim = new Student(123456,"kim");
			System.out.println(studentKim.showStudentInfo());
	}

}
package ch01;

class School{
	//class를 여러개 가질 수 있음
} 
public class Student { // 그러나 public class는 단 하나 , 자바 파일의 이름과 클래스 이름이 같아야O
	int studentNumeber;
	String studentName;
	int majorCode;
	String majorName;
	int grade;
	
	
	
}
package ch01;


public class Student { // 그러나 public class는 단 하나 , 자바 파일의 이름과 클래스 이름이 같아야O
	public static int addNum(int num1, int num2) {
		
		int result;
		result=num1+num2;
		return result;
	}
	public static void sayHello(String greeting) {
		System.out.println(greeting);
	}
	public static int calSum() {
		int sum=0;
		int i;
		for(i=0;i<10;i++) {
			sum+=i;
		}
		return sum;
	}
	public static void main (String[] args) {
		int n1=10;
		int n2=20;
		
		int total= addNum(n1,n2);
		System.out.println(total);
		
		sayHello("안녕하세요");
		
		total=calSum();
		System.out.println(total);
	}
}

 

 

 

'WEB > Java' 카테고리의 다른 글

[JAVA] 객체지향입문- 과제  (0) 2023.01.21
[JAVA] 객체지향입문- 생성자(Constructor)  (0) 2023.01.21
[java] 자바 프로그래밍 - 연산자  (0) 2023.01.04
[java] 자바 프로그래밍 - 상수  (0) 2023.01.04
[GUI]  (0) 2022.12.22

증가, 감소 연산자 (순서 유의)

package ch01;

public class HelloWorld {
	public static void main(String[] args) {
		
		int gameScore=150;
		int lastScore=gameScore++;
		
		System.out.println(lastScore); //150
		System.out.println(gameScore); //151
		
		
		
	}
}

논리 연산자, 단락회로평가

package ch01;

public class HelloWorld {
	public static void main(String[] args) {
		
		int num1=10;
		int i=2;
		
		boolean value= ((num1=num1+10)<10)&& ((i=i+2)<10);
		
		
		System.out.println(value); //false
		System.out.println(num1); //20
		System.out.println(i); //2 <-i의 값 바뀌지 않음, 뒤의 항 계산하지 않기 때문
		
	}
}

'WEB > Java' 카테고리의 다른 글

[JAVA] 객체지향입문- 생성자(Constructor)  (0) 2023.01.21
[JAVA] 객체지향입문 - 객체 구현하기  (0) 2023.01.15
[java] 자바 프로그래밍 - 상수  (0) 2023.01.04
[GUI]  (0) 2022.12.22
[java] 자바 프로그래밍 - 자료형  (0) 2022.12.22
package ch01;

public class HelloWorld {
	public static void main(String[] args) {
		
		final int max=100;
		final int min=10; //상수는 반드시 값을 지정해야O
		
		System.out.println(max);
		System.out.println(min);
		
		
		
	}
}

 

'WEB > Java' 카테고리의 다른 글

[JAVA] 객체지향입문 - 객체 구현하기  (0) 2023.01.15
[java] 자바 프로그래밍 - 연산자  (0) 2023.01.04
[GUI]  (0) 2022.12.22
[java] 자바 프로그래밍 - 자료형  (0) 2022.12.22
[java] 자바 프로그래밍  (0) 2022.08.28
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class HelloSwing {
	public static void main (String[] args) {
		JFrame f= new JFrame ("Hello");
		JPanel p = new JPanel();
		JButton b = new JButton("Press Me");
		
		f.setSize(400,400);
		f.setContentPane(p);
		p.add(b);//판넬에 버튼을 추가
		
		f.setVisible(true);
	}

}

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class JComponentExample {

	class MyJComponent extends JComponent{
		public void paint (Graphics g) {
			g.setColor(Color.green);
			g.fillOval(50,10,150,150);
		}
	}
	
	public static void main(String[] argument) {
		
		MyJComponent com = new MyJComponent();
	
		JFrame.setDefaultLookAndFeelDecorated(true);
		JFrame frame = new JFrame("JComponent Example");
		frame.setSize(300,200);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	
		frame.add(com);
		frame.setVisible(true);
}

}
package ch01;

public class HelloWorld {
	public static void main(String[] args) {
		int num=10;
		int bNum=0B1010;//binary num 2진수
		int oNum=012; //8진수
		int xNum=0XA;
		
		System.out.println(num);
		System.out.println(bNum);
		System.out.println(oNum);
		System.out.println(xNum);
	}
}
package ch01;

public class HelloWorld {
	public static void main(String[] args) {
		
		byte bnum= -128;
		System.out.println(bnum);
		
		long num=1237423823489L;
		System.out.println(num);
		
		
	}
}
package ch01;

public class HelloWorld {
	public static void main(String[] args) {
		
		double dnum = 3.14;
		float fnum= 3.14; // 오류, 뒤에 식별자를 써야 O
		
		float fnum2 =3.14f;
		
		
		
	}
}

자료형 - 문자 표현 방법

package ch01;

public class HelloWorld {
	public static void main(String[] args) {
		char ch1= 'A';
		System.out.println(ch1); //A
		System.out.println((int)ch1); //65
		
	}
}

character set: 문자를 숫자로 변환한 값의 세트

encoding : 문자가 숫자로 변환되는 것

decoding: 숫자에서 다시 문자로 변환되는 것

ASKII code: 알파벳과 숫자 특수 문자 등을 1바이트 표현하는데 사용하는 문자 세트

UNICODE: 전 세계 표준으로 만든 문자 세트

UTF-8: 1바이트에서 4바이트 까지 다양하게 문자를 표현할 수 있음

UTF-16: 2바이트를 문자로 표

 

지역변수 자료형 없이 표현하기

package ch01;

public class HelloWorld {
	public static void main(String[] args) {
		var i=10;
		var j=10.0;
		var k="hello";
		
		System.out.println(i);
		System.out.println(j);
		System.out.println(k);
		
		
	}
}

 

//강의표

https://gitlab.com/easyspubjava/javacoursework/-/tree/master/

'WEB > Java' 카테고리의 다른 글

[JAVA] 객체지향입문 - 객체 구현하기  (0) 2023.01.15
[java] 자바 프로그래밍 - 연산자  (0) 2023.01.04
[java] 자바 프로그래밍 - 상수  (0) 2023.01.04
[GUI]  (0) 2022.12.22
[java] 자바 프로그래밍  (0) 2022.08.28
01 자바 프로그래밍 시작하기

컴파일: 프로그래밍 언어->기계어

Java: 자바 소스코드-> 자바 컴파일러 (JVM) (운영체제 상관없이, 플랫폼 영향X)

객체지향 프로그래밍: 프로그램의 구현을 시간 흐름순(절차 지향 언어)X, 객체간의 관계,협력O

 

'WEB > Java' 카테고리의 다른 글

[JAVA] 객체지향입문 - 객체 구현하기  (0) 2023.01.15
[java] 자바 프로그래밍 - 연산자  (0) 2023.01.04
[java] 자바 프로그래밍 - 상수  (0) 2023.01.04
[GUI]  (0) 2022.12.22
[java] 자바 프로그래밍 - 자료형  (0) 2022.12.22

+ Recent posts