커뮤니티 - 자유게시판

자바 식권자판기 프로그램 짜는법과 주석문좀 부탁합니다~!

김짱
  • 작성일
    2024-05-24
  • 조회수
    2,415
자바공부하는 초보학생입니다. 식권자판기 짜주세요 예문입니다. 식권자판기가 있는데 메뉴는 3가지입니다 가격은 다 다르고요 1. 돈까지 2. 볶음밥 3. 라면 식권구매순서입니다 메뉴에 대해 몇매를 구입할건지 입력하고 돈남으면 다른메뉴선택합니다 단, 1000원짜리 메뉴를 2개 뽑는데 1500원을 넘었습니다 그럼 500원이 남는데 거스름돈이 나오게 하는방법하고, 돈을 더 넣어야 나오게하는 방법중 한가지를 선택해서 짜주시면 감사하겠습니다. 주석문좀 달아주십시요 1번째 public class Person { static Person [] persons = new Person[1 00]; static int next = 0; String name; int age; public Person(String name,int age) { this.name = name; this.age = age; System.out.println("Person created"); persons[next] = this; next++; } void identify( ){ System.out.println("Hi, I am " + this.getName()); } String getName() { return this.name; } int getAge() { return this.age; } void incrementAge() { age++; System.out.println("Age incremented"); } public boolean equals(Object o){ Person p = (Person) o; return (p.name.equals(this.name) && p.age == this.age); } static void printPersons() { for(int i=0; i < next; i++) { System.out.println("Name : " + persons[i].getName()); System.out.println("Age : " + persons[i].getAge()); } } public static void main(String args[]) { Person p = new Person("Peter", 25); p.identify(); p.incrementAge(); Person p2 = new Person("Mary",20); Person.printPersons(); // p1.printPerson ?, p2.printPerson ? } } 2번째 import java.util.*; class Shape { void draw() {} void erase() {} } class Circle extends Shape { void draw() { System.out.println("Circle.draw()"); } void erase() { System.out.println("Circle.erase()"); } } class Square extends Shape { void draw() { System.out.println("Square.draw()"); } void erase() { System.out.println("Square.erase()"); } } class Triangle extends Shape { void draw() { System.out.println("Triangle.draw()"); } void erase() { System.out.println("Triangle.erase()"); } } public class Shapes { public static Shape randShape() { switch((int)(Math.random()*3)) { default : // To quit the compiler case 0 : return new Circle(); case 1 : return new Square(); case 2 : return new Triangle(); } } public static void main(String args[]) { Shape s[] = new Shape[9]; // Fill up the array with shapes; for (int i=0;i < s.length;i++) s[i] = randShape(); // Make polymorphic method calls: for (int i = 0; i < s.length; i++) s[i].draw(); } }

댓글 0

자바 식권자판기 프로그램 짜는법과 주석문좀 부탁합니다~! : 창업정보 포털 오늘의창업