Results 1 to 8 of 8
Like Tree3Likes
  • 3 Post By JosAH

Thread: Hi guys~ special prize for you all :)

  1. #1
    cjwei is offline Member
    Join Date
    Aug 2011
    Posts
    1
    Rep Power
    0

    Default Hi guys~ special prize for you all :)

    This is my assignment, can you help me check any errors and report to me? Special thanks to you if you able to reply how to solve the founded problem :) THANKS
    Java Code:
    import java.util.*;
    import java.io.*;
    public class application {
    
        public static void main(String[] args) {
        	Menus1();
        }
    
    	public static void Menus1(){
    		Scanner input = new Scanner(System.in);
        	Item[] itemArray = new Item[100];
    
        	readFile(itemArray);
    
        	System.out.println("**********Menus**********\n1.Book\n2.CD\n3.Stationery\n4.Stop");;
        	System.out.print("Enter your choose : ");
        	int choose = input.nextInt();
    
        	switch(choose){
        		case 1:
        			itemArray[0] = new Book();
        			Menus(itemArray);
        			break;
        		case 2:
        			itemArray[0] = new CD();
        			Menus(itemArray);
        			break;
        		case 3:
        			5
        				
        			itemArray[0] = new Stationery();
        			Menus(itemArray);
        			break;
        		case 4:
        			System.out.println("Thanks you for using this System.");
        			break;
        		default:
        			System.out.println("Your choose is not available.");
        			Menus1();
        			break;
        	}
        }
    
        public static void Menus(Item[] itemArray){
        	Scanner input = new Scanner(System.in);
        	try{
        		readFile(itemArray);
        	}catch(IOException ex){
        	}
    
        	System.out.println("1) Add An New Item.");
        	System.out.println("2) Search An Item.");
        	System.out.println("3) Amend The Details Of An Item.");
        	System.out.println("4) Update The Quantity Item.");
        	System.out.println("5) Stop Selling An Item.");
    		System.out.println("6) Display The Information of Item.");
    		System.out.println("7) Preview.");
    		System.out.print("Choose The Number You Want To Do(1-7) : ");
        	int choose = input.nextInt();
    
        		switch(choose){
        			case 1:
        				AddItem(itemArray);
        				break;
        			case 2:
        				SearchItem(itemArray);
        				break;
        			case 3:
        				AmendItem(itemArray);
        				break;
        			case 4:
        				UpdateQuantity(itemArray);
        				break;
        			case 5:
        				StopSelling(itemArray);
        				break;
        			case 6:
        				DisplayItem(itemArray);
        				break;
        			case 7:
        				try{
        					writeFile(itemArray);
        				}catch(IOException ex){
        				}
        				Menus1();
        				break;
        			default:
        				System.out.print("Incorrect input.Please try again.");
        				Menus(itemArray);
        				break;
        		}
        	}
    
        public static void AddItem(Item[] itemArray){
        	Scanner input = new Scanner(System.in);
    		int count=0;
    		int repeat;
    
    		do{
    			for(int i = 0 ; i<itemArray.length ; i++){
    				if(itemArray[i].getItem()==""){
    					count=i;
    					break;
    				}
    			}
    			userInput(count, itemArray);
    
    			System.out.print("Do you want to continue [0=No/1=Yes]: ");
    			repeat = input.nextInt();
    		}while(repeat == 1);
    
    		Menus(itemArray);
        }
    
        public static void SearchItem(Item[] itemArray){
        	Scanner input = new Scanner(System.in);
        	int equal;
        	int i = 100;
    
        	System.out.print("\nEnter the item code you want to search : ");
        	String ItemCode = input.next();
    
    		for(int r = 0 ; r < itemArray.length ; r++){
        		if(ItemCode.equals(itemArray[r].getItem())){
        			i = r;
        			break;
        		}
        	}
    		if(i!=100){
    			equal = equalsTo(i, itemArray);
    			if(equal != 1)
    				search(i, itemArray, ItemCode);
    		}
    		else
    			System.out.println("The item code is not found.\n");
    
        	Menus(itemArray);
    	}
    
    	public static void search(int i, Item[] itemArray, String ItemCode){
       		if(ItemCode.equals(itemArray[i].getItem())){
       	 			System.out.println("The Item Code is found.\n");
        			System.out.println(itemArray[i].toString());
       		}
    	}
    
        public static void AmendItem(Item[] itemArray){
        	Scanner input = new Scanner(System.in);
        	System.out.print("Enter The Item Code You Want To Amend : ");
        	String ItemCode = input.next();
        	int i = 100;
    
        	for(int r = 0 ; r < itemArray.length ; r++){
        		if(ItemCode.equals(itemArray[r].getItem())){
        			i = r;
        			break;
        		}
        	}
    		if(i!=100){
        		search(i, itemArray, ItemCode);
    
        		System.out.print("Is it?[0/1] : ");
        		int Yes = input.nextInt();
    
        		if(Yes == 1)
        			userInput(i, itemArray);
        		else
        			AmendItem(itemArray);
    		}
    		else
    			System.out.println("The item code is not found.\n");
    
        	Menus(itemArray);
        }
    
        public static void UpdateQuantity(Item[] itemArray){
        	Scanner input = new Scanner(System.in);
        	int i = 100;
        	System.out.print("Enter the item code that you need to update the quantity : ");
        	String ItemCode = input.next();
    
        	for(int r = 0; r < itemArray.length ; r++){
        		if(ItemCode.equals(itemArray[r].getItem())){
        			i = r;
        			break;
        		}
        	}
        	if(i!=100){
        		search(i, itemArray, ItemCode);
    
        		System.out.print("Is it?[0/1] : ");
        		int Yes = input.nextInt();
    			if(Yes == 1)
        			update(i, itemArray);
        		else
        			UpdateQuantity(itemArray);
        	}
        	else
        		System.out.println("The item code is not found.\n");
        	Menus(itemArray);
        }
    
        public static void update(int i, Item[] itemArray){
    		Scanner input = new Scanner(System.in);
    		int quantity = itemArray[i].getQuantity();
    
    		System.out.print("Enter 0 to spoilt or 1 to add quantity : ");
    		int choose = input.nextInt();
    
    		if(choose == 1){
    			System.out.print("Enter The number of reorder item : ");
    			int reorder = input.nextInt();
    
    			quantity += reorder;
    			itemArray[i].setQuantity(quantity);
        	}
        	else if(choose ==0){
        		System.out.print("Enter The number of spoilt item : ");
    			int spoilt = input.nextInt();
    
    			quantity -= spoilt;
    			itemArray[i].setQuantity(quantity);
        	}
        	else{
        		System.out.println("Incorrect input. Please try again.");
        		update(i, itemArray);
        	}
        	try{
        	writeFile(i, itemArray);
        	}catch(IOException ex){
        	}
        	Menus(itemArray);
        }
    
        public static void StopSelling(Item[] itemArray){
        	Scanner input = new Scanner(System.in);
        	System.out.print("Enter The Item Code You Want To Stop : ");
        	String ItemCode = input.next();
        	int i = 100;
    
        	for(int r = 0 ; r < itemArray.length ; r++){
        		if(ItemCode.equals(itemArray[r].getItem())){
        			i = r;
        			break;
        		}
        	}
    		if(i!=100){
        		search(i, itemArray, ItemCode);
    
        		System.out.print("Is it?[0=No/1=Yes] : ");
        		int Yes = input.nextInt();
    
        		if(Yes == 1){
        			System.out.print("Stop or Selling[0=Stop/1=Sell] : ");
        			int Stop = input.nextInt();
        			if(Stop == 1){
        				itemArray[i].setStatus(true);
        				System.out.println("This item is continue to sell.");
        			}
        			else if(Stop == 0){
        				itemArray[i].setStatus(false);
        				System.out.println("The Item is Stop to sell.\n");
        			}
        			else{
        				System.out.println("Incorrect input. Please try again.");
        				StopSelling(itemArray);
        			}
        		}
    		}
    		else
    			System.out.println("The item code is not found.\n");
    		try{
    			writeFile(i, itemArray);
    		}catch(IOException ex){
    		}
        	Menus(itemArray);
        }
    
        public static void DisplayItem(Item[] itemArray){
    		for(int i =0 ; i < itemArray.length ; i++){
    			if(itemArray[i].getItem() != "")
    			System.out.println(itemArray[i].toString());
    			else{
    				System.out.println("No More");
    				break;
    			}
    		}
    		Menus(itemArray);
        }
    
        public static int equalsTo(int i, Item[] itemArray){
        	int count = 0;
        	int equal = 0;
        	for(int r = 0; r < itemArray.length ; r++){
        		if(itemArray[i].getItem().equals(itemArray[r].getItem())){
        			count++;
        		}
        	}
        	System.out.println(count);
        	if(count >=2){
        		System.out.println("Got two or more item have the same item code. Please Amend the one of item.");
        		equal = 1;
        	}
        	return equal;
        }
    
        public static void userInput(int count, Item[] itemArray){
        	Scanner input = new Scanner(System.in);
    
        	try{
    			System.out.print("Enter the new item code : ");
    			String ItemCode = input.next();
    			System.out.print("Enter the new item Quantity : ");
    			int Quantity = input.nextInt();
    			System.out.print("Enter the new item Cost Price : ");
    			double CostPrice = input.nextDouble();
    			System.out.print("Enter the new item Sell Price : ");
    			double SellPrice = input.nextDouble();
    			System.out.print("Enter the new item Status : ");
    			boolean Status = input.nextBoolean();
    			System.out.print("Enter the new item Discount : ");
    			double Discount = input.nextDouble();
    
    			if(itemArray instanceof Book[]){
    				System.out.print("Enter the title of new item : ");
    				String title = input.next();
    				System.out.print("Enter the Author of new item : ");
    				String author = input.next();
    				System.out.print("Enter the publisher of new item : ");
    				String publisher = input.next();
    				System.out.print("Enter the ISBN10 of new item : ");
    				String ISBN10 = input.next();
    				System.out.print("Enter the ISBN13 of new item : ");
    				String ISBN13 = input.next();
    				System.out.print("Enter the fiction of new item : ");
    				String fiction = input.next();
    
    				itemArray[count] = new Book(ItemCode, Quantity, CostPrice, SellPrice, Status, Discount, title, author, publisher,
    				ISBN10, ISBN13, fiction);
    				try{
        				writeFile(itemArray);
        				}catch(IOException ex){
        			}
    			}
    			else if(itemArray instanceof CD[]){
    				System.out.print("Enter the title of new item : ");
    				String title = input.next();
    				System.out.print("Enter the description of new item : ");
    				String description = input.next();
    				System.out.print("Enter the distributer of new item : ");
    				String distributer = input.next();
    				System.out.print("Enter the No Of track of new item : ");
    				int NoOfTrack = input.nextInt();
    				System.out.print("Enter the TrackList of new item : ");
    				String TrackList = input.next();
    
    				itemArray[count] = new CD(ItemCode, Quantity, CostPrice, SellPrice, Status, Discount, title, description,
    					distributer, NoOfTrack, TrackList);
    				try{
        				writeFile(itemArray);
        				}catch(IOException ex){
        			}
    			}
    			else{
    				System.out.print("Enter the brand of new item : ");
    				String brand = input.next();
    				System.out.print("Enter the type of new item : ");
    				String type = input.next();
    				System.out.print("Enter the manufacturer of new item : ");
    				String manufacturer = input.next();
    				System.out.print("Enter the barcode of new item : ");
    				String barcode = input.next();
    
    				itemArray[count] = new Stationery(ItemCode, Quantity, CostPrice, SellPrice, Status, Discount, brand, type,
    					manufacturer, barcode);
    				try{
        				writeFile(itemArray);
        			}catch(IOException ex){
        			}
    			}
    		}catch(InputMismatchException e){
    			System.out.println("Error Input.Please try again.");
    		}
        }
    
        public static void readFile(Item[] itemArray)throws IOException{
        	DataInputStream in = null;
    
        		if(itemArray instanceof Book[]){
          			in = new DataInputStream(new BufferedInputStream(new FileInputStream("Book.txt")));
    
          			for(int i = 0; i < itemArray.length ; i++){
            	  		String ItemCode = in.readUTF();
              			int Quantity = in.readInt();
              			double Cprice = in.readDouble();
            	  		double Sprice = in.readDouble();
           	   			boolean status = in.readBoolean();
              			double discount = in.readDouble();
              			String title = in.readUTF();
              			String Author = in.readUTF();
              			String Publisher = in.readUTF();
              			String ISBN10 = in.readUTF();
              			String ISBN13 = in.readUTF();
              			String fiction = in.readUTF();
    
              			itemArray[i] = new Book(ItemCode, Quantity, Cprice, Sprice, status, discount, title, Author, Publisher
              			, ISBN10, ISBN13, fiction);
          			}
        		}
        		else if(itemArray instanceof CD[]){
         	 		in = new DataInputStream(new BufferedInputStream(new FileInputStream("CD.txt")));
    
          			for(int i = 0; i < itemArray.length ; i++){
              			String ItemCode = in.readUTF();
              			int Quantity = in.readInt();
             	 		double Cprice = in.readDouble();
              			double Sprice = in.readDouble();
              			boolean status = in.readBoolean();
              			double discount = in.readDouble();
              			String title = in.readUTF();
              			String description = in.readUTF();
              			String distributer = in.readUTF();
              			int NoOfTrack = in.readInt();
              			String TrackList = in.readUTF();
    
              			itemArray[i] = new CD(ItemCode, Quantity, Cprice, Sprice, status, discount, title, description, distributer
              				, NoOfTrack, TrackList);
          			}
        		}
        		else{
          			in = new DataInputStream(new BufferedInputStream(new FileInputStream("Stationery.txt")));
    
          			for(int i = 0; i < itemArray.length ; i++){
              			String ItemCode = in.readUTF();
             	 		int Quantity = in.readInt();
             	 		double Cprice = in.readDouble();
             	 		double Sprice = in.readDouble();
              			boolean status = in.readBoolean();
              			double discount = in.readDouble();
             	 		String brand = in.readUTF();
              			String type = in.readUTF();
              			String manufacturer = in.readUTF();
              			String barCode = in.readUTF();
    
        	      		itemArray[i] = new Stationery(ItemCode, Quantity, Cprice, Sprice, status, discount, brand, type, manufacturer, barCode);
          			}
        		}
          	in.close();
        }
    
        public static void writeFile (Item[] itemArray)throws IOException{
        	DataOutputStream out = null;
    
    		if(itemArray instanceof Book[]){
        		out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("Book.txt")));
    
        		for (int i = 0; i < itemArray.length; i++) {
        			if(itemArray[i].getItem() != ""){
            			out.writeUTF(itemArray[i].getItem());
            			out.writeInt(itemArray[i].getQuantity());
            			out.writeDouble(itemArray[i].getCPrice());
            			out.writeDouble(itemArray[i].getSPrice());
            			out.writeBoolean(itemArray[i].getStatus());
            			out.writeDouble(itemArray[i].getDiscount());
      	  	    		out.writeUTF(((Book)itemArray[i]).getTitle());
            			out.writeUTF(((Book)itemArray[i]).getAuthor());
            			out.writeUTF(((Book)itemArray[i]).getPublisher());
            			out.writeUTF(((Book)itemArray[i]).getISBN10());
            			out.writeUTF(((Book)itemArray[i]).getISBN13());
            			out.writeUTF(((Book)itemArray[i]).getFiction());
            		}
        		}
    		}
           	else if(itemArray instanceof CD[]){
        		out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("CD.txt")));
    
        		for (int i = 0; i < itemArray.length; i++) {
        			if(itemArray[i].getItem() != ""){
            			out.writeUTF(itemArray[i].getItem());
          		  		out.writeInt(itemArray[i].getQuantity());
            			out.writeDouble(itemArray[i].getCPrice());
            			out.writeDouble(itemArray[i].getSPrice());
            			out.writeBoolean(itemArray[i].getStatus());
            			out.writeDouble(itemArray[i].getDiscount());
            			out.writeUTF(((CD)itemArray[i]).getTitle());
            			out.writeUTF(((CD)itemArray[i]).getDescription());
            			out.writeUTF(((CD)itemArray[i]).getDistributer());
            			out.writeInt(((CD)itemArray[i]).getNoOfTrack());
            			out.writeUTF(((CD)itemArray[i]).getTrackList());
            		}
        		}
            }
            else{
        		out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("Stationery.txt")));
    
        		for (int i = 0; i < itemArray.length; i++) {
        			if(itemArray[i].getItem() != ""){
            			out.writeUTF(itemArray[i].getItem());
            			out.writeInt(itemArray[i].getQuantity());
            			out.writeDouble(itemArray[i].getCPrice());
            			out.writeDouble(itemArray[i].getSPrice());
            			out.writeBoolean(itemArray[i].getStatus());
            			out.writeDouble(itemArray[i].getDiscount());
            			out.writeUTF(((Stationery)itemArray[i]).getBrand());
            			out.writeUTF(((Stationery)itemArray[i]).getType());
            			out.writeUTF(((Stationery)itemArray[i]).getManufacturer());
            			out.writeUTF(((Stationery)itemArray[i]).getBarCode());
            		}
        		}
            }
         	out.close();
        }
    
        public static void writeFile (int i, Item[] itemArray)throws IOException{
        	DataOutputStream out = null;
    
    		if(itemArray instanceof Book[]){
        		out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("Book.txt")));
    
            	out.writeUTF(itemArray[i].getItem());
            	out.writeInt(itemArray[i].getQuantity());
            	out.writeDouble(itemArray[i].getCPrice());
            	out.writeDouble(itemArray[i].getSPrice());
            	out.writeBoolean(itemArray[i].getStatus());
            	out.writeDouble(itemArray[i].getDiscount());
      	  	    out.writeUTF(((Book)itemArray[i]).getTitle());
            	out.writeUTF(((Book)itemArray[i]).getAuthor());
            	out.writeUTF(((Book)itemArray[i]).getPublisher());
            	out.writeUTF(((Book)itemArray[i]).getISBN10());
            	out.writeUTF(((Book)itemArray[i]).getISBN13());
            	out.writeUTF(((Book)itemArray[i]).getFiction());
    		}
           	else if(itemArray instanceof CD[]){
        		out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("CD.txt")));
    
            	out.writeUTF(itemArray[i].getItem());
          		out.writeInt(itemArray[i].getQuantity());
            	out.writeDouble(itemArray[i].getCPrice());
            	out.writeDouble(itemArray[i].getSPrice());
            	out.writeBoolean(itemArray[i].getStatus());
           		out.writeDouble(itemArray[i].getDiscount());
            	out.writeUTF(((CD)itemArray[i]).getTitle());
            	out.writeUTF(((CD)itemArray[i]).getDescription());
            	out.writeUTF(((CD)itemArray[i]).getDistributer());
            	out.writeInt(((CD)itemArray[i]).getNoOfTrack());
            	out.writeUTF(((CD)itemArray[i]).getTrackList());
           	}
            else{
        		out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("Stationery.txt")));
    
            	out.writeUTF(itemArray[i].getItem());
            	out.writeInt(itemArray[i].getQuantity());
            	out.writeDouble(itemArray[i].getCPrice());
            	out.writeDouble(itemArray[i].getSPrice());
            	out.writeBoolean(itemArray[i].getStatus());
            	out.writeDouble(itemArray[i].getDiscount());
            	out.writeUTF(((Stationery)itemArray[i]).getBrand());
            	out.writeUTF(((Stationery)itemArray[i]).getType());
            	out.writeUTF(((Stationery)itemArray[i]).getManufacturer());
            	out.writeUTF(((Stationery)itemArray[i]).getBarCode());
            }
         	out.close();
        }
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,679
    Blog Entries
    7
    Rep Power
    21

    Default

    We are not your compiler.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    To clarify: we'll be happy to help if you have any specific questions, but we usually don't look to kindly on code dumps. So please feel free to ask any specific answerable questions you may have.

  4. #4
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    356
    Rep Power
    5

    Default

    lol @ special prize.

  5. #5
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,000
    Rep Power
    10

    Default

    Where's my special prize?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    Join Date
    Aug 2011
    Location
    Leicester/UK
    Posts
    2
    Rep Power
    0

    Default

    if you have a specific quest ask

  7. #7
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Quote Originally Posted by KevinWorkman View Post
    Where's my special prize?
    You are the special prize ;)

  8. #8
    Rami is offline Member
    Join Date
    Jul 2011
    Posts
    28
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    We are not your compiler.

    kind regards,

    Jos
    LOL! Very funny! True though

Similar Threads

  1. $50 prize to who ever can write this code
    By owencain in forum Advanced Java
    Replies: 10
    Last Post: 06-16-2011, 06:06 AM
  2. Special Characters on GUI
    By keo in forum AWT / Swing
    Replies: 4
    Last Post: 05-01-2011, 11:40 PM
  3. XML with special characters
    By Kaizah in forum XML
    Replies: 1
    Last Post: 11-06-2009, 03:26 PM
  4. Cash Prize Challenge
    By Laura 123 in forum New To Java
    Replies: 19
    Last Post: 04-01-2009, 04:56 AM
  5. JSP Prize Tags 3.4.0
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-13-2007, 04:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •