Java program for Call Details

Question:-

For the postpaid customers, the airvoice mobile shop maintains the calls made by the customer in the file in the given format below:

Callid:callednumber:noofminutes

Example: 123:9874561230:2.5

The shop wants to extract the information from the file and populate them in to the Call object. Develop a java application to do the above task.

Consider the class given below:

Call details
Call details

In the Call class include the given attributes and methods with the access specifiers as specified in the class diagram.

The getter methods are used to retrieve the value.

The parseData method takes the string as argument, the string value will be (123:9874561230:2.5). This method should extract the callid, called number and number of minutes from the string and set the callId, calledNumber and noOfMinutes.

In the Main class, create an object for the Call class; Get the details as shown in the sample input and invoke the parseData method.  Display the details as shown in the sample output using the getters method.

Note: The attribute/method/class name should be specified correctly as given in the class diagram.

Sample Input:

Enter the call details:

102:6547891230:2.15

 Sample output:

  Call id:102

  Called number:6547891230

  Duration:2.15

Code:-

Call.java

public class Call{
    private int callId;
    private long calledNumber;
    private float duration;
    
    public void Call()
    {

    }
    
    public void parseData(String data)
    {
        this.callId=Integer.parseInt(data.substring(0,3));
        this.calledNumber=Long.parseLong(data.substring(4,14));
        this.duration=Float.parseFloat(data.substring(15));
    }
    
    public int getCallId()
    {
        return this.callId;
    }
    
    public long getCalledNumber()
    {
        return this.calledNumber;
    }
    
    public float getDuration()
    {
        return this.duration;
    }
}

Main.java

import java.util.*;
public class Main{
    public static void main (String[] args) {
        
        Scanner sc=new Scanner(System.in);
        Call obj=new Call();
        System.out.println("Enter the call details:");
        String data=sc.nextLine();
        
        obj.parseData(data);
        System.out.println("Call id:"+obj.getCallId());
        System.out.println("Called number:"+obj.getCalledNumber());
        System.out.println("Duration:"+obj.getDuration());
    }
    
}

Recommended:-

8 thoughts on “Java program for Call Details”

  1. I would like to thnkx for the efforts you have put in writing this blog. I am hoping the same high-grade site post from you in the upcoming also. Actually your creative writing skills has encouraged me to get my own web site now. Actually the blogging is spreading its wings rapidly. Your write up is a good example of it.

  2. YOU NEED QUALITY VISITORS for your: quizforexam.com

    I Will Provide Organic Traffic By Keyword From Search Engines Or Social Media

    YOU GET HIGH-QUALITY VISITORS
    – visitors from search engines
    – visitors from social media
    – visitors from any country you want
    – very low bounce rate & long visit duration

  3. YOU NEED QUALITY VISITORS for your: quizforexam.com

    I Will Provide Organic Traffic By Keyword From Search Engines Or Social Media

    YOU GET HIGH-QUALITY VISITORS
    – visitors from search engines
    – visitors from social media
    – visitors from any country you want
    – very low bounce rate & long visit duration

  4. YOU’RE CRAVING MORE MONEY, MORE TIME, AND MUCH LESS STRESS.

    My approach solves your issues and equips you with tried and tested techniques that help you reach your business goals.
    Check it out…

  5. Hello

    YOU NEED HELP FOR SEO LINK BUILDING?

    I just checked out your website quizforexam.com, and wanted to find out if you need help for SEO Link Building ?

    We offer you the BEST SEO STRATEGY for 2021, my name is Carmella, and I’m a SEO Specialist.

    Build unlimited number of Backlinks and increase Traffic to your websites which will lead to a higher number of customers and much more sales for you.

    If You Are Interested, I’m waiting for your response here => https://bit.ly/32uQKuH

    Thanks,
    SEO Specialist

  6. This design is wicked! You obviously know how to keep a reader entertained. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Wonderful job. I really enjoyed what you had to say, and more than that, how you presented it. Too cool!

  7. great post, very informative. I’m wondering why the opposite experts of this sector do not understand this. You must continue your writing. I’m confident, you’ve a huge readers’ base already!

Leave a Comment

Your email address will not be published. Required fields are marked *

x