Sie sind auf Seite 1von 6

NODE

public class Node


{
Invoice data;
Node next;
Node(Invoice I)
{ data= I;}
}

LINKLIST

public class LinkList


{
public Node first;
private Node last;
private Node current;
public LinkList()
{
first = null;
last = null;
current = null;
}
public boolean isEmpty()
{ return(first==null);}
public void insertAtBack(Invoice item)
{
Node newNode = new Node(item);
if(isEmpty())
{
first=newNode;
last=newNode;
}
else
{
last.next = newNode;
last = newNode;
}
}

public Invoice removeFromFront()


{
Invoice removeItem = null;
if(isEmpty())
{
return removeItem;
}
removeItem=first.data;
if(first==last)
{
first =null;
last =null;
}
else
{
first = first.next;
}
return removeItem;
}
public Invoice removeFromBack()
{
Invoice removeItem =null;
if(isEmpty())
{
return removeItem;
}
removeItem =last.data;
if(first==last)
{
first=null;
last=null;
}
else
{
current=first;
while(current.next!=last)
{
current = current.next;
}
last = current;
last.next = null;
}
return removeItem;
}
}

QUEUE
public class Queue extends LinkList
{
public Queue()
{}
public void enqueue(Invoice item)
{
insertAtBack(item);
}
public Invoice dequeue()
{
return removeFromFront();
}
public boolean isEmpty()
{
return(first == null);
}
}

INVOICE
public class Invoice
{
private int orderID;
private String custName;
private String prodName;
private int prodQuantity;
private double unitPrice;
public Invoice()
{
orderID = 0;
custName = " ";
prodName = " ";
prodQuantity = 0;
unitPrice = 0.0;
}
public void setData(int oid, String cn, String pn, int pq,double up)
{
orderID = oid;
custName = cn;
prodName = pn;
prodQuantity = pq;
unitPrice = up;
}
public int getOrderID()
{ return orderID;}
public String getCustName()
{ return custName;}
public String getProdName()
{ return prodName;}
public int getProdQuantity()
{ return prodQuantity;}
public double getUnitPrice()
{ return unitPrice;}
public String toString()
{
return("Order ID :"+orderID+"\n"+"Customer Name :"+custName+"\n"+"Product
Name :"+prodName+"\n"+"Product Quantity :"+prodQuantity+"\n"+"Unit
Price :"+unitPrice);
}
}

INVOICE APPLICATION
import java.util.*;
public class InvoiceApp
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
Invoice I = new Invoice();
Queue Q = new Queue();
Queue tempQ = new Queue();
int prodQuantity = 0;
for(int i=0;i<3;i++)
{
System.out.print("Enter Order ID : ");
int orderID = sc.nextInt();
System.out.print("Enter Customer Name : ");
String custName = sc.next();
System.out.print("Enter Product Name : ");
String prodName = sc.next();
System.out.print("Enter Product Quantity : ");
prodQuantity = sc.nextInt();
System.out.print("Enter Unit Price : ");
double unitPrice = sc.nextDouble();
I = new Invoice();
I.setData(orderID,custName,prodName,prodQuantity,unitPrice);
Q.enqueue(I);
System.out.println("************************************");
}
while(!Q.isEmpty())
{
I = (Invoice)Q.dequeue();
tempQ.enqueue(I);
}
Invoice location = null;
int count =0;
double max =0.00;
double payment =0.00;
System.out.println("Invoice Information where the payment more than
RM5000 :-");
while(!tempQ.isEmpty())
{
I = (Invoice)tempQ.dequeue();
payment = I.getProdQuantity()* I.getUnitPrice();
if(payment > max)
{
max = payment;
location = I;
}

if(payment > 5000)


{
count = count +1;
System.out.println(I.toString());
System.out.println("\n");
}
Q.enqueue(I);
}
System.out.println("The highest payment : RM"+max);
System.out.println(location.toString());
System.out.println("\n");
System.out.println("The number of count of invoice where the payment more
than RM5000 :"+count);
}
}

Das könnte Ihnen auch gefallen