Please help me!

hi..i'm a student cs, i've wandering around here to find some

Page 1 of 1

6 Replies - 815 Views - Last Post: 29 August 2009 - 09:32 PM Rate Topic: -----

#1 heiz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-August 09

Please help me!

Post icon  Posted 28 August 2009 - 10:58 PM

import java.util.*;
import javax.swing.*;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class main
{
	public static void main (String[]args)
	{
		Scanner in = new Scanner(System.in);
	  
		  Queue StudQ = new Queue();
		  Queue BookQ = new Queue();
		  String choice="m",choice3="y",choice4="",titleSearch="",choice5="";
		  String data="yes";
		  int type=0;
		  String choice2="y";
		  boolean found=true;
		  int c=0,c2=0;
		
		  do
		  {
		   System.out.println("Note-please insert data if the 1st time use this library");
		   System.out.print("Enter Your choice (1-Data entry),(2-check Avalability),(3-return book),(4-display of book ),(5-borrow book) =");
		   
		   type=in.nextInt();		
	  
			 switch(type)
			 {
			 
			 case 1:
			 {
			   do
			   {
				System.out.print("Please insert Name:");
				String name=in.next();
				System.out.print("Enter ID :");
				int id=in.nextInt();
				System.out.print("Enter Couse :");
				String couse=in.next();
				System.out.print("Enter Part :");
				int part=in.nextInt();
				Student std1=new Student(name,id,couse,part);
				StudQ.enqueue(std1);
				   
				
			
		   
				System.out.println("\nThe Information for Book");   
				System.out.println("=====================================");
				System.out.print("\nHow many Book to enter :");
				int count1=in.nextInt();
				Book bk1=(Book)BookQ.getFront();
				String Bokname="";
				String a="";
					for(int i=0;i<count1;i++)
					{
						System.out.print("\nInsert Book's Name:");
						Bokname=in.next();
						System.out.print("Enter the Author of the book :");
						a=in.next();
						System.out.print("Insert date Borrow :");
						int db=in.nextInt();
						Book book1=new Book(Bokname,a,db,id);
						BookQ.enqueue(book1);
					   
						bk1=(Book)BookQ.getEnd();	
												
					}
				  System.out.println("_____________________________________________________");
			   System.out.print("Do you want to Insert more data (yes-y or No-n)=");  
				choice2=in.next();
			   } while(choice2.equalsIgnoreCase("y"));
			   
			   break;
			 }   
				
					
			}
			case 2:
			{
				do
				{
					System.out.print("Enter Your choice (1-checking name),(2-checking book) =");
					type=in.nextInt();  
					System.out.println("_____________________________________________________"); 
					
					if(type == 1)
					{
					System.out.println("Application for checking borrower"); 
					System.out.print("Enter name to seach:");
					String name=in.next();
				
					Student stud2=(Student)StudQ.getFront();
					 for (int d=0;d<2;d++)
					 {

					
						if(stud2.getName().equalsIgnoreCase(name))
						{
							System.out.println("_____________________________________________________");
							System.out.println("Below is the list of Borrowed the Book"); 
							System.out.println(stud2.getName()+ " is in list");
							System.out.println("_____________________________________________________"); 
							
						   // break;
						}
						stud2=(Student)StudQ.getEnd();
					}
					}
					else if(type == 2)
					 {
						 Book bk3=(Book)BookQ.getFront();
						 System.out.println("_____________________________________________________"); 
						 System.out.println("Application for checking Book"); 
						 System.out.print("Enter title for seach :");
						 String tit=in.next();
						 for (int d=0;d<2;d++)
						 {
									  
							if(bk3.getTitle().equalsIgnoreCase(tit))
							{
								System.out.println("_____________________________________________________"); 
								System.out.println("Below is the list of book title that already borrowed"); 
								System.out.println(bk3.getTitle()+ " is already borrowed");
								System.out.println("_____________________________________________________"); 
							
							//break;
							}
							bk3=(Book)BookQ.getEnd();
						}
					 }
						
					System.out.print("Do you want to insert more data (Yes-y or No-n)=");
					choice3=in.next();
			   } while(choice3.equalsIgnoreCase("y"));
			   break;
			}
			
			case 3:
			{
				System.out.println("_____________________________________________________"); 
				Student stud4=(Student)StudQ.getFront();
				 Book bk4=(Book)BookQ.getFront();
				System.out.println("Checking weather the book must to pay or not");
				System.out.println("Please insert Id");
				System.out.print("Enter the ID :"); 
				int id=in.nextInt();
			   
				
					
			
				
					for (int d=0;d<2;d++)
					{
						if(stud4.getId()==id)
						{
							double calTot=0;
							double  calTot2=0;
							double newTot=0.0;
							System.out.println("Book is borrowed by "+stud4.getName());
							System.out.print("Insert the Current date : ");
							int currDate=in.nextInt();
							calTot=currDate-bk4.getDateBorrow();
			   
							if(currDate-bk4.getDateBorrow()> 7)
							{
				
								System.out.println("The book is out of date ");
								calTot=currDate-bk4.getDateBorrow()-7;
								newTot=calTot*0.2;
								System.out.println("------Detail------");
								System.out.println("Date borrowed :"+bk4.getDateBorrow()+"/8/"+"2009");
								System.out.println("Date returned :"+currDate+"/8/"+"2009");
								System.out.println("Total to pay :RM "+newTot);
						
							}
							else if(currDate-bk4.getDateBorrow()< 7)
							{
			   
								calTot=currDate-bk4.getDateBorrow();
								calTot2=7-calTot;
								System.out.println("You have "+calTot2+" more days to borrow");
							}
							else
							System.out.println("please recheck");
											
						}
						bk4=(Book)BookQ.getEnd();
						stud4=(Student)StudQ.getEnd();
					}
					
					break;
				
			}
			case 4:
			{
				System.out.println("\nDisplay Detail book borrower");   
				System.out.println("=====================================");
				Student stud5=(Student)StudQ.getFront();
			   
				do
				{
					System.out.print("Insert Student id : ");
					 int id=in.nextInt();
				   Book bk5=(Book)BookQ.getFront();
				   for (int d=0;d<2;d++)
				   {
					 
					 if(stud5.getId()==id)
					 {
						System.out.println(stud5.display());
						System.out.println(bk5.display());

						System.out.print("Do you want to display another borrower (Yes-y No-n) =");  
						choice4=in.next();
					  
					}
					 stud5=(Student)StudQ.getEnd();
					 bk5=(Book)BookQ.getEnd();
				  }
				  
				} while(choice4.equalsIgnoreCase("y"));
				
				break;
			}
			case 5:
			{
				System.out.print("Please enter book title = ");  
				titleSearch=in.next();
				System.out.print("Insert the Current date : ");
				int currDate2=in.nextInt();
				
				Book bk6=(Book)BookQ.getFront();
				Student stud6 = (Student)StudQ.getFront();
				do
				{
					for (int d=0;d<2;d++)
					{
						String nameB="";
					 
						if(bk6.getTitle().equalsIgnoreCase(titleSearch))
						{
							System.out.print("book title = " + bk6.getTitle());
							if(stud6.getId() == bk6.getIdBorrow())
							{
								nameB = stud6.getName();	
							}
							else if(currDate2-bk6.getDateBorrow()<7)
							{
								System.out.print("Book is being borrowed by : \n name :"+nameB+"\nID :" + bk6.getIdBorrow());
								System.out.print("Do you want to enter queue? (Y-yes),(N-no)");
							
							}
						}
						bk6=(Book)BookQ.getNext();
						stud6 = (Student)StudQ.getNext();
					}
					System.out.print("Do you want to Insert more data (yes-y or No-n)=");  
					choice5=in.next();
			   } while(choice5.equalsIgnoreCase("y"));
				
				break;
			}
			
			default : System.out.println("Invalid input");
			
		  c2++;				
		System.out.println("_____________________________________________________");	 
		System.out.print("Do you want to EXIT or go to MAIN (Exit-e or Main-m) =");  
		choice=in.next();
		if(choice.equalsIgnoreCase("e"))
		   System.out.print("\nExit......");

		}  while(choice.equalsIgnoreCase("m"));
			 
		   
					   
}

}



