Advertisement
YST

item main menu

YST
Mar 19th, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.95 KB | None | 0 0
  1. //node class
  2. /**
  3.  * Created by yst on 19/03/2016.
  4.  */
  5. public class Node {
  6.     Object data;
  7.     Node next;
  8.  
  9.     public Node(Object obj) {
  10.         this.data = obj;
  11.     }
  12. }
  13. //linked list
  14. /**
  15.  * Created by yst on 19/03/2016.
  16.  */
  17. public class LinkedList {
  18.     public Node first = null;
  19.     public Node current = null;
  20.     public Node last = null;
  21.  
  22.     public LinkedList() {
  23.     }
  24.  
  25.     public void insertAtBack(Object item) {
  26.         Node newNode = new Node(item);
  27.         if(this.first == null) {
  28.             this.first = newNode;
  29.             this.last = newNode;
  30.         } else {
  31.             this.last.next = newNode;
  32.             this.last = newNode;
  33.         }
  34.  
  35.     }
  36.  
  37.     public Object removeFromFront() {
  38.         Object removeData = null;
  39.         if(this.first == null) {
  40.             return removeData;
  41.         } else {
  42.             removeData = this.first.data;
  43.             if(this.first == this.last) {
  44.                 this.first = null;
  45.                 this.last = null;
  46.             } else {
  47.                 this.first = this.first.next;
  48.             }
  49.  
  50.             return removeData;
  51.         }
  52.     }
  53.  
  54.     public Object removeFromBack() {
  55.         Object removeData = null;
  56.         if(this.first == null) {
  57.             return removeData;
  58.         } else {
  59.             removeData = this.last.data;
  60.             if(this.first == this.last) {
  61.                 this.first = null;
  62.                 this.last = null;
  63.             } else {
  64.                 for(this.current = this.first; this.current.next != this.last; this.current = this.current.next) {
  65.                     ;
  66.                 }
  67.  
  68.                 this.last = this.current;
  69.                 this.last.next = null;
  70.             }
  71.  
  72.             return removeData;
  73.         }
  74.     }
  75.  
  76.     public Object getFirst() {
  77.         if(this.first == null) {
  78.             return null;
  79.         } else {
  80.             this.current = this.first;
  81.             return this.current.data;
  82.         }
  83.     }
  84.     public Object getNext() {
  85.         if (current == last) {
  86.             return null;
  87.         } else {
  88.             current = current.next;
  89.             return current.data;
  90.         }
  91.     }
  92. }
  93. //ITEM
  94.  
  95. /**
  96.  * Created by yst on 19/03/2016.
  97.  */
  98. public class ITEM {
  99.  
  100.     private String type;
  101.     private String size;
  102.     private double price;
  103.  
  104.     //default constructor
  105.     public ITEM(){
  106.         type=" ";
  107.         size=" ";
  108.         price=0.0;
  109.     }
  110.     //normal constructor
  111.     public ITEM (String t,String s,double p){
  112.         type = t;
  113.         size = s;
  114.         price = p;
  115.     }
  116.     //mutator
  117.     public void mutator(String T,String S,double P){
  118.         type=T;
  119.         size=S;
  120.         price=P;
  121.     }
  122.     //getter
  123.     public String getType(){
  124.         return type;
  125.     }
  126.     public String getSize(){
  127.         return size;
  128.     }
  129.     public double getPrice(){
  130.         return price;
  131.     }
  132.     //toString
  133.     public String toString(){
  134.             return type + "\t        " + size + "\t      RM " + price+"0";
  135.     }
  136.  
  137.  
  138. }
  139. //app
  140. /**
  141.  * Created by yst on 11/03/2016.
  142.  */
  143. import java.util.*;
  144. public class APP {
  145.     public static void main(String[] args){
  146.         String username=" ",password=" ";
  147.         Scanner input=new Scanner(System.in);
  148.         System.out.print("USERNAME :" );
  149.         username=input.next();
  150.         System.out.print("PASSWORD :");
  151.         password=input.next();
  152.  
  153.         //Arraylist for login
  154.         ArrayList<login> a =new ArrayList<login>();
  155.  
  156.         //adding object to a arraylist
  157.         a.add(new login("balqis","hanis"));
  158.         a.add(new login("safuan","alane"));
  159.         a.add(new login("abah","caah"));
  160.  
  161.         //username and password will be search according to the index respectively
  162.         for(int counter=0;counter<a.size();counter++){
  163.             if((a.get(counter).getUsername().equalsIgnoreCase(username))&&(a.get(counter).getPassword().equalsIgnoreCase(password))) {
  164.                 System.out.println("Sucessfully Login\n");
  165.                 String type;
  166.                 int size;
  167.                 double price;
  168.  
  169.                 LinkedList item=new LinkedList();
  170.  
  171.                 item.insertAtBack(new ITEM("add category","add size  ",add price double format));
  172.                  item.insertAtBack(new ITEM("add category","add size  ",add price double format));
  173.                 //add as much as you want and use your logic
  174.  
  175.                 int count=0;
  176.                 ITEM data=(ITEM) item.getFirst();
  177.                 while(data!=null){
  178.                     if (count==0){
  179.                         //main menu format edit if you wanted to do so
  180.                         System.out.println("   TYPE        " + "         SIZE " + "          PRICE ");
  181.                         count++;
  182.                     }
  183.                     System.out.println(data);
  184.                     data=(ITEM) item.getNext();
  185.                 }
  186.             }
  187.                 break;
  188.             }
  189.         }
  190.  
  191. }
  192. //add any other logic and syntax to make main menu easy for the end user
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement