Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

xfactor0707

macrumors newbie
Original poster
Aug 5, 2009
28
0
Alright guys im back. So this time my assignment is there giving me the test class and i have to create the main class. So this is the test class that that gave me.


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()));
}
}



So im here to see if you guys can give me some tips on how to get the program up and running.

This is my main class so far

public class PropertyTax
{
private static double totalTax;
private static double TaxableAmount;
private static double AssessedValue;
 
Let's look at what's used in the tester/driver:
Initializer that takes an int and double
Instance Methods:
void calculate()
double getAsessedValue()
double getTaxableAmount()
double getTaxRate()
double getTax()

Class methods:
double totalTax()

So from there you can figure out what instance and class variables the class needs, what methods you have to write, then you can get to implementing them.

-Lee
 
Let's look at what's used in the tester/driver:
Initializer that takes an int and double
Instance Methods:
void calculate()
double getAsessedValue()
double getTaxableAmount()
double getTaxRate()
double getTax()

Class methods:
double totalTax()

So from there you can figure out what instance and class variables the class needs, what methods you have to write, then you can get to implementing them.

-Lee

Thanks a lot man. Im working on my main class now, let me see what i can come up with
 
Alright this is my main class now


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;
}

}

Its still not compiling but i think im close
 
Its still not compiling but i think im close

When something doesn't compile, post the actual error message. Otherwise we can only guess at what the error is. Help us to help you.

I have several guesses...

The first is that your constructor is misnamed.

public House(double assvalue, double taxamt, int rate)
You have to name constructors with the same name as the class they belong to.

Second is the constructor is defined with 3 parameters, but the required constructor only takes 2.

new PropertyTax(100000, 1.05);

Also, you need to look very carefully at the types of the constructor parameters. 1.05 isn't going to fit in an int.

And what about calculate()?

Those aren't the only problems, just some I see that would cause compilation to fail.
 
The thing is dude, i just need to base my main class off of the test class they gave me. So the only thing that is wrong is my main class, and i have not idea if evenr part of my main class is right. I need help fast too cause its due by 11:55 tonight. Im really trying to learn this stuff
 
Where is your calculate method?
getTotalTax should be called totalTax.
chown33 said this, but your constructor is named incorrectly, and has the wrong argument count and type. 100000 is going to be an int literal, not a double.

Was the assignment given to you at 6pm and it's due at 11:55pm? That doesn't seem very fair.

-Lee

EDIT: Also, you need a static variable to store all of the tax calculated for each instance. Write your calculate function and figure out what you need to calculate for each instance, then what you need to add to the class variable.
 
No i got emailed the assignment on friday but i left to orlando for the weekend and i didnt get back till now. I know im asking for a big favor. But can you please write out the main class so it could compile. Because i dont understand when you guys just tell me to do these things because i dont understand what they mean. So i know you guys dont want to like directly fix it for me, but i would greatly appreciate it and it would be easier to learn off of the compiled program because then i could actually see the mistake i made. And how you connected all the methods together
 
I'm not sure what to add to my previous post. I am not going to write any code for a homework assignment of yours, but I'll reiterate:
public House

is not in a class called House. You need to name your constructor the same thing as your class. It needs to take an int and a double as its arguments to match the invocation in the driver provided to you.

You didn't write a calculate method. Your constructor should do 2 assignments, based on the two parameters. Your calculate method should calculate the tax on the given property, and add this to some sort of sum for all properties.

You wrote a method called getTotalTax, when the driver calls a method totalTax. You need to rename this.

You also need to be learning to read the error messages your compiler is producing. If i recall correctly, you're using an IDE. I would really switch to compiling with javac from the command line, the errors are spelled out pretty explicitly there. The IDE puts the errors on the proper lines, etc. but you have to know how to navigate the IDE to figure it out, and right now you should be focusing on learning the language, not learning an IDE.

-Lee
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.