首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >需要澄清此java程序中的错误

需要澄清此java程序中的错误
EN

Stack Overflow用户
提问于 2012-12-09 05:38:33
回答 2查看 2.7K关注 0票数 0

我试图修复to方法,但我一直收到相同的错误:无法找到符号构造器to(java.lang.String,int)。如果有人能告诉我为什么会收到这个错误消息,我将不胜感激。下面是我的代码:

代码语言:javascript
复制
import java.util.Scanner;
public class Television
{
    private String manufacturer;       //the brand name
    private int SCREEN_SIZE;           //the size of the television screen.
    private boolean powerOn;           //the value true if the power is on
    private int channel;               //the value of the station that the television is showing.
    private int volume;                //a number value representing the loudness

    Scanner keyboard = new Scanner(System.in);
    /*
     *Constructor to assign the values to manufacturer and SCREEN_SIZE
     *@param the manufacturer value
     *@param the SCREEN_SIZE value
     */
    public Television(String sony, int size, int chan)
    {
        manufacturer = sony;
        SCREEN_SIZE = size;
        channel = chan;

        powerOn = false;
        channel = 2;
        volume = 20;
    }
    public int getChannel()
    {
        return channel;
    }
    public int getVolume()
    {
        return volume;
    }
    public String getManufacturer()
    {
        return manufacturer;
    }
    public int getScreenSize()
    {
        return SCREEN_SIZE;
    }
    public void setChannel(int channel)
    {
        channel = keyboard.nextInt();
    }
    public void power()
    {
        if (true)
        {
            powerOn = !powerOn;
        }
        else
        {
            powerOn = powerOn;
        }
    }
    public void increaseVolume()
    {
        volume = volume + 1;
    }
    public void decreaseVolume()
    {
        volume = volume - 1;
    }
public static void main(String[] args)
{
    //create a Scanner object to read from the keyboard
    Scanner keyboard = new Scanner (System.in);
    //declare variables
    int station; //the user’s channel choice


    //declare and instantiate a television object
    Television bigScreen = new Television("Toshiba", 55);



    //turn the power on
    bigScreen.power();
    //display the state of the television
    System.out.println("A " + bigScreen.getScreenSize() +
    bigScreen.getManufacturer() + " has been turned on.");
    //prompt the user for input and store into station
    System.out.print("What channel do you want? ");
    station = keyboard.nextInt();
    //change the channel on the television
    bigScreen.setChannel(station);
    //increase the volume of the television
    bigScreen.increaseVolume();
    //display the the current channel and volume of the television
    System.out.println("Channel: " + bigScreen.getChannel() +
    " Volume: " + bigScreen.getVolume());
    System.out.println("Too loud!! I am lowering the volume.");
    //decrease the volume of the television
    bigScreen.decreaseVolume();
    bigScreen.decreaseVolume();
    bigScreen.decreaseVolume();
    bigScreen.decreaseVolume();
    bigScreen.decreaseVolume();
    bigScreen.decreaseVolume();
    //display the current channel and volume of the television
    System.out.println("Channel: " + bigScreen.getChannel() +
    " Volume: " + bigScreen.getVolume());
    System.out.println(); //for a blank line
    //HERE IS WHERE YOU DO TASK #5
}
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-12-09 05:40:01

您的two构造函数接受三个参数、一个字符串和两个整型数,而您只是传递了两个参数。

代码语言:javascript
复制
Television bigScreen = new Television("Toshiba", 55);

应该是

代码语言:javascript
复制
Television bigScreen = new Television("Toshiba", 55, there should be another int argument here);

正如我在您的代码中看到的,您应该将一个int (channel)作为第三个参数传递给构造函数。

票数 4
EN

Stack Overflow用户

发布于 2012-12-09 05:41:25

构造函数定义为接收3个参数,而您只传递2个参数

代码语言:javascript
复制
public Television(String sony, int size, int chan);

Television bigScreen = new Television("Toshiba", 55);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13782197

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档