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 6924707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:41:48+00:00 2026-05-27T10:41:48+00:00

I have to read from a file, so made: cod_order (int) cod_cliente (int) cod_pizza

  • 0

I have to read from a file, so made:

cod_order (int)
cod_cliente (int)
cod_pizza (int)
num_pizza (int)
cod_pizza
num_pizza
...
$FINE

here is an example:

1
1107
02
1
01
5
03
2
$FINE

I created this method to read from this text file:

private void loadOrdini(String fname){

    try{

        BufferedReader reader = new BufferedReader(new FileReader(fname));

        String cod_ordine = reader.readLine();
        while(cod_ordine!=null){

            String cod_cliente=reader.readLine();

            Cliente cl=listaclienti.get(Integer.parseInt(cod_cliente));

            String cod_pizza=reader.readLine();
            while(!cod_pizza.equals("$FINE")){

                String n_pizze=reader.readLine();

                Ordine ord = new Ordine(Integer.parseInt(cod_pizza),Integer.parseInt(n_pizze));

                cl.getListaOrdini().put(Integer.parseInt(cod_ordine), ord);

                cod_pizza=reader.readLine();

            }

            cod_ordine=reader.readLine();
        }

    }
    catch(IOException ioe){

        ioe.printStackTrace();
    }

}

the problem is the method load into the HashMap listaordini only the numbers 03 and 2 while the numbers before aren’t considerer.why?

import java.util.*;

public class Cliente{

private String name;
private String address;

private Map<Integer,Ordine> listaordini;

public Cliente(String n,String addr){

    name=n;
    address=addr;

    listaordini=new HashMap<Integer,Ordine>();
}

public String getName(){

    return name;
}

public String getAddr(){

    return address;
}

public Map<Integer,Ordine> getListaOrdini(){

    return listaordini;
}

public String toString(){

    String temp="";

    temp+="Nome Cliente: "+name;
    temp+="\nIndirizzo: "+address;

    return temp;
}

}

even after this suggets the problem remain the same

  • 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-27T10:41:49+00:00Added an answer on May 27, 2026 at 10:41 am

    I think the other answers have missed the point: you want a mapping from order IDs to pizzas.

    The problem is, a map (such as a HashMap) must have a unique mapping for each key. What that means is, you can only map a single Ordine to the order ID, a map doesn’t support having multiple Ordines for the same order ID.

    There’s a couple of ways around this. You could make a new object that contains a list of Orders and put that into the map, or you could change your map to map an order ID to a List of orders.

    For example, doing it the second way you would have:

    // To create your map:
    Map<Integer, List<Ordine>> listaordini = new HashMap<Integer, List<Ordine>>( );
    
    
    
    // To add an order to it:
    Ordine ord = new Ordine(Integer.parseInt(cod_pizza),Integer.parseInt(n_pizze));
    
    List<Ordine> ordineList = cl.getListaOrdini( ).get(Integer.parseInt(cod_ordine));
    if (ordineList == null)
    {
        ordineList = new ArrayList<Ordine>( );
        cl.getListaOrdini( ).put(Integer.parseInt(cod_ordine), ordineList);
    }
    
    ordineList.add(ord);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made an app where I read words from an rtf file File
I have to write a program that read from a file that contains the
I have an XmlDocument that already exists and is read from a file. I
I have a Perl script that uses WWW::Mechanize to read from a file and
I have a byte array in memory, read from a file. I would like
I have dynamic array filled with bytes, which are read from .raw file with
I have some code to read from a pdf file. Is there a way
I'm trying to read a file from a local filesystem. I do not have
I have this function to read in all ints from the file. The problem
I have an xml file(from federal government's data.gov) which I'm trying to read with

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.