Menu
Question Index
...

Write a program to convert from fixed length format to mobile object.
Assume that the first two characters represent number of sims, the next 15 characters are the maker, the next 15 characters are the model and the last 5 characters represent the camera mega pixels. The record will be of length 2 + 15 + 15 + 5 = 37. Spaces are used as fillers. So trim before using the data.

Input(Fixed Format String) Output(Mobile Object)
1 Nokia          3412           02.50 NumberOfSims = 1, Maker = "Nokia", Model = "3412", CameraMegaPixels = 2.5
12Samsung        2252           12.00 NumberOfSims = 12, Maker = "Samsung", Model = "2252", CameraMegaPixels = 12.0
2 Apple          C3752          12.35 NumberOfSims = 2, Maker = "Apple", Model = "C3752", CameraMegaPixels = 12.35
1 Sony           Sony Xperia SL 04.32 NumberOfSims = 1, Maker = "Sony", Model = "Sony Xperia SL", CameraMegaPixels = 4.32



class ConvertFixedFormatToMobile
{
    public static void main(String s[])
    {
        String result = "12Samsung        2252           12.00";
        Mobile mobile = convertToMobile(result);
        System.out.println("Number of sims : " + mobile.numberOfSims);
        System.out.println("Maker : " + mobile.maker);
        System.out.println("Model : " + mobile.model);
        System.out.println("CameraMegaPixels :" + mobile.cameraMegaPixels);

    }


    public static Mobile convertToMobile(String str) {
    }

}
class Mobile {

int numberOfSims;
String maker;
String model;
double cameraMegaPixels;
}

Doubts

Problems

Topic: Object As A Super Class In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App