4 Replies - 709 Views - Last Post: 26 November 2012 - 06:40 PM Rate Topic: -----

#1 Dana_Persad_05   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-November 12

java assignment. stuck midway having errors with code. can you assist?

Posted 25 November 2012 - 08:17 PM

i need help to write a code for the folllowing question.

A realtor wishes to track her commissions of house sales. The information that she collects is as follows:

house address a string
house type a string ( split level, bungalow, etc.)
sale price a double

She wishes to calculate the commission for each house as well as find the total commission earned for all houses. Commission is calculated as 7% of the first $100,000 and 3.5% of any amount over $100,000. Create an application that will accept an array of house objects and return the total commission. The application should also be able to calculate the commission earned on each house.

***Use the following test data:
123 Main Street, Split level, 250000.00
456 Elm Street, Bilevel, 150000.00
789 Oak Ave, Bungalow, 95000.00
***
i already made a class House and it compiles with no errors
public class House
{
private String houseAddress;
private String houseType; 
private double sellingPrice;

public House( String address, String type, double price)
{ setAddress(address);
setType(type);
setPrice(price);
}
public void setAddress(String add )
{
houseAddress = add;
}

public String getAddress()
{ return houseAddress;
}

public void setType(String typ )
{
houseType = typ;
}

public String getType()
{return houseType;
}

public void setPrice(double p )
{
sellingPrice = p;
}

public double getPrice()
{return sellingPrice;
}

}

but i attempted the HouseCommissions class and i am encountering some errors, can u please explain what i did wrong,, here is the code below

import java.util.*;
public class HouseCommissions
{
final private double commissionrate1= 0.07;
final private double commissionrate2 = 0.035;
double commission1;
double commision2;

Scanner in = new Scanner(System.in); 
House[] h= new House[3];

h[0]= new House{123 Main Street, Split level, 250000.00};
h[1]= new House{456 Elm Street, Bilevel, 150000.00};
h[2]= new House{789 Oak, Bungalow, 95000.00};


public double Commission(House[] h)
{ 

if( House[] h.getPrice<=100000.0)

{ commission1= (commissionrate1*h);
System.out.println(commission1);
}

else { commision2= commissionrate2*h;
System.out.println(commision2);
}
}

}

*** Edit ***
Please use code tags when posting code.
:code:

This post has been edited by GunnerInc: 25 November 2012 - 08:38 PM
Reason for edit:: Added elusive code tags


Is This A Good Question/Topic? 0
  • +

Replies To: java assignment. stuck midway having errors with code. can you assist?

#2 GunnerInc   User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 917
  • View blog
  • Posts: 2,358
  • Joined: 28-March 11

Re: java assignment. stuck midway having errors with code. can you assist?

Posted 25 November 2012 - 08:40 PM

Quote

but i attempted the HouseCommissions class and i am encountering some errors, can u please explain what i did wrong

What errors are there? Compiler errors? Not the expected output? If compiler errors, post the complete errors your compiler is giving you.

Help us help you!
Was This Post Helpful? 0
  • +
  • -

#3 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: java assignment. stuck midway having errors with code. can you assist?

Posted 25 November 2012 - 08:54 PM

View PostDana_Persad_05, on 25 November 2012 - 11:17 PM, said:

i already made a class House and it compiles with no errors

So what is your problem ?

This post has been edited by pbl: 25 November 2012 - 08:55 PM

Was This Post Helpful? 0
  • +
  • -

#4 heinbau   User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 22
  • Joined: 08-November 12

Re: java assignment. stuck midway having errors with code. can you assist?

Posted 25 November 2012 - 10:31 PM

Maybe I'm missing some requirement, but I would personally just have a calculate commission method inside of the house class. I think it would be a function of that house.

public double getTotalCommision()
{
     if (this.getPrice() <= 100000)
          return (double)(this.getPrice() * .07)
     else
         {
             return (double)((100000 * .07) + ((this.getPrice() - 100000) * .035))
         }
}



I just sortha threw that together, and am completely dead tired, so take it with a grain of salt....

PS yes it does appear as if you misunderstood the instructions about how she gets paid on her houses. You're basically shafting this real estate agent 50% on big sales! ;-)
Was This Post Helpful? 0
  • +
  • -

#5 Dana_Persad_05   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-November 12

Re: java assignment. stuck midway having errors with code. can you assist?

Posted 26 November 2012 - 06:40 PM

View Postheinbau, on 25 November 2012 - 10:31 PM, said:

Maybe I'm missing some requirement, but I would personally just have a calculate commission method inside of the house class. I think it would be a function of that house.

public double getTotalCommision()
{
     if (this.getPrice() <= 100000)
          return (double)(this.getPrice() * .07)
     else
         {
             return (double)((100000 * .07) + ((this.getPrice() - 100000) * .035))
         }
}








I just sortha threw that together, and am completely dead tired, so take it with a grain of salt....

PS yes it does appear as if you misunderstood the instructions about how she gets paid on her houses. You're basically shafting this real estate agent 50% on big sales! ;-)






did over my "housecommissions" class but i am encountering an error that has an arrow pointing to "main" in the line "public static void main" only one error. please help..

View PostDana_Persad_05, on 26 November 2012 - 06:39 PM, said:

View Postheinbau, on 25 November 2012 - 10:31 PM, said:

Maybe I'm missing some requirement, but I would personally just have a calculate commission method inside of the house class. I think it would be a function of that house.

public double getTotalCommision()
{
     if (this.getPrice() <= 100000)
          return (double)(this.getPrice() * .07)
     else
         {
             return (double)((100000 * .07) + ((this.getPrice() - 100000) * .035))
         }
}








I just sortha threw that together, and am completely dead tired, so take it with a grain of salt....

PS yes it does appear as if you misunderstood the instructions about how she gets paid on her houses. You're basically shafting this real estate agent 50% on big sales! ;-)






did over my "housecommissions" class but i am encountering an error that has an arrow pointing to "main" in the line "public static void main" only one error. please help..


import java.util.*;

public class HouseCommissions
{

public static void main(String[]args)
{
Scanner in=new Scanner(System.in);


private final double commissionrate1=0.07;
private final double commissionrate2=0.035;


{

House [] h = new House[3];

h[0] = new House("123 Main Street","Bilevel",250000.00);
h[1] = new House("456 Elm Street","Split Level",150000.00);
h[2] = new House("789 Oak Ave","Bungalow",95000.00);
}
public double Commission(House[] h)
{
for(int i=0; i<h.length;i++)
{

if( h[i] <=100000.0)
{
double num = (commissionrate1*h[i]);
System.out.println(num);
}
}

}
public double HouseCommission(House[] h1)

{
for(int j=0; j<h1.length;j++)
{
if( h1[j] >= 100000.0)
{
double num2= commissionrate2*h1[j];
System.out.println(num2);
}
}

}

}
}
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1