Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Help with Java

Options
  • 15-10-2006 9:30pm
    #1
    Closed Accounts Posts: 1,080 ✭✭✭


    I need help with these questions

    Question 3 - Ok I think this one is ok but I put it up for question 4
    [PHP]public class Product
    {
    public String name;
    public double price;

    public Product(String name,double price)
    {
    this.name = name;
    this.price = price;
    }

    public Product()
    {
    name = "Toaster";
    price = 29.95;
    }

    public String getName()
    {
    return name;
    }

    public double getPrice()
    {
    return price;
    }
    }
    [/PHP]

    Question 4 - Now that is all I have done in it! is it ment to be like the EmployeeHarness I have put up?
    [PHP]public class ProductHarness
    {
    public static void main(String[] args)
    {

    }
    }
    [/PHP]

    EmployeeHarness
    [PHP]import javax.swing.JOptionPane;
    public class EmployeeHarness
    {
    public static void main(String[] args)
    {
    String name = JOptionPane.showInputDialog("Enter your name");
    String salary = JOptionPane.showInputDialog("Enter your salary");

    Double db = new Double(salary);
    double Salary = db.doubleValue();

    Employee one = new Employee(name,Salary);
    System.exit(0);

    }
    }
    [/PHP]

    Question 5 - Ah I need something at the end of the aib program but I dont know wat!
    [PHP]public interface BankAccount
    {
    public void deposit(double amount);
    public void withdraw(double amount);
    public double getBalance();
    }
    [/PHP]

    [PHP]public class AIBBankAccount implements BankAccount
    {
    private double balance;

    public AIBBankAccount(double amount)
    {
    balance = amount;
    }

    public AIBBankAccount()
    {
    this(0,0);
    }

    public void deposit(double amount)
    }
    [/PHP]


Comments

  • Registered Users Posts: 919 ✭✭✭timeout


    Q3 - you are missing setprice method.
    Q4 - yes like EmployeeHarness but don't forget its 2 products this time not one. and the price has to be changed.
    Q5 - generally if you implement an interface you need to add code to the methods you are implementing, so add public void deposit(double amount); public void withdraw(double amount); public double getBalance(); along with the neccassary code.

    Hope that helps!


  • Registered Users Posts: 4,188 ✭✭✭pH


    Well a good habit to get into is to never use double for financial data. This is not just java but all coding languages, using a floating point variable to represent a monetary amount is a very bad idea.

    Having a default constructor that makes a product "toaster",29.95 is also a bad idea.


Advertisement