주사위 게임 주사위 2개를 가지고 하는 게임 작성 주사위 굴리는 건 랜덤 값으로 처리 플레이어 선택 => 키보드 입력

Slides:



Advertisements
Similar presentations
IS Programming Fundamentals 1 (Lec) Date: September 14, Array.
Advertisements

CS Network Programming CS 3331 Fall CS 3331 Outline Socket programming Remote method invocation (RMI)
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
1 Streams and Input/Output Files Part 2. 2 Files and Exceptions When creating files and performing I/O operations on them, the systems generates errors.
Taking Input Java Md. Eftakhairul Islam
Iterations for loop. Outcome Introduction to for loop The use of for loop instead of while loop Nested for loops.
Input review If review Common Errors in Selection Statement Logical Operators switch Statements Generating Random Numbers practice.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Copyright © Recursive GCD Demo public class.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
Lecture 15: I/O and Parsing
Java Review – Exec, I/O, New Features George Blankenship1 CSCI 6234 Object Oriented Design: Java Review – Execution, I/O and New Features George Blankenship.
Simple Programs Simple Strings Writing some programs Only in Parameters? I/O Gadget.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Java File I/O. File I/O is important! Being able to write and read from files is necessary and is also one common practice of a programmer. Examples include.
MOD III. Input / Output Streams Byte streams Programs use byte streams to perform input and output of 8-bit bytes. This Stream handles the 8-bit.
1 Java Remote Method Invocation java.rmi.* java.rmi.registry.* java.rmi.server.*
Formal Language, chapter 4, slide 1Copyright © 2007 by Adam Webber Chapter Four: DFA Applications.
LYNBROOK COMPUTER SCIENCE CLUB MONDAY, OCTOBER 26, 2009 POWERPOINT CREATED BY: RITIK MALHOTRA PRESENTATION BY: KARTHIK VISWANATHAN Intro to USACO.
Graohics CSC 171 FALL 2001 LECTURE 16. History: COBOL Conference on Data System Languages (CODASYL) - led by Joe Wegstein of NBS developed the.
Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
Software Engineering Implementation Lecture 3 ASPI8-4 Anders P. Ravn, Feb 2004.
Craps. /* * file : Craps.java * file : Craps.java * author: george j. grevera, ph.d. * author: george j. grevera, ph.d. * desc. : program to simulate.
Multiplexing/Demux. CPSC Transport Layer 3-2 Multiplexing/demultiplexing application transport network link physical P1 application transport network.
Public class ABC { private int information = 0; private char moreInformation = ‘ ‘; public ABC ( int newInfo, char moreNewInfo) { } public ABC () {} public.
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
Değişik Parametreli Nesne Tanımı 1. Object with parameter Class Box { double width; double height; double depth; Box(Box ob) { width=ob.width; height=ob.height;
1 Working with String Duo Wei CS110A_ Empty Strings An empty string has no characters; its length is 0. Not to be confused with an uninitialized.
Building Java Programs
Computer Programming Lab 8.
Distribuerade system Java Sockets RMI Etc.. Vad är distribuerade system Distr system är enkla att förstå –Distribuera last –Centrala funktioner på samma.
Exception Handling – illustrated by Java mMIC-SFT November 2003 Anders P. Ravn Aalborg University.
1 Fall 2009ACS-1903 The break And continue Statements a break statement can be used to abnormally terminate a loop. use of the break statement in loops.
Unit 201 FILE IO Types of files Opening a text file for reading Reading from a text file Opening a text file for writing/appending Writing/appending to.
Java Threads A tool for concurrency. OS schedules processes Ready Running 200 Blocked A process loses the CPU and another.
Exception examples. import java.io.*; import java.util.*; class IO { private String line; private StringTokenizer tokenizer; public void newline(DataInputStream.
1 Text File I/O  I/O streams  Opening a text file for reading  Closing a stream  Reading a text file  Writing and appending to a text file.
1 Text File I/O Overview l I/O streams l Opening a text file for reading l Reading a text file l Closing a stream l Reading numbers from a text file l.
SELECTION CSC 171 FALL 2004 LECTURE 8. Sequences start end.
1 Streams Overview l I/O streams l Opening a text file for reading l Reading a text file l Closing a stream l Reading numbers from a text file l Writing.
7/2/2015CS2621 OO Design and Programming II I/O: Reading and Writing.
16-Aug-15 Java Puzzlers From the book Java Puzzlers by Joshua Bloch and Neal Gafter.
Using java’s Scanner class To read from input and from a file. (horstmann ch04 and ch 17)
Java Programming: I/O1 Java I/O Reference: java.sun.com/docs/books/tutorial/essential/io/
Java Exception Handling Handling errors using Java’s exception handling mechanism.
Example 1 :- Handling integer values public class Program1 { public static void main(String [] args) { int value1, value2, sum; value1 = Integer.parseInt(args[0]);
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
SOFTWARE TECHNOLOGY - I CONSTANTS VARIABLES DATA TYPES.
Loops, Methods, Classes Loops, Methods, Using API Classes, Exceptions SoftUni Team Technical Trainer Software University
Console Input. So far… All the inputs for our programs have been hard-coded in the main method or inputted using the dialog boxes of BlueJ It’s time to.
Chapter 9 1 Chapter 9 – Part 1 l Overview of Streams and File I/O l Text File I/O l Binary File I/O l File Objects and File Names Streams and File I/O.
Lecture 16: Multithreaded Programming. public partial class Form1 : Form { Thread ct; Thread rt; public static int circle_sleep = 0; public static int.
Networks Sockets and Streams. TCP/IP in action server ports …65535 lower port numbers ( ) are reserved port echo7 time13 ftp20 telnet23.
Java Exception Handling Handling errors using Java’s exception handling mechanism.
CS101 Lab “File input/Output”. File input, output File : binary file, text file READ/WRITE class of “text file” - File Reading class : FileReader, BufferedReader.
State Design Pattern. Behavioral Pattern Allows object to alter its behavior when internal state changes Uses Polymorphism to define different behaviors.
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
LOGO 형식언어와 오토마타 컴퓨터 공학부 4 학년 서정태
CSCI 1100/1202 January 23, Class Methods Some methods can be invoked through the class name, instead of through an object of the class These methods.
Chapter 5 : Methods Part 2. Returning a Value from a Method  Data can be passed into a method by way of the parameter variables. Data may also be returned.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Loops, Methods, Classes Using Loops, Defining and Using Methods, Using API Classes, Exceptions, Defining Classes Svetlin Nakov Technical Trainer
CS 121 – Intro to Programming:Java - Lecture 4 Announcements Course home page: Owl due soon; another.
using System; namespace Demo01 { class Program
Accessing Files in Java
Operators Laboratory /11/16.
הרצאה 12: קבצים וחריגות (Exceptions)
null, true, and false are also reserved.
Java Exception Handling
Presentation transcript:

주사위 게임 주사위 2개를 가지고 하는 게임 작성 주사위 굴리는 건 랜덤 값으로 처리 플레이어 선택 => 키보드 입력 High (합이 6이상) Low (합이 6이하)

주사위 Class class jusa { private int junum; public jusa() rannum(); } public void rannum() junum = 1+ (int)(Math.random()*6); public int getju() return junum;

Main int money = Integer.parseInt(args[0]); jusa j1 = new jusa (); int sum=0, win=0, lose=0; String read=null; BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); while (money>=100) { System.out.println("High? low?"); try read = buf.readLine(); } catch(Exception e){} j1.rannum(); j2.rannum(); sum = j1.getju() + j2.getju();

if (read.equalsIgnoreCase("high")) { if (sum>=7) System.out.println("----- You Win -----"); System.out.println("Computer Value : "); System.out.println("Jusa 1 : " +j1.getju()); System.out.println("Jusa 2 : " +j2.getju()); System.out.println("Sum : " +sum); System.out.println("-------------------"); win++; } else System.out.println("----- You lose -----"); lose++;

if (read.equalsIgnoreCase(“low")) { if (sum<7) System.out.println("----- You Win -----"); System.out.println("Computer Value : "); System.out.println("Jusa 1 : " +j1.getju()); System.out.println("Jusa 2 : " +j2.getju()); System.out.println("Sum : " +sum); System.out.println("-------------------"); win++; } else System.out.println("----- You lose -----"); lose++;

else { System.err.println("error"); } money = money-100; System.out.println("---------- Quit Game ----------"); System.out.println("Win : " +win + " Lose : " + lose);

가위/바위/보 게임 컴퓨터와 플레이어가 가위/바위/보 플레이어 선택 => 키보드 입력 컴퓨터 선택은 랜덤값으로 처리 가위

class Chand { private int ran_num; void rnd() { ran_num =1+(int)(Math.random()*3); } int val() { return ran_num; };

class ex2 { public static void main(String[] args) throws java.io.IOException int v,rv; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); Chand hand = new Chand(); aa: do System.out.println("주사위를 던지세요(1:가위, 2:바위, 3:보) (0:그만하기)"); v=Integer.parseInt(in.readLine()); if (v==0) break; hand.rnd(); rv=hand.val(); if(v==rv) { System.out.println("비겼습니다. 다시하세요~"); continue aa; }

if( (v==1) && (rv==2) ) System. out. println("졌습니다 if( (v==1) && (rv==2) ) System.out.println("졌습니다."); if( (v==2) && (rv==3) ) System.out.println("졌습니다."); if( (v==3) && (rv==1) ) System.out.println("졌습니다."); if( (v==2) && (rv==1) ) System.out.println("이겼습니다."); if( (v==3) && (rv==2) ) System.out.println("이겼습니다."); if( (v==1) && (rv==3) ) System.out.println("이겼습니다."); System.out.println(rv); }while(true); } }

문제 – 함수 오버로딩을 통해서 스택을 구현하라 문제 – 함수 오버로딩을 통해서 스택을 구현하라. 예를 들어 값이 정수이면 정수형 스택에 값을 넣고 문자형이면 문자형 스택에 값을 넣는다. 그리고 스택을 출력한다. Time class extends Date class 년, 월, 일, 시,분, 초를 가지는 Time 에서 1초를 증가시켜 60초가 되면 1분이 증가되고, 60분이 되면 1시간이 증가되며, 24시간이 되면, 하루가 증가, 그렇게 해서 1초를 증가시키며, 계속 처리해주는 프로그램