Admin Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: Please help me!

#2 paperclipmuffin  Icon User is offline

  • Disassembling...
  • member icon

Reputation: 13
  • View blog
  • Posts: 944
  • Joined: 16-April 09

Re: Please help me!

Posted 28 August 2009 - 11:06 PM

Hi, and welcome to Dream.In.Code! :)

What is going wrong with your code? Can you give us a description of any compilation errors you are encountering?

Thanks!
Was This Post Helpful? 0
  • +
  • -

#3 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 550
  • View blog
  • Posts: 5,624
  • Joined: 20-March 08

Re: Please help me!

Posted 28 August 2009 - 11:08 PM

Also...:code:
Was This Post Helpful? 0
  • +
  • -

#4 heiz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-August 09

Re: Please help me!

Posted 29 August 2009 - 04:35 PM

View Postpaperclipmuffin, on 28 Aug, 2009 - 10:06 PM, said:

Hi, and welcome to Dream.In.Code! :)

What is going wrong with your code? Can you give us a description of any compilation errors you are encountering?

Thanks!

i`m having problem after i`m using the switch statement in the prog. B4 using the switch..the program seem to be ok.
I think there maybe the error lies round it. This progrm purpose is to recorded the activites if borrowing and returning books of library. I'm really thankful if anyone could help me. Tension!!!
Was This Post Helpful? 0
  • +
  • -

#5 syfran  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 83
  • View blog
  • Posts: 1,103
  • Joined: 12-July 09

Re: Please help me!

Posted 29 August 2009 - 04:44 PM

View Postheiz, on 29 Aug, 2009 - 03:35 PM, said:

View Postpaperclipmuffin, on 28 Aug, 2009 - 10:06 PM, said:

Hi, and welcome to Dream.In.Code! :)

What is going wrong with your code? Can you give us a description of any compilation errors you are encountering?

Thanks!

i`m having problem after i`m using the switch statement in the prog. B4 using the switch..the program seem to be ok.
I think there maybe the error lies round it. This progrm purpose is to recorded the activites if borrowing and returning books of library. I'm really thankful if anyone could help me. Tension!!!


Please, :code:. I can't read it without indentation at the very least.
Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Please help me!

Posted 29 August 2009 - 04:46 PM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#7 smacdav  Icon User is offline

  • D.I.C Head

Reputation: 56
  • View blog
  • Posts: 177
  • Joined: 06-June 09

Re: Please help me!

Posted 29 August 2009 - 09:32 PM

View Postheiz, on 29 Aug, 2009 - 05:35 PM, said:

i`m having problem after i`m using the switch statement in the prog. B4 using the switch..the program seem to be ok.
I think there maybe the error lies round it. This progrm purpose is to recorded the activites if borrowing and returning books of library. I'm really thankful if anyone could help me. Tension!!!


Since you didn't give any specifics as to what problem you're having in using the switch statement, I can only provide a couple of observations:
  • The closing } just before case 2 ends the switch statement. Move it to just before } while(choice.equalsIgnoreCase("m"));
  • java.util.Queue is an interface, not a class. You can't create an object of that type. If you have defined your own class Queue then you are creating a conflict by importing java.util.*.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1