Menu
Question Index
...


Write a program to convert mobile to fixed format.
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. Use spaces for filling. The format of the camera mega pixels is like 99.99, 01.00, 00.14

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

class ConvertMobileToFixedFormat

{    public static void main(String s[])
    {
        Mobile mobeen_mobile = new Mobile(1, "Nokia", "3412", 12);
        System.out.println("Converted Fixed Format is : " + convertToFixedFormat(mobeen_mobile));

    }


public static String convertToFixedFormat(Mobile mobile) {
String result = null;
//Write code here to convert Mobile object to fixed format. Use the suffixSpaces method if required.
return result;
}

public static String suffixSpaces(String result, int length) {
//Write code here to suffix spaces to the string and return it.
}
}
class Mobile {

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

public Mobile(int numberOfSims, String maker, String model, double cameraMegaPixels) {
this.numberOfSims = numberOfSims;
this.maker = maker;
this.model = model;
this.cameraMegaPixels = cameraMegaPixels;
}
}

Doubts

Problems

Topic: Java Formatter

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App