Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7093091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:23:45+00:00 2026-05-28T08:23:45+00:00

I have made a simple program with : working with files(read write) end class

  • 0

I have made a simple program with :
working with files(read write)
end class extends
but the program does not work. Netbeans show no errors but when i run it ……some kind of errors show up …..and well i can’t understand where is my bug (i think is a logical one).

Here is the simple program:

package detyre_kursi;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class Detyre_kursi {

  public static void main(String[] args) {
    LlogariBankare llogaria1 = new LlogariBankare("aaa", 1000); 
    llogaria1.Balanca();    
  }

}



class LlogariBankare {
  //variablat e instances
  private String id;
  private int nrLlogarise;
  private int vitiHapjes;
  private double balanca;
  static int nrTranasksioneve = 0;

  public LlogariBankare() {
    System.out.println("Ju keni harruar te vendosi id dhe nrLlogarise");

  }

  public LlogariBankare(String id, int nrLlogarise) {
    this.id = id;
    this.nrLlogarise = nrLlogarise;
    vitiHapjes = 0;
    balanca = 0; 
    Lexim(this.id, this.nrLlogarise); 
  }

  public double getBalanca() {
    return balanca;
  }

  public int getVitiHapjes() {
    return vitiHapjes;
  }

  private void Lexim(String s, int llog) {
    try {
      File file = new File("c:\\java\\balanca.txt");
      Scanner scanner = new Scanner(file);
      while (scanner.hasNextLine()) {
        if (scanner.next().equals(s) && scanner.nextInt() == llog) {
          vitiHapjes = scanner.nextInt();
          balanca = scanner.nextDouble();
        }
      }
    } catch (IOException e) {
      e.getMessage();
    }   
  }


  void Balanca() { 
    try{
      File file = new File("c:\\java\\test.txt");
      PrintWriter out = new PrintWriter(file);
      out.println(this.balanca);  
    } catch (IOException e) {
      e.getMessage();
    }   
    System.out.println(this.id + " , ju keni " + this.balanca + 
        " lek ne llogarine tuaj te krijuar ne vitin " + vitiHapjes + 
        " dhe keni kryer " + nrTranasksioneve + " transaksione gjithsej");
  }


  void Terheqe(double terheqe) {
    this.balanca -= terheqe;
    System.out.println("Ju sapo keni terhequr " + terheqe + " nga llogaria juaj");
    nrTranasksioneve++;
  }

  void Depozitim(double depozitim) {
    this.balanca += depozitim;
    System.out.println("Ju sapo keni depozituar " + depozitim + " nga llogaria juaj");
    nrTranasksioneve++;
  }


}

class Interesi extends LlogariBankare {
  int vitiTanishem = 2012;
  double interesi = 0;
  int diferencaViteve = vitiTanishem - getVitiHapjes();

  Interesi(String id, int nrLlogarise) {
    super(id,nrLlogarise); 
  }

  void gjejInteresisn() {
    interesi = getBalanca() + getBalanca() * diferencaViteve * 0.01;
  }

}

The file balanca has this line in it :
aaa 1000 1990 34000

In poor words this is some simple version of a bank.

You read the balance from a file, and
you use the Terheqe() and Depozitim() for – and + the balance.
You use Balance() to see how many $ you have. When I run it, this error show up:

Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:907)
at java.util.Scanner.next(Scanner.java:1416)
at detyre_kursi.LlogariBankare.Lexim(Detyre_kursi.java:57)
at detyre_kursi.LlogariBankare.<init>(Detyre_kursi.java:40)
at detyre_kursi.Detyre_kursi.main(Detyre_kursi.java:11)

Java Result: 1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:23:46+00:00Added an answer on May 28, 2026 at 8:23 am

    This line causing issue. scanner.nextInt() might not be an int and I feel it is not good to do two next() calls unless you have specific reason.

    if(scanner.next().equals(s)&&scanner.nextInt()==llog){
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a program with a scroll pane, but it is not working.
I have made my own file type (.ddd) and I made a simple program
I have a simple nav made up of the following HTML; <div class=inner> <div
Heavy emphasis on simple. I've never made an installer and I'd rather not have
I have made a simple, test program to experiment using classes. It creates a
I have a very simple openGL program in C++. I have made a Sphere
I have made a simple test application for the issue, two winforms each containing
I have started using jQuery and rails. I have made a simple form that
I'm just playing around with WPF and MVVM, and I have made a simple
I have made a very simple AppleScript to close tabs in Safari. The problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.