Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //node class
- /**
- * Created by yst on 19/03/2016.
- */
- public class Node {
- Object data;
- Node next;
- public Node(Object obj) {
- this.data = obj;
- }
- }
- //linked list
- /**
- * Created by yst on 19/03/2016.
- */
- 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;
- }
- }
- }
- //ITEM
- /**
- * Created by yst on 19/03/2016.
- */
- public class ITEM {
- private String type;
- private String size;
- private double price;
- //default constructor
- public ITEM(){
- type=" ";
- size=" ";
- price=0.0;
- }
- //normal constructor
- public ITEM (String t,String s,double p){
- type = t;
- size = s;
- price = p;
- }
- //mutator
- public void mutator(String T,String S,double P){
- type=T;
- size=S;
- price=P;
- }
- //getter
- public String getType(){
- return type;
- }
- public String getSize(){
- return size;
- }
- public double getPrice(){
- return price;
- }
- //toString
- public String toString(){
- return type + "\t " + size + "\t RM " + price+"0";
- }
- }
- //app
- /**
- * Created by yst on 11/03/2016.
- */
- import java.util.*;
- public class APP {
- public static void main(String[] args){
- 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("balqis","hanis"));
- a.add(new login("safuan","alane"));
- a.add(new login("abah","caah"));
- //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))) {
- System.out.println("Sucessfully Login\n");
- String type;
- int size;
- double price;
- LinkedList item=new LinkedList();
- item.insertAtBack(new ITEM("add category","add size ",add price double format));
- item.insertAtBack(new ITEM("add category","add size ",add price double format));
- //add as much as you want and use your logic
- int count=0;
- ITEM data=(ITEM) item.getFirst();
- while(data!=null){
- if (count==0){
- //main menu format edit if you wanted to do so
- System.out.println(" TYPE " + " SIZE " + " PRICE ");
- count++;
- }
- System.out.println(data);
- data=(ITEM) item.getNext();
- }
- }
- break;
- }
- }
- }
- //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