Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Apps
- import java.util.Scanner;
- import java.util.ArrayList;
- import java.io.*;
- import java.util.Stack;
- public class application {
- public static void main(String[] args) {
- Stack <Double> profit=new Stack<Double>();
- double proCal=0.0;//profit calculation
- int autoGenerator = 0;
- String username = " ", password = " ";
- Scanner input = new Scanner(System.in);
- System.out.print("USERNAME :");
- username = input.next();
- System.out.print("PASSWORD :");
- password = input.next();
- //Arraylist for login
- ArrayList<login> a = new ArrayList<login>();
- //adding object to a arraylist
- a.add(new login("yunus", "yst","manager"));
- a.add(new login("farina", "ina","manager"));
- a.add(new login("iskandar", "is","manager"));
- a.add(new login("fathul","press","staff"));
- a.add(new login("iqbal","saurabi","staff"));
- a.add(new login("adam","isyqi","staff"));
- a.add(new login("aiman","muhammad","staff"));
- String noti = " ";
- String status=" ";
- String ans=" ";
- //username and password will be search according to the index respectively
- for (int counter = 0; counter < a.size(); counter++) {
- if ((a.get(counter).getUsername().equalsIgnoreCase(username)) && (a.get(counter).getPassword().equalsIgnoreCase(password))) {
- status=a.get(counter).getStatus();
- noti = "Sucessfully Login";
- System.out.println(noti + "\n");
- break;
- }
- }
- String blocker=" ";
- if(status.equals("manager"))
- blocker = "allow";
- if (noti.equals("Sucessfully Login")) {
- do {
- String type;
- int size;
- double price=0.0;
- Queue Cdetail = new Queue();
- System.out.println("CUSTOMER NAME :");
- String name = input.next();
- String name2=input.nextLine();
- autoGenerator++;
- LinkedList item = new LinkedList();
- item.insertAtBack(new item(1, "MINERAL WATER", "BIG ", 20.00));
- item.insertAtBack(new item(2, "MINERAL WATER", "SMALL ", 10.00));
- item.insertAtBack(new item(3, "DRINKING WATER", "BIG ", 17.00));
- item.insertAtBack(new item(4, "DRINKING WATER", "SMALL ", 7.00));
- int counter1 = 0;
- item data = (item) item.getFirst();
- while (data != null) {
- if (counter1 == 0) {
- System.out.println("NO" + " TYPE " + " SIZE " + " PRICE ");
- counter1++;
- }
- System.out.println(data);
- data = (item) item.getNext();
- }
- char ans3=' ';
- int choice=0,quant=0;
- double total=0.0;
- BSTree tree = new BSTree();
- do {
- System.out.println("CUSTOMER'S CHOICE :");
- choice = input.nextInt();
- System.out.println("QUANTITY : ");
- quant = input.nextInt();
- if ((choice == 1)) {
- price = 20.00;
- tree.insertNode(new calculator(choice, price, quant));
- } else if ((choice == 2)) {
- price = 10.00;
- tree.insertNode(new calculator(choice, price, quant));
- } else if ((choice == 3)) {
- price = 17.00;
- tree.insertNode(new calculator(choice, price, quant));
- } else if ((choice == 4)) {
- price = 7.00;
- tree.insertNode(new calculator(choice, price, quant));
- }
- double total2=tree.totalPrice(price,quant);
- total=total2+total;
- Cdetail.enqueue(new customerDetails(choice,quant,price,total2));
- System.out.println("ANYTHING ELSE PRESS Y");
- String temp=input.next();
- ans3=temp.charAt(0);
- }while (ans3=='Y');
- double totalOverall=total;
- System.out.println("TOTAL PRICE : RM " + totalOverall+"0");
- //String tempT=" ",tempS=" ";
- try{
- BufferedWriter writer=new BufferedWriter(new FileWriter("receipt.txt"));
- writer.write("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~IFY H2O~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
- writer.write("CASHIER : "+"\t"+username+"\n");
- writer.write("CUSTOMER : "+"\t"+ name+""+name2+"\n");
- writer.write("CUSTOMER ID : "+"\t"+autoGenerator+"\n");
- writer.write("item SIZE PRICE QUANTITY TOTAL PRICE\n");
- while(Cdetail.isEmpty()==false){
- customerDetails obj = (customerDetails) Cdetail.dequeue();
- if(obj.getChoice()==1)
- writer.write("MINERAL WATER"+"\t"+"BIG"+"\t RM "+obj.getPrice()+"0\t "+obj.getQuantity()+"\t RM "+obj.getTotal()+"0\n");
- else if(obj.getChoice()==2)
- writer.write("MINERAL WATER"+"\t"+"SMALL"+"\t RM "+obj.getPrice()+"0\t "+obj.getQuantity()+"\t RM "+obj.getTotal()+"0\n");
- else if(obj.getChoice()==3)
- writer.write("DRINKING WATER"+"\t"+"BIG"+"\t RM "+obj.getPrice()+"0\t "+obj.getQuantity()+"\t RM "+obj.getTotal()+"0\n");
- else if(obj.getChoice()==4)
- writer.write("DRINKING WATER"+"\t"+"SMALL"+"\t RM "+obj.getPrice()+"0\t "+obj.getQuantity()+"\t RM "+obj.getTotal()+"0\n");
- }
- writer.write("====================================================================\n");
- writer.write("OVERALL TOTAL PRICE RM "+totalOverall+"0\n");
- writer.write("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~THANK YOU~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
- writer.close();
- }
- catch (FileNotFoundException e){
- System.out.println("Problem "+e.getMessage());
- }
- catch (IOException ioe){
- System.out.println("Problem "+ioe.getMessage());
- }
- profit.push(total);
- if((blocker.equals("allow"))&&(status.equals("manager"))){
- while (!profit.isEmpty())
- proCal=profit.pop()+proCal;
- System.out.println("ENTER Y TO DISPLAY YOUR PROFIT");
- String temp=input.next();
- char ans2=temp.charAt(0);
- if(ans2=='Y')
- System.out.println("YOUR PROFIT RM "+proCal+"0");
- }
- System.out.println("Continue? press Y");
- ans=input.next();
- } while (ans.equals("Y"));
- if(status.equals("staff")){
- System.out.println("IF YOU ARE MANAGER AND WANT TO DISPLAY PROFIT PRESS Y");
- String temp=input.next();
- char ans4=temp.charAt(0);
- if(ans4=='Y'){
- System.out.println("~~~SECUIRTY VERIFICATION~~~");
- System.out.println("ENTER MANAGER'S USERNAME :");
- String username1=input.next();
- System.out.println("ENTER MANAGER'S PASSWORD");
- String password1=input.next();
- String status1=" ";
- for (int counter = 0; counter < a.size(); counter++) {
- if ((a.get(counter).getUsername().equalsIgnoreCase(username1)) && (a.get(counter).getPassword().equalsIgnoreCase(password1))) {
- status1=a.get(counter).getStatus();
- if(status1.equals("manager")){
- while (!profit.isEmpty())
- proCal=profit.pop()+proCal;
- }
- System.out.println("YOUR PROFIT RM "+proCal+"0");
- break;
- }
- }
- }
- }
- }
- }
- }
- Log In
- public class login {
- private String username;
- private String password;
- private String status;
- //default constructor
- public login(){
- username=" ";
- password=" ";
- status=" ";
- }
- //normal constructor
- public login(String u,String p,String s){
- username=u;
- password=p;
- status=s;
- }
- //getter
- public String getUsername(){
- return username;
- }
- public String getPassword(){
- return password;
- }
- public String getStatus(){return status; }
- }
- Item
- public class ITEM {
- private int no;
- private String type;
- private String size;
- private double price;
- //default constructor
- public ITEM(){
- no=0;
- type=" ";
- size=" ";
- price=0.0;
- }
- //normal constructor
- public ITEM (int n,String t,String s,double p){
- no=n;
- type = t;
- size = s;
- price = p;
- }
- //mutator
- public void mutator(int N,String T,String S,double P){
- no=N;
- type=T;
- size=S;
- price=P;
- }
- //getter
- public int getNo(){return no;}
- public String getType(){
- return type;
- }
- public String getSize(){
- return size;
- }
- public double getPrice(){
- return price;
- }
- //toString
- public String toString(){
- return no+"\t"+type + "\t " + size + "\t RM " + price+"0";
- }
- }
- Customer Detail
- public class CustomerDetails {
- private int choice;
- private int quantity;
- private double price;
- private double total;
- //default constructor
- public CustomerDetails(){
- choice=0;
- quantity=0;
- price=0.0;
- total=0.0;
- }
- //normal constructor
- public CustomerDetails(int C,int Q,double P,double T){
- choice=C;
- quantity=Q;
- price=P;
- total=T;
- }
- //mutator
- public void setter(int c,int q,double p,double t){
- choice=c;
- quantity=q;
- price=p;
- total=t;
- }
- //getter
- public int getChoice(){
- return choice;
- }
- public int getQuantity(){
- return quantity;
- }
- public double getPrice(){
- return price;
- }
- public double getTotal(){
- return total;
- }
- public String toString(){
- return choice +"\t"+ quantity+"\t"+price+"\t"+total;
- }
- }
- Calculator
- public class Calculator {
- private int choice;
- private double price;
- private int quantity;
- //default constructor
- public Calculator(){
- choice=0;
- price=0.0;
- quantity=0;
- }
- //normal constructor
- public Calculator(int choice,double p,int q){
- price=p;
- quantity=q;
- }
- //mutator
- public void Calculator(int c,double P,int Q){
- choice=c;
- price=P;
- quantity=Q;
- }
- //getter
- public int getChoice(){
- return choice;
- }
- public double getPrice(){
- return price;
- }
- public int getQuantity(){
- return quantity;
- }
- }
- Linked List
- public class LinkedList {
- public Node first = null;
- public Node current = null;
- public Node last = null;
- public LinkedList() {
- }
- public void insertAtBack(Object item) {
- Node newNode = new Node(item);
- if(this.first == null) {
- this.first = newNode;
- this.last = newNode;
- } else {
- this.last.next = newNode;
- this.last = newNode;
- }
- }
- public Object removeFromFront() {
- Object removeData = null;
- if(this.first == null) {
- return removeData;
- } else {
- removeData = this.first.data;
- if(this.first == this.last) {
- this.first = null;
- this.last = null;
- } else {
- this.first = this.first.next;
- }
- return removeData;
- }
- }
- public Object removeFromBack() {
- Object removeData = null;
- if(this.first == null) {
- return removeData;
- } else {
- removeData = this.last.data;
- if(this.first == this.last) {
- this.first = null;
- this.last = null;
- } else {
- for(this.current = this.first; this.current.next != this.last; this.current = this.current.next) {
- ;
- }
- this.last = this.current;
- this.last.next = null;
- }
- return removeData;
- }
- }
- public Object getFirst() {
- if(this.first == null) {
- return null;
- } else {
- this.current = this.first;
- return this.current.data;
- }
- }
- public Object getNext() {
- if (current == last) {
- return null;
- } else {
- current = current.next;
- return current.data;
- }
- }
- }
- Queue
- public class Queue extends LinkedList {
- public Queue() {
- }
- public void enqueue(Object elem) {
- this.insertAtBack(elem);
- }
- public Object dequeue() {
- return this.removeFromFront();
- }
- public boolean isEmpty() {
- return this.getFirst() == null;
- }
- }
- Node
- public class Node {
- Object data;
- Node next;
- public Node(Object obj) {
- this.data = obj;
- }
- }
- Tree Node
- public class TreeNode
- {
- TreeNode left;
- TreeNode right;
- Calculator data;
- int temp=0;
- //normal constructor to initialize data to d and make this a leaf node
- public TreeNode(Calculator d)
- {
- left=right=null;
- data = d;
- }
- // Insert a TreeNode into a Tree that contains nodes. Ignore duplicate values.
- public void insert( Calculator d )
- {
- if ( d.getChoice() < temp )
- {
- if ( left == null )
- left = new TreeNode( d );
- else
- left.insert( d );
- }
- else
- if ( d.getChoice() > temp)
- {
- if ( right == null )
- right = new TreeNode( d );
- else
- right.insert( d );
- }
- //to make leaf well defined
- temp=d.getChoice();
- }
- }
- BS Tree
- public class BSTree
- {
- TreeNode root;
- // Construct an empty Tree
- public BSTree()
- { root = null; }
- // Insert a new node in the binary search tree.
- // If the root node is null, create the root node here.
- // Otherwise, call the insert method of class TreeNode.
- public void insertNode( Calculator d )
- {
- if ( root == null )
- root = new TreeNode( d );
- else
- root.insert( d );
- }
- // Preorder Traversal
- public void PreOrder()
- {
- RecurPreOrder( root );
- }
- // Recursive method to perform preorder traversal
- private void RecurPreOrder( TreeNode node )
- {
- if ( node == null )
- return;
- System.out.print( node.data + " " );
- RecurPreOrder( node.left );
- RecurPreOrder( node.right );
- }
- // Inorder Traversal
- public void InOrder()
- {
- RecurInOrder( root );
- }
- // Recursive method to perform inorder traversal
- private void RecurInOrder( TreeNode node )
- {
- if ( node == null )
- return;
- RecurInOrder( node.left );
- System.out.print( node.data + " " );
- RecurInOrder( node.right );
- }
- // Postorder Traversal
- public void PostOrder()
- {
- RecurPostOrder( root );
- }
- // Recursive method to perform postorder traversal
- private void RecurPostOrder( TreeNode node )
- {
- if ( node == null )
- return;
- RecurPostOrder( node.left );
- RecurPostOrder( node.right );
- System.out.print( node.data + " " );
- }
- //user defined
- public double totalPrice ( double price, int quantity)
- {
- return totPrice( root, price, quantity);
- }
- private double totPrice( TreeNode node, double price, int quantity )
- {
- if ( node == null) {
- return 0.0;
- }
- double total=0.0;
- total = price * quantity;
- return total + totPrice ( node.left, price, quantity ) +totPrice(node.right,price,quantity);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement