Sort by

recency

|

1912 Discussions

|

  • + 0 comments

    How am i supposed to debug if i am not allowed to change/ update the main[] method at all? This program seems to have problem in itself i.e. the testcase is failing because of extra blank space but i am unable to remove that additional print statement from the main[] method.

  • + 0 comments

    C# code of the Person class..

    public int age;     
        
        public Person(int initialAge) {
            if (initialAge > 0) {
                age = initialAge;
            } else {
                age = 0;
                Console.WriteLine("Age is not valid, setting age to 0.");
            }
        }
        
        public void amIOld() {
            if (age < 13) {
                Console.WriteLine("You are young.");
            } else if (age >= 13 && age < 18) {
                Console.WriteLine("You are a teenager.");
            } else {
                Console.WriteLine("You are old.");
            }
        }
    
        public void yearPasses() {
            age++;
        }
    
  • + 0 comments

    Python

    class Person: def init(self, initialAge): self.age = initialAge

    @property
    def age(self):
        return self.__age
    
    @age.setter
    def age(self, value):
        if value < 0:
            value = 0
            print("Age is not valid, setting age to 0.")
        self.__age = value
    
    def amIOld(self):
        if self.age < 13:
            print("You are young.")
        elif 13 <= self.age < 18:
            print("You are a teenager.")
        else:
            print("You are old.")
    
    def yearPasses(self):
        self.age += 1
    
  • + 0 comments

    Python code

    class Person:
        def __init__(self,initialAge):
            self.initialAge=initialAge
            if self.initialAge<0:
                print("Age is not valid, setting age to 0.")
        def amIOld(self):
            if self.initialAge < 13:
                print("You are young.") 
            elif self.initialAge>=13 and self.initialAge<18:
                print("You are a teenager.")
            else:
                print("You are old.")
        def yearPasses(self):
            self.initialAge+=1
    
    t = int(input())
    for i in range(0, t):
        age = int(input())         
        p = Person(age)  
        p.amIOld()
        for j in range(0, 3):
            p.yearPasses()       
        p.amIOld()
        print("")
    
  • + 0 comments

    public Person(int initialAge) {

        if(initialAge < 0 ){
            System.out.println("Age is not valid, setting age to 0.");
        }
        else{
            this.age =initialAge;
        }
    }
    
    public void amIOld() {
        if(age < 13){
            System.out.println("You are young.");
        }
        else if( age >= 13 && age < 18 ) {
            System.out.println("You are a teenager.");
        }
        else{
            System.out.println("You are old.");
        }
    
    }
    
    public void yearPasses() {
        age ++;
    }
    
    public static void main(String[] args) {