Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 844|回复: 1
打印 上一主题 下一主题

请帮忙我!!!

[复制链接]

51

主题

0

好友

1336

积分

黄金长老

Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8

跳转到指定楼层
1#
发表于 2009-8-8 04:09 PM |只看该作者 |倒序浏览
public class TV{
  private int channel;
  private int volume;
  private boolean flag;

//no-arg constructor
  public TV(){}

//default constructor
  public TV(int channel,int volume,boolean flag){
     this.channel=channel;
     this.volume=volume;
     this.flag=flag;
  }

  public int getChannel(){
     return channel;
  }

  public int getVolume(){
     return volume;
  }

  public boolean isOn(){
     return flag;
  }

  public void setChannel(int channel){
     this.channel=channel;
  }

  public void setVolume(int volume){
     this.volume=volume;
  }

  public void volumeUp(){
     this.volume+=1;
  }

  public void volumeDown(){
     this.volume-=1;
  }

  public void setFlag(boolean flag){
     this.flag=flag;
  }

  public String toString(){
     return ((flag) ? "TV is on" : "TV is off") +
             "\nChannel is " + channel + "\nVolume is "
             + volume;

  }
}





import java.util.Scanner;
public class testTV{
  public static void main(String[] args){


   //create object
   TV tv = new TV();
   Scanner input = new Scanner(System.in);

   System.out.print("do you want to switch the power ? On = 1 or Off = 0: ");

         //powerOnOff = input.nextBoolean();
         int power = input.nextInt();

      if (power == 1)
                           tv.setFlag(true);
                   else if(power == 0){
                  System.out.println("The tv is off ");
                           //tv.setPowerOnOff(false);
                   //else
                        System.exit(0);
                }


   System.out.print("Enter the TV channel between 0 to 99: ");

        int channel = input.nextInt();
        if (channel >=0 && channel <=99)
                        tv.setChannel(channel);
                else
                        System.exit(0);



   System.out.print("Enter the TV volume between 0 to 20: ");
         int volume = input.nextInt();
         if (volume >=0 && volume <=99)
                        tv.setVolume(volume);
                else
                        System.exit(0);


  // System.out.print("Pls increased the volume by unit: ");
  //        volume = input.nextInt();
  //       tv.setVolumeUp(volume);


  // System.out.print("Pls decreased the volume by unit: ");
  //        volume = input.nextInt();
  //       tv.setVolumeDown(volume);


   //tv.setPowerOnOff(powerOnOff);
   tv.setChannel(channel);
   tv.setVolume(volume);
   tv.volumeUp();
   tv.volumeDown();

   System.out.println(tv);
   System.out.println("\nThe channel's TV is: " + tv.getChannel());
   System.out.println("\nThe volume is : " + tv.getVolume());
   System.out.println("\nWhen the volume increased by 1 \n" + tv);
   System.out.println("\nWhen the volume decreased by 1 \n" + tv);
  }
}


为么 VOLUME dint increase & decrease!!!哪出了问题




收藏收藏0

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

2#
发表于 2009-8-8 09:44 PM |只看该作者
原帖由 lmy5360 于 2009-8-8 04:09 PM 发表
public class TV{
  private int channel;
  private int volume;
  private boolean flag;

//no-arg constructor
  public TV(){}

//default constructor
  public TV(int channel,int volume,bool ...



   tv.setVolume(volume); //這裡設定 volume
   tv.volumeUp(); //這裡 increase
   tv.volumeDown(); // 這裡 decrease

我想會數學的人 50 + 1 - 1 也知道最終答案


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-10-26 03:20 PM , Processed in 0.104621 second(s), 23 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部