Hey I´m getting some errors, could anyone please help me to get rid of them?


Main code

import javax.swing.JOptionPane;

public class Kontotest
{
  public static void main(String[] args)
  {


   Konto bok = null;

   String navn = JOptionPane.showInputDialog( "Skriv inn navn");
   String nummer = JOPtionPane.showInputDialog( "Skriv inn kontonummer");
   String saldo = JOPtionPane.showInputDialog( "Skriv inn saldo");
   int nummer1 =  Integer.parseInt(nummer);
   int saldo1 =  Integer.parseInt(saldo);

   bok = new Konto(navn, nummer1, saldo1);

   String info = "Konto info\n";
   info += "\nKontoinnehavers navn " + bok.getNavn() + "\nKontonummer " + getKontonummer() + "\nSaldo " + getTotalsalda1();

  JOptionPane.showMessageDialog(null, info, "Konto info", JOptionPane.PLAIN_MESSAGE);
  }
}

Error main

Kontotest.java:12: cannot find symbol
symbol  : variable JOPtionPane
location: class Kontotest
   String nummer = JOPtionPane.showInputDialog( "Skriv inn kontonummer");
                   ^
Kontotest.java:13: cannot find symbol
symbol  : variable JOPtionPane
location: class Kontotest
   String saldo = JOPtionPane.showInputDialog( "Skriv inn saldo");
                  ^
Kontotest.java:20: cannot find symbol
symbol  : method getKontonummer()
location: class Kontotest
   info += "\nKontoinnehavers navn " + bok.getNavn() + "\nKontonummer " + getKontonummer() + "\nSaldo " + getTotalsalda1();
                                                                          ^
Kontotest.java:20: cannot find symbol
symbol  : method getTotalsalda1()
location: class Kontotest
   info += "\nKontoinnehavers navn " + bok.getNavn() + "\nKontonummer " + getKontonummer() + "\nSaldo " + getTotalsalda1();
                                                                                                          ^
4 errors

Code 2

import javax.swing.JOptionPane;

public class Konto
{
    
    private String innehaversnavn;

    private int kontonummer1;
 
    private int totalsaldo1;


   public Konto(String n, int k, int s)
   
   {
	 innehaversnavn = n;
	 kontonummer1 = k;
	 totalsaldo1 = s;
	
	
   }


    public void setNavn(String navn)
    {
	 innehaversnavn = navn;
	}

    public String getNavn()
    {
	 return innehaversnavn;
    }

    public void setKontonummer(int nummer)
    {
	 kontonummer1 = nummer;
	}

    public int getKontonummer()
    {
	 return kontonummer1;
	}

    public void setSaldo(int saldo)
    {
      totalsaldo1 = saldo;
	}

    public int getSaldo()
    {
	 return totalsaldo1;
	}
   


   public void visTittel()
{
   JOptionPane.showMessageDialog( null, "Navn\n " + innehaversnavn + "Kontonummer\n " + kontonummer1 + "Saldo\n " + totalsaldo1);

 }      

    
  
	}

cannot find symbol
symbol : variable JOPtionPane Java is case-sensitive JOPtionPane != JOptionPane

getKontonummer() is not a method of that class, it's in class Konto

Thanks, but get.Kontonummer1() should work right? I tried that, but didn´t work.

Why would that possibly work? There's no object called "get" and there's no method called Kontonummer1. Making random changes is never the answer.

You correctly call getNavn method just one line earlier. Can you see how similar getKontonummer is?

info += "\nKontoinnehavers navn " + bok.getNavn() + "\nKontonummer " + bok.getNummer1() + "\nSaldo " + bok.getSaldo1();

So how does this line look, i forgot bok. before, but this isn´t either working..?

Don't ask me - ask the compiler! It's good that you put the bok. in, but what follows must be the name of a method. Have another look at the Konto class to check the method names.

It´s called innehaversnavn , kontonummer1, totalsaldo1 in Konto class, so why does´t that work?

Those are variables not methods. They are (correctly) private, so you can't access them from outside the class anyway. You need to use the public methods.

Ah, thanks I got it now!

Great. Glad to help. J

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.