Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #1015

Java class constructor method

From Cleaver Greene <thybutcher@gmail.com>
Newsgroups comp.lang.java.help
Subject Java class constructor method
Date 2011-09-06 23:32 -0700
Organization http://groups.google.com
Message-ID <5fdf778b-5252-4cbe-8e9a-bfd969796579@br5g2000vbb.googlegroups.com> (permalink)

Show all headers | View raw


Why doesn't this line compile? The constructor indicated by <<!!>>
returns a "cannot find symbol" error.

import java.util.Scanner;

/** This class demonstrates the Television class*/

public class TelevisionTester
{
   public TelevisionTester()
   {
      //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() + " inch "
+  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


I am using this (partially completed) class for the Television object
initialised by the constructor on the erroronus line.


/**
 * Write a description of class Television here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class Television
{
    // instance variables - replace the example below with your own
    private int channel;
    private int volume;
    private boolean powerOn;
    public int SCREEN_SIZE;
    char MANUFACTURER;

    /**
     * Constructor for objects of class Television
     */
    public Television(char tvMANUFACTURER, int tvSCREEN_SIZE)
    {
        MANUFACTURER = tvMANUFACTURER;
        SCREEN_SIZE = tvSCREEN_SIZE;
    }

    //Method
    public int setChannel(int setChannel)
    {
        channel = setChannel;
        return channel;
    }
}

Back to comp.lang.java.help | Previous | NextNext in thread | Find similar


Thread

Java class constructor method Cleaver Greene <thybutcher@gmail.com> - 2011-09-06 23:32 -0700
  Re: Java class constructor method Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-07 07:48 -0400

csiph-web