🌙 DARK

Converting a String to Double Wrapper Class

 

Converting a String to Double


Write a program to read the input amount as a string and parse it to Double using the 'valueOf/parseDouble' method.
 
Strictly adhere to the Object-Oriented specifications given in the problem statement. All class names, attribute names, and method names should be the same as specified in the problem statement.
 
Consider the class BillHeader with the following private members
 
Data TypeVariable Name
DateissueDate
DatedueDate
DoubleoriginalAmount
DoubleamountOutstanding
Include appropriate getters and setters.
 
Consider the class Main. It includes the method main,

Note:
  • amountOutstanding can be calculated by subtracting the amount paid so far from the original amount
  • All double values should be displayed upto 2 decimal places
     
The link to download the template code is given below
Code Template

Input and Output Format:
Refer sample input and output for formatting specifications.
 
Sample Input & Output:
[All text in bold corresponds to input and the rest corresponds to output]

Enter the issue date as dd/MM/yyyy
12/07/2015
Enter the due date as dd/MM/yyyy
21/08/2015
Enter the original amount
2000
Enter amount paid so far
1000
Issue date: 12/07/2015
Due Date: 21/08/2015
Original amount Rs.2000.0
Amount outstanding Rs.1000.0


@MRProgrammer89 


CREATE CLASS < BillHeader:


import java.text.DecimalFormat;
import java.util.Date;

public class BillHeader {
DecimalFormat df = new DecimalFormat("0.00");
    private Date issueDate,dueDate;
private double originalAmount,amountOutstanding;
public Date getIssueDate() {
return issueDate;
}
public void setIssueDate(Date issueDate) {
this.issueDate = issueDate;
}
public Date getDueDate() {
return dueDate;
}
public void setDueDate(Date dueDate) {
this.dueDate = dueDate;
}
public double getOriginalAmount() {
return originalAmount;
}
public void setOriginalAmount(double originalAmount) {
this.originalAmount = originalAmount;
}
public double getAmountOutstanding() {
return amountOutstanding;
}
public void setAmountOutstanding(double amountOutstanding) {
this.amountOutstanding = amountOutstanding;
}
}


@MRProgrammer89 


CREATE CLASS < Main :


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.*;

public class Main {
    public static void main(String[] args)throws ParseException {
    Scanner sc=new Scanner(System.in);
    BillHeader ev=new BillHeader();
    SimpleDateFormat df=new SimpleDateFormat("dd/MM/yyyy");
        System.out.println("Enter the issue date as dd/MM/yyyy");
        Date dt=df.parse(sc.nextLine());
        System.out.println("Enter the due date as dd/MM/yyyy");
        Date dt1=df.parse(sc.nextLine());
        System.out.println("Enter the original amount");
        String oa=sc.nextLine();
        System.out.println("Enter amount paid so far");
        String am =sc.nextLine();
        Double d=Double.parseDouble(oa);
        Double f=Double.parseDouble(am);
        ev.setIssueDate(dt);
        ev.setDueDate(dt1);
        ev.setOriginalAmount(d);
        ev.setAmountOutstanding(f);
        
        System.out.println("Issue date: "+df.format(dt));
        System.out.println("Due Date: "+df.format(dt1));
        System.out.println("Original amount Rs."+ev.getOriginalAmount());
        System.out.println("Amount outstanding Rs."+(ev.getOriginalAmount()-ev.getAmountOutstanding()));
    }

}





String Tokenizer

Write a Java program to implement a string tokenizer in order to split a string into two different tokens by =(equal to) and ;(semicolon).
 


The link to download the template code is given below
Code Template


Input Format:
Input is a string that needs to be split.

Output Format:
Each line of the Output contains two strings. The first string is formed by the token '=' and the second string is formed by the token ';'

Assume The tokens, '=' and ';', will always come alternately. Refer Sample Input.

 

Sample Input:

title=Java-Samples;author=Emiley J;publisher=java-samples.com;copyright=2007;

 

Sample Output:
title Java-Samples
author Emiley J
publisher java-samples.com
copyright 2007



Problem Requirements:

Java

KeywordMin CountMax Count
StringTokenizer2-


@MRProgrammer89 


CREATE CLASS < Main :


import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args)  {
        Scanner sc= new Scanner(System.in);
        String s=sc.nextLine();
        StringTokenizer s1 = new StringTokenizer(s,"=");
        String s2 ="";
        while(s1.hasMoreTokens()){
            s2=s2+""+s1.nextToken();
        }
        StringTokenizer s3=new StringTokenizer(s2,";");
        while(s3.hasMoreTokens()){
            System.out.println(s3.nextToken());
        }
    
}
}



Excesses:

Wrapper Class – Integer

 

This program is to illustrate the Integer Wrapper class.

 

Write a program that accepts an “Integer” class type value as input and invokes some of the methods defined in the Integer Wrapper class.

 

All functions should be performed using the methods defined in the Integer class.

The link to download the template code is given below
Code Template
 

Input and Output Format:
 

Refer sample input and output for formatting specifications.
All the double values should be displayed upto 1 decimal place.
All text in bold corresponds to input and the rest corresponds to output.

 

Sample Input and Output :
 

Enter an integer

540

The binary equivalent of 540 is 1000011100

The hexadecimal equivalent of 540 is 21c

The octal equivalent of 540 is 1034

Byte value of 540 is 28

Short value of 540 is 540

Long value of 540 is 540

Float value of 540 is 540.0

Double value of 540 is 540.0



@MRProgrammer89 






MOTIVATION :


    “The way we spend our time defines who we are 


Although we may not see each other as often as we’d like, distance is no match for the bond that we share. Thank you for coming to visit. It was fantastic to catch up.


VISITE MORE BLOGS




THANK YOU....😊

 

Post a Comment

Thanks for reading the blog. We hope it was useful to you and that you learned something new. Will always be writing on new and interesting topics, so you can visit our website to know the latest updates of our blogs. Thank You!

Previous Post Next Post

Contact Form