Question Index

Write a program to find the cost for carpeting a room. The width and length are provided in meters. Define a class with two member variables width and length. Add a constructor to initialize these member variables. Create a method getArea() to return the area of the room and create one more getCarpetingCost() to get the cost for carpeting that area. The cost of carpeting per square meter is Rs. 24.30.

class FindRoomCarpetingCost
    public static void main(String s[])
        Room hall = new Room(12.5, 52.0);
        System.out.print("The cost for carpeting a room ");
        System.out.print("with area " + hall.getArea() + " square meters ");
        System.out.println("is Rs. " + hall.getCarpetingCost() + ".");


class Room



Topic: Java Multiple Methods In One Class

Read this topic
Take test on this topic

Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App