Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Help with Java

  • 15-10-2006 08: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, Registered Users 2 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, Registered Users 2 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