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 Type | Variable Name |
Date | issueDate |
Date | dueDate |
Double | originalAmount |
Double | amountOutstanding |
Include appropriate getters and setters.
Consider the class Main. It includes the method main,
Note:
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
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
[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
Keyword | Min Count | Max Count |
StringTokenizer | 2 | - |
@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: