MAIN.JAVA:
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Scanner; public class Main { public static void main(String[] args) throws ParseException { SimpleDateFormat dk = new SimpleDateFormat("dd/MM/yyyy"); Scanner sc = new Scanner(System.in); BillHeader b = new BillHeader(); System.out.println("Enter the issue date as dd/MM/yyyy"); String d1 = sc.nextLine(); Date di = dk.parse(d1); b.setIssueDate(di); System.out.println("Enter the due date as dd/MM/yyyy"); String d2 = sc.nextLine(); Date df = new SimpleDateFormat("dd/MM/yyyy").parse(d2); b.setDueDate(df); System.out.println("Enter the original amount"); String orig = sc.next(); System.out.println("Enter amount paid so far"); String paid = sc.next(); double o= Double.parseDouble(orig); double p = Double.parseDouble(paid); b.setOriginalAmount(o); b.setAmountOutstanding(p); double bal = o-p; b.setAmountOutstanding(bal); b.display(); } }
BILLHEADER.JAVA:
import java.text.SimpleDateFormat; import java.util.Date; public class BillHeader { private Date issueDate; private Date dueDate; private double originalAmount; private double amountOutstanding; SimpleDateFormat dk = new SimpleDateFormat("dd/MM/yyyy"); 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; } public void display(){ System.out.println("Issue date: "+dk.format(getIssueDate())); System.out.println("Due Date: "+dk.format(getDueDate())); System.out.println("Original amount Rs."+originalAmount); System.out.println("Amount outstanding Rs."+amountOutstanding); } }