logo codesdope
Level 1
1.
Create a Cricle class and intialize it with radius. Make two methods getArea and getCircumference inside this class.
Answer
class Circle
  def initialize(radius)
    @radius = radius
  end
  def  getArea()
    return 3.14*@radius*@radius
  end
  def getCircumference()
    return @radius*2*3.14
  end
end
  
									

2.
Create a Temprature class. Make two methods :
1. convertFahrenheit - It will take celsius and will print it into Fahrenheit.
2. convertCelsius - It will take Fahrenheit and will convert it into Celsius.
Answer
class Temprature
  def  convertFahrenhiet(celsius)
    return (celsius*(9/5))+32
  end
  def convertCelsius(farenhiet)
    return (farenhiet-32)*(5/9)
  end
end
  
									

3.
Create a Student class and initialize it with name and roll number. Make methods to :
1. Display - It should display all informations of the student.
2. setAge - It should assign age to student
3. setMarks - It should assign marks to the student.
Answer
class Student
  def initialize(name,roll)
    @name = name
    @roll= roll
  end
  def display()
    puts @name
    puts @roll
  end
  def setAge(age)
    @age=age
  end
  def setMarks(marks)
    @marks = marks
  end
end
  
									

4.
Create a Time class and initialize it with hours and minutes.
1. Make a method addTime which should take two time object and add them. E.g.- (2 hour and 50 min)+(1 hr and 20 min) is (4 hr and 10 min)
2. Make a method displayTime which should print the time.
3. Make a method DisplayMinute which should display tje total minutes in the Time. E.g.- (1 hr 2 min) should display 62 minute.
Doubt? Ask question
Close

Welcome.please sign up.

Close

Welcome.please login.