Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: How to compile and run java program?

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to compile and run java program?

    Hey guys im new to java and programming, im taking a introductory course into java and im having trouble with my current assignment. Ok they provided me with a test class and i had to create the main class. so this is what i got.

    public class PropertyTax
    {
     
    private static double totalTax;
     
     
    private double AssessedValue;
    private double TaxableAmount;
    private double TaxRate;
    private double Tax;
     
    public House(double assvalue, double taxamt, int rate)
    {
    AssessedValue = assvalue;
    TaxableAmount = taxamt;
    TaxRate = rate;
     
    totalTax = assvalue * rate;
    }
     
     
    public static double getTotalTax()
    {
    return totalTax;
    }
     
    public double getAssessedValue()
    {
    return AssessedValue;
    }
     
    public double getTaxableAmount()
    {
    return TaxableAmount;
    }
     
    public double getTaxRate()
    {
    return TaxRate;
    }
     
    public double getTax()
    {
    return Tax;
    }
     
    }
    this is the test class provided

    import java.text.NumberFormat;
     
    class TestPropertytax
    {
    public static void main(String[] arg)
    {
    NumberFormat nf = NumberFormat.getCurrencyInstance();
     
    PropertyTax p1 = new PropertyTax(100000, 1.05);
    p1.calculate();
    print(p1, nf);
    System.out.println("----------------------------------");
     
    PropertyTax p2 = new PropertyTax(150000, 1.05);
    p2.calculate();
    print(p2, nf);
    System.out.println("----------------------------------");
     
    System.out.println("Total tax revenue " + nf.format(PropertyTax.totalTax()));
    System.out.println("--------- End of report ----------");
    }
     
    static void print(PropertyTax p, NumberFormat nf)
    {
    System.out.println("Assessed value " + nf.format(p.getAssessedValue()));
    System.out.println("Taxable amount " + nf.format(p.getTaxableAmount()));
    System.out.println("Tax rate for each $100.00 is " + nf.format(p.getTaxRate()));
    System.out.println("Property tax is " + nf.format(p.getTax()));
    }
    }

    i need a lot of help getting this program to compile. I hope you guys could give me some tips that could help me compile my program which is due in a few.
    - Thanks ahead of time guys


  2. #2
    Junior Member
    Join Date
    Sep 2009
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: New guy with problems

    to compile this program
    javac filename.java
    to run this program
    java TestPropertytax
    I compiled ur program and found the following errors dude:
    E:\java>javac homework.java
    homework.java:12: invalid method declaration; return type required
    public House(double assvalue, double taxamt, int rate)
    ^
    homework.java:51: class, interface, or enum expected
    import java.text.NumberFormat;
    ^
    2 errors
    To fix this bug, do the following:
    For 1st error:
    public void House(double assvalue, double taxamt, int rate)
    for 2nd error:
    Check the import statements. U need to import additional packages.

  3. #3
    Junior Member
    Join Date
    Sep 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: New guy with problems

    Ok i added the void. But other than that i have no clue to what i need it to do to compile. Im a complete beginner with java and programming in general. It still doesnt compile when i add the void. What should i do next?

  4. #4
    Junior Member
    Join Date
    Sep 2009
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: New guy with problems

    Pal, follow my steps:

    1. Copy ur program into the "bin" folder. For eg. copy ur program into "c:\jdk1.6\bin". U can compile ur program from ur current working directory itself. But it is little complex. So we are following the easiest way.
    2. Open command prompt. Move to "c:\jdk1.6\bin"
    3. To compile ur program do the following:
    Type javac filename.java

    C:\jdk1.6\bin>javac homework.java
    4. To run the program do the following:
    Type java classname
    C:\jdk1.6\bin>java TestPropertytax

  5. #5
    Junior Member
    Join Date
    Sep 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: New guy with problems

    i know how to compile and stuff. I do it off of netbeans. Im saying that if you guys could help me find out whats wrong with my main class.

Similar Threads

  1. Problems with recursion
    By KingLane in forum Algorithms & Recursion
    Replies: 4
    Last Post: September 21st, 2009, 12:02 AM
  2. Homework problem (scanner problems)
    By TommyFiz in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: September 20th, 2009, 07:10 PM
  3. If you have any .NET problems
    By antony_t in forum The Cafe
    Replies: 1
    Last Post: August 26th, 2009, 11:49 AM
  4. big problems bounding() in Java2d with LineBreakMeasurer.
    By fenderman in forum AWT / Java Swing
    Replies: 0
    Last Post: July 27th, 2009, 02:15 PM
  5. Problems in setting classpath
    By missyati in forum Java Theory & Questions
    Replies: 3
    Last Post: June 30th, 2009, 01:43 AM