java 面向对象的编程思想

按照first  head java 所说的 从今天开始我才正式进入对象村,才开始面向对象的学习,进行面向对象的相互调用

这是一个猜数字的小程序

import java.io.*;
import java.util.*;
import java.math.*;

 class Player                      //这里class前面貌似不能加public 不知道为什么
{
      int number;
      public void count (){
                           number=(int)(Math.random()*10);
                           System.out.println("this number is "+number);
                          }
}

 class GuessGame            //这里class前面貌似不能加public 不知道为什么
{
  Player a=new Player();
  Player b=new Player();
  Player c=new Player();
  
  public void startGame()
   {
      int x,y,z;
      int number;
      boolean judgea=false,judgeb=false,judgec=false;

      number=(int) (Math.random()*10);
      System.out.println("please put the number between 0-9");
      System.out.println("the orignal number is "+number);
      while(true)
      {
        a.count();
        b.count();
        c.count();
        x=a.number;
        y=b.number;
        z=c.number;       
 
        if(x==number)judgea=true;
        if(y==number)judgeb=true;      
        if(z==number)judgec=true;
        if(judgea||judgeb||judgec)      
        {
          if(judgea==true)System.out.println("player one is correct he 

get "+x);
          else System.out.println("player one is wrong he get "+x);
          if(judgeb==true)System.out.println("player two is correct he 

get "+y);
          else System.out.println("player two is wrong he get "+y);
          if(judgec==true)System.out.println("player three is correct he 

get "+z);
          else System.out.println("player three is wrong he get "+z);
         break;
        }
       else System.out.println("Please try again!!!");
      }
   }
}
public class GameLanuch
{ 
   public static void main(String args[]){
    GuessGame a=new GuessGame();
    a.startGame();
                                         } 
} 



 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值