Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class Ordliste{
- ArrayList<Ord> ordliste = new ArrayList<Ord>();
- public void lesBok(String filnavn) throws Exception{
- File filen = new File(filnavn);
- Scanner in = new Scanner(filen);
- while (in.hasNextLine())
- {
- Ord ord = new Ord(in.nextLine());
- ordliste.add(ord);
- }
- }
- public void leggTilOrd(String s)
- {
- for(int i = 0; i < ordliste.size(); i++)
- {
- Ord ord = ordliste.get(i);
- if(ord.ord.equals(s))
- {
- antallForekomster =+ 1;
- }
- else
- {
- ordliste.add(ord);
- }
- break;
- }
- }
- public Ord finnOrd(String s) {
- for(int i = 0; i < ordliste.size(); i++)
- {
- Ord ord = ordliste.get(i);
- if(ord.ord.equals(s))
- {
- return ord;
- }
- }
- return null;
- }
- public int antallForekomster(String s)
- {
- for(int i = 0; i < ordliste.size(); i++)
- {
- Ord ord = ordliste.get(i);
- if(ord.ord.equals(s))
- {
- antallForekomster++;
- }
- }
- return antallForekomster;
- }
- Ord vanligste()
- {
- Ord ord = ordliste.get(0);
- for(int i = 0; i < ordliste.size(); i++)
- {
- if(ordliste.get(i).antallForekomster > ord.antallForekomster())
- {
- ord = ordliste.get(i);
- }
- }
- return ord;
- }
- public static void main(String[] args) throws Exception
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement