Results 1 to 4 of 4
  1. #1
    brk35 is offline Member
    Join Date
    Feb 2012
    Posts
    1
    Rep Power
    0

    Default Help for finding out of error in this code

    Hello I'm studying about CS and I wrote these codes for my Algorithm Homework We haven't used JAVA before so I wrote these codes in C# first but I couldn't convert them to JAVA's syntax.Could you help me for converting ?






    import java.io.InputStream;
    import java.util.Scanner;

    import javax.print.DocFlavor.STRING;
    import javax.swing.Spring;
    import java.util.ArrayList;


    class Book
    {

    public string name;

    public string author;

    public string publisher;

    public int publishyear;

    public string silinecek;

    public void Info()
    {


    ArrayList karmaList = new ArrayList();

    karmaList.Add(name);

    karmaList.Add(author);

    karmaList.Add(publisher);

    karmaList.Add(publishyear);

    if (silinecek == name)
    {
    karmaList.Clear();
    }


    Console.WriteLine("Kitaplarımızın Listesi");

    foreach (object eleman in karmaList)

    System.out.println("Kitap Bilgileri {0}", eleman);





    }



    public void Tanit(string alias, string developer, string company, int year,string kit)
    {
    name = alias;

    author = developer;

    publisher = company;

    publishyear = year;

    silinecek = kit;


    }





    static void Main(string[] args)
    {

    Scanner scn=new Scanner(System.in);

    Book alpha = new Book();

    int option;
    do
    {
    System.out.println("------------ MENU -----------");

    System.out.println("1 - Kitap Ekle");

    System.out.println("2 - Kitabı sil");

    System.out.println("3 - Tüm kitapları göster");

    System.out.println("4 - Kapat");

    System.out.println("-----------------------------");

    System.out.println("Seçiminiz?");

    option = NextInt(System.in);
    string kito = " ";
    switch (option)
    {
    case 1:
    System.out.println("Lütfen girmek istediğiniz kitap sayısını giriniz");

    int length =NextInt(System.in);

    for (int i = 0; i < length; i++)
    {



    System.out.println("Lütfen kitabın adını giriniz");

    string bookname=scn.nextLine(System.in);

    System.out.println("Lütfen yazarın adını giriniz");

    string typer =scn.nextLine(System.in);

    System.out.println("Lütfen yayınevinin adını giriniz");

    string ltd=scn.nextLine(System.in);

    System.out.println("Lütfen basım tarihini giriniz");

    int date=scn.NextInt(System.in);

    string kit = kito;
    alpha.Tanit(bookname, typer, ltd, date, kit);



    }





    break;

    case 2:


    System.out.println("Lütfen silinmesini istediğiniz kitabı giriniz");

    kito = scn.nextLine(System.in);




    break;

    case 3:


    alpha.Info();


    break;
    }

    } while (option != 4);









    }



    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Help for finding out of error in this code

    Nothing specifically related to Eclipse. Moving to New to Java.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Help for finding out of error in this code

    1. Java is case sensitive. If those method calls are supposed to be to methods in standard JDK classes, many of them are wrong simply on account of being spelled with an uppercase letter.

    2. When seeking help with compile time or run time errors, post the entire error message including any stack trace.

    3. Scout around the FAQs or elsewhere on this site and learn to post your code within tags to retain its formatting. Get rid of the extraneous double spacing as nobody will bother to scroll up and down to read your few lines of code.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    DiamondSoul is offline Member
    Join Date
    Oct 2011
    Posts
    83
    Rep Power
    0

    Default Re: Help for finding out of error in this code

    One thing I notice right away is that the syntax for foreach loops is different in Java than in C#

    In C#:
    foreach(Type element in collection)

    In Java:
    for(Type element:collection)

    And yeah, it'd be easier to help you if you followed DarrylBurke's suggestions.

Similar Threads

  1. error in this code
    By gradiente99 in forum Eclipse
    Replies: 11
    Last Post: 07-20-2010, 05:58 PM
  2. Need help finding error in code
    By BobTedmen in forum New To Java
    Replies: 3
    Last Post: 05-04-2010, 04:51 AM
  3. Help Finding Compiler error solution please
    By jamesr2b in forum New To Java
    Replies: 5
    Last Post: 04-30-2009, 06:07 AM
  4. Replies: 0
    Last Post: 11-25-2008, 09:24 AM
  5. error in code
    By dirtycash in forum New To Java
    Replies: 2
    Last Post: 12-06-2007, 11:40 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
  •