Hello guys,

I've recently started programming in Java, and I need help with one "assignment" that I found on one of our universitys website (Norwegian).
It's like this ( I will translate as good as I can, please leave a message if you don't understand ):

<  necessary import-packages >

public class Account
{
    <  Data fields for the account holder's name, account number and balance. >

    <  Constructor which initializes the account holder's name, account number and balance.  >

    <  set-method for account holder's name >

    <  get-method for account holder's name, account number and balance  >

    <  Account print-out method, which prints the account holder
        name, account number and balance in a dialog. >

    <  Metode som setter inn et beløp på kontoen.
       Beløpets størrelse skal tas imot via en parameter til metoden.
       Metoden skal returnere en tekst som inneholder informasjon om
       den nye saldoen.  >

} // end of class Account

I belive it's something like this:

import javax.swing.JOptionPane;

public class Account
{
    private String name;
    private long number;
    private double balance;

    public Account (String n, long nr, double s)
    {
	name = n;
	number = nr;
	balance = s;
    }

    public void setAccountname(String Accountname)
    {
	name = Accoutname;
    }

    public String getAccountname()
    {
	return name;
    }

    public long getAccountnumb()
    {
	return number;
    }

    public double getAccountbalance()
    {
	return balance;
    }

    public void visTittel()
    {
	JOptionPane.showMessageDialog(null, "Account holder's name: " + name + "\n"
+ "Account number: " + number + "\n"
+ "Balance: " + balance);
}

Is it right? Or is something wrong with this? Anyways, to my problem. Here is a pseudo-code for the main method:

<  necessary import-settings  >

public class Accountest
{
  public static void main(String[] args)
  {
    <  Create two Account-objects, which in the establishment is provided each name, each account number and each balance. >

    <  Test in ALL of the methods you've created in the Account-class at the
        Account objects. Write the results on the screen.
        Use the dialog windows for both scanning and printing.. >

  }
} // end of class Kontotest

Well, I didn't understand this, and was wondering if any of you could help me with this? What should I do? What does the program want (didn't understand)..

Thanks in advance :)

Is there any reason why you use JOptionPane instead of simple print method?
Also you did not translate last part of Account

For the second part

Account ac1 = new Account("User1", 123456, 5678.99);
Account ac2 = new Account("User2", 234567, 10.99);

//if you had print method you would do
ac1.print();
//other tests
System.out.println("Name: " + ac2.getAccountName());
System.out.println("Number: " + ac2.getAccountNumber());
System.out.println("Ballance: " + ac2.getAccountBallance());

//test set
ac2.setAccountName("User23");
ac2.print();

PS: Be aware I did not used exactly names as you

Thanks for the help! Yes, I need the JOptionPane, but I'll try to figure this out by myself! If I'm stucked, I'll ask again :)

Edit: I think I need to insert the account holder's name in a dialog box, and get the output with account number and balance. How should I do this with JOptionPane?

And btw. the last method in Account isn't necessary for this (it's an optional). it only says that I have to make a method for withdrawing and depositing money.

Edit: I think I need to insert the account holder's name in a dialog box, and get the output with account number and balance. How should I do this with JOptionPane?
>> If you create simple print method that return string there should be no problem

public Sting print(){
   return String.format("Account name: %s%nAccount number:%d%nAccount balance: %.2f%n", name, number, balance);
}

Thanks for your help, though I'm very confused about this. The first pseudo code in main class says that I need to create two account-objects which in the establishment is provided each name, account number and balance. Like you said, I did this:

Acc acc1 = new Acc("Justin Timberlake", 123456, 5678.57);
Acc acc1 = new Acc("Bruce Willis", 234567, 204.62);

The second pseuco code says that I must test all my methods I created in my account-class at the account-objects. Your result should be printed on the screen. Use dialog-windows for both input and output.

I still don't understand what my input should be. Could anyone give me some tips? And btw. could anyone check if I tested all my methods right?

acc1.setAccname("Justin Timberlake")
JOptionPane.showMessageDialog(null, 
"Account holders name: " + acc1.getAccname()								
+ "\nAccount number: " + acc1.getAccnumber()
+ "\nBalance: " + acc1.getBalance());

acc2.setAccname("Bruce Willis")
JOptionPane.showMessageDialog(null, 
"Account holders name: " + acc2.getAccname()								
+ "\nAccount number: " + acc2.getAccnumber()
+ "\nBalance: " + acc2.getBalance());

Is this right? My account class consists of one set-method for account holders name, three get-methods for account holders name, account number and balance, and the last one which prompts a message dialog on the screen (public void showHeader()).

You want to call your method with JOptionPane and not to create another one

acc1.visTittel()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.