function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
srinivas pulipatisrinivas pulipati 

I am write the below code but some errors came could you please rectify this one

public class TvremoteControll {
    integer volume;
    static final integer MAX_VOLUME=50;
    public TvremoteControll(){
        volume= v;    // Error:Non-void method might not return a value or might have statement after a return statement.
    }
    public integer increaseVolume(integer amount){
        volume t= amount;
        for(volume > MAX_VOLUME){   //Error =expecting an equals sign, found '>'
            volume = MAX_VOLUME;  
            
        }
       return volume;
    }
    public integer decreaseVolume(integer amount){
        volume t1=amount;
        if(volume<0){
            volume=0;
        }
        return volume;
    }
    public static String getMenuOptions(){
        return 'audio settings _ vedio settings';      
    }
}
Abhishek BansalAbhishek Bansal
Hi,

Please update your code as follows :

public class TvremoteControll {
    Integer volume;
    static final integer MAX_VOLUME=50;
    
    public TvremoteControll(Integer v){
        volume = v;
    }
    public Integer increaseVolume(Integer amount){
        Integer increasedVolume = volume + amount;
        if(increasedVolume > MAX_VOLUME){
            return MAX_VOLUME;
        }
        else{
            return increasedVolume;
        }
    }
    
    public Integer decreaseVolume(Integer amount){
        Integer decreasedVolume = volume - amount;
        if(decreasedVolume < 0){
            return volume;
        }
        else{
            return decreasedVolume;
        }
    }
    
    public static String getMenuOptions(){
        return 'audio settings _ vedio settings';      
    }
}


If this code does not help you or does not meet your requiremnt than please share your requirement so that i can help you.

Thanks,
Abhishek
Rahul GoyalRahul Goyal
1 )  v is not defined in the constructor. 
public TvremoteControll(){
        volume= v;    // Error:Non-void method might not return a value or might have statement after a return statement.
    }

2) in this line volume t= amount;
change to volume = amount;

3) same in this line volume t1=amount;
volume =amount;

try to make the above changes........let me know if this works..

Regards,
Rahul
srinivas pulipatisrinivas pulipati
how to write test class in above program?
 
Abhishek BansalAbhishek Bansal
Hi ,

Please find the required test class;

private class TvremoteControllTest {
    static testMethod void myUnitTest() {
        TvremoteControll testRef = new TvremoteControllTest(10);
        testRef.increaseVolume(15);
        testRef.increaseVolume(100);
        
        testRef.decreaseVolume(15);
        testRef.decreaseVolume(1);
        
        testRef.getMenuOptions();
    }
}


Regards,
Abhishek.