public class TVRemote {
    //initialize variables


private int channel, vol;

public TVRemote(){this(0,0);}
public int getChannel(){return channel;}
public void setChannel(int a){channel = a;}
public TVRemote(int a, int b){setChannel(a); setVolume(b);}
public int getVolume(){return vol;}
public void setVolume(int b){vol = b;}
public void channelUp(){
                  channel++; }
                 public void channelDown(){
                  channel--; }
                 public void changeChannel(int x){
                     channel = x;
                 }
            public void changeVolume(int b){vol = b;}
              public void volumeUp(){
                  vol++; }
              public void volumeDown(){
                  vol--; }
              //prints out the final report of the program
    public void display() {
System.out.println("Channel = "+channel);
System.out.println("Volume = "+vol);
}}








                          public class TVRemoteClient {
public static void main(String args[])
        {
            TVRemote t = new TVRemote(22 ,10);


                t.channelUp();/*increase the channel*/
               t.display(); /*display current status of channel and volume*/
              t.changeChannel(1); /*directly set channel*/
               t.display(); /*display current status of channel and volume*/
                t.channelDown();/*go down to next channel*/
                t.volumeUp(); /*increase volume by one*/
               t.display(); /*display current status of channel and volume*/


public class DVDRemote extends TVRemote{

private String mode;
private int status;

public DVDRemote(){this(0,null);}
public DVDRemote(int c, String d){
    super(0,0);
    mode = null;
    status = 0;
}
public String getMode(){return mode;}
public void setMode(String a){mode = a;}
public int getStatus(){return status;}
public void setStatus(int b){status = b;}
public void changeStatus(int x){
    if(x>-1&&x<2)
                  status = x; }
                 public void statusEject(){
                  status=0; }
                 public void changeMode(String x){
                     mode = x;
                 }
              public void StatusDVD(){
                  status = 1; }
              public boolean equals(DVDRemote a){return true;}
              //prints out the final report of the program, their percentage, and if they need help with their chosen subject
    public void display() {
        System.out.println("Channel = "+getChannel());
       System.out.println("Volume = "+getVolume());

System.out.println("Status = "+mode);
if(status==0){
    System.out.println("There is no DVD in the machine.");}
            if(status==1){
                System.out.println("There is a DVD in the machine.");}
}}







public class DVDRemoteClient{
    public static void main(String[]args){
        DVDRemote v = new DVDRemote(1, "Play");
v.setChannel(100);
v.setVolume(10);
        v.StatusDVD();
        v.setMode("stop");
        v.display();
        v.setMode("Fast forward");
        v.display();
    }
}

Here's what I have so far. The assignment (final project) is:

Create a class TVRemote. This class will simulate a TV remote control.

Data members:
* channel
*volume level
*any other you wish to add

Member methods:
* overloaded constructors (no data, channel data only, volume and channel data)
* get and set methods for all data members
* channelUp and channelDown methods (can't exceed or go below your channel limit and will go from last channel to first channel)
* volumeUp and volumeDown methods (can't exceed or go below your volume level)

Requirements:
In a client, instantiate a TVRemote object and demonstrate its capabilities (change volume, up and down; change channels, up and down, and direct input).

Example of client code:

TVRemote t = new TVRemote(22,10); /*instantiate object*/
t.channelUp();/*increase the channel*/
t.display(); /*display current status of channel and volume*/
t.changeChannel(1); /*directly set channel*/
t.display(); /*display current status of channel and volume*/
t.channelDown();/*go down to next channel*/
t.volumeUp(); /*increase volume by one*/
t.display(); /*display current status of channel and volume*/

Part B
Using the class TVRemote from Part A above, create a class DVDRemote class that inherits from TVRemote. In addition to the data members and member methods it inherits, it will have the following methods:

Data members:
your choice
Member methods:
insertDVD()
ejectDVD()
setMode()
getMode()

The user should be able to play, stop, fast forward, and rewind a DVD in the setMode method. The getMode method should tell the user what mode the DVD is in or that a DVD is not in the machine.

Requirements:
In a client, instantiate a DVDRemote object and demonstrate its capabilities (including its ability to operate the TV).


Example of client code:

DVDRemote v = new DVDRemote(“play”);
v.setMode(“stop”);
v.display();
v.setMode(“fast forward”);

My code runs, but I'm not sure I have everything asked for in the project. I think it's fine, but would really appreciate the help of the experts here. Also, is there anything I could/should do differently, or anything I may have missed.

Thanks

You need to have an upper limit for the channels. Declare it as a constant in the TVRemote class.

When you try to increase the channel above that limit then have channel become 1. When you try to decrease it below 1 have channel take the upper limit.

The same as volume you should have code that checks if the volume has gone below 0 and prevent that. May be ignore it or print a message:

public void decreaseVolume() {
   if (volume==0) {
     // cannot decrease;
   } else {
      volume--;
   }
}

Also you should have checks at your set methods:

public void setChannel(int a) {
   if (a<1) {
      channel = 1;
   } else if (a>TOP_LIMIT) {
     channel = TOP_LIMIT;
   } else {
      channel = a;
   }
}

Great catch, Java. Thanks so much for your help. I incorporated your changes and cleaned things up a bit and the program looked great.

Solved!

You need to have an upper limit for the channels. Declare it as a constant in the TVRemote class.

When you try to increase the channel above that limit then have channel become 1. When you try to decrease it below 1 have channel take the upper limit.

The same as volume you should have code that checks if the volume has gone below 0 and prevent that. May be ignore it or print a message:

public void decreaseVolume() {
   if (volume==0) {
     // cannot decrease;
   } else {
      volume--;
   }
}

Also you should have checks at your set methods:

public void setChannel(int a) {
   if (a<1) {
      channel = 1;
   } else if (a>TOP_LIMIT) {
     channel = TOP_LIMIT;
   } else {
      channel = a;
   }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.