Menu
Question Index
...

Define a Mobile class, with parameters like model, manufacturer, numberOfSims, hasCamera and cameraMegaPixels. cameraMegaPixels should be zero by default and should be modified only if it hasCamera. When hasCamera is change to false then cameraMegaPixels should automatically come back to zero.

Input Output
Previous Camera = false, Previous Camera Mega Pixels = 0.0, New Camera = true, New Camera Mega Pixels = 2.0 New Camera = true, New Camera Mega Pixels = 2.0
Previous Camera = true, Previous Camera Mega Pixels = 2.0, New Camera = false, New Camera Mega Pixels = 0.0 New Camera = false, New Camera Mega Pixels = 0.0
Previous Camera = false, Previous Camera Mega Pixels = 0.0, New Camera = false, New Camera Mega Pixels = 3.0 New Camera = false, New Camera Mega Pixels = 0.0



class ClassMobileValidation
{
    public static void main(String s[])
    {
        Mobile mobile = new Mobile("Asha303", "Nokia", 2);
        mobile.setHasCamera(true);
        mobile.setCameraMegaPixels(2.0);
        mobile.print();

    }



}
class Mobile
{
    String model;
    String manufacturer;
    int numberOfSims;
    boolean hasCamera;
    double cameraMegaPixels;

    Mobile(String model, String manufacturer, int numberOfSims)
    {
    }

    void setHasCamera(boolean hasCamera)
    {
    }

    void setCameraMegaPixels(double cameraMegaPixels)
    {
    }
    
    void print()
    {
        System.out.println(model+ " manufactured by " + manufacturer + " with " + numberOfSims +" sims." + " It has camera " + hasCamera + " with MegaPixels " + cameraMegaPixels);
    }    
}

Doubts

Problems

Topic: Creating A Class For Data Validation

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App