Zelores 0 Newbie Poster

i checked everywhere i could for the answer. this is basically the problem i have. i declared a array at the class level. i have a text file with x lines of strings. how do i find the number of elements i need for the array

import java.io.*;
import java.util.Scanner;

public class ClockShop
{
    private String[] clocks = new String[index()];

    private int index() throws FileNotFoundException
    {
        Scanner file = new Scanner(new File("clocks.txt"));
        int i = 0;
        while(file.hasNextLine())
        {
            i++;
            file.nextLine();
        }
        file.close();
        return i;
    }
}

this is the error im getting:

ClockShop.java:9: unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown
private String[] clocks = new String[index()];
Zelores 0 Newbie Poster

so heres the issue im having. i have this class that im suppose to make for a tester class. i have to declare an array of string at the class level. there is method call to read the context of a file and put into the array. the problem im having is how do i get the number of elements the array needs? i cant change the tester class. iv tried calling a method ie private String[] clocks = new String[index()]; but its saying that the filenotfoundexception needs to be caught or thrown. i threw the exception. any ideas?

Zelores 0 Newbie Poster

Sorry I havent been able to reply. Way to busy at work lately. I just wanted to see what everyone had to say. Java is my first programming language and since I have never programmed before its a tad challenging for me. Well I should have better luck this coming quarter! I still want to do computer science.

Zelores 0 Newbie Poster

Hey guys,

So I finished my first year of college. I'm taking computer science, or well tiring to. My first programming class (python) wasn't to bad. The next class was java and well... I failed the class.... badly. Was it hard for you guys to learn programming for the first time? What got me was the projects later in class. Especially hangman. My friend basically did it all for me. I didn't even know where to start. My teacher didn't do a good job of telling us how to work on it. Was java hard for you guys? Because it was really hard for me.

Zel

Zelores 0 Newbie Poster

That is what I was doing. I figured it out why it wasn't working though. One of the sticks was bad. so i need to get another 512 stick. the strange thing is i left the good 512 in and when it was place in one slot. the computer said 1.4gb. i place it in the other slot the computer went back to 2gb. shouldn't it be 2.5gb?

Zelores 0 Newbie Poster

correction. its not an athlon, its a sempron

Zelores 0 Newbie Poster

Im pretty sure this question gets asked all the time.... anyways. i recently bought a 1gb stick. Now i have 3gb (2x 1gb and 2x 512mb). The two 1gn are in dual channel as well as the 512 sticks. Right on the board says DIMM 1 and 3 are side by side and the same for 2 and 4. My computer and windows won't detect the 3rd gb but cpuz does. I have updated my bios to the most recent but no luck. I checked the manual but no luck. Im out of ideas. Anyone know whats the issue is? I have a machspeed mk8-939a. with a AMD Athlon 3000+.

thanks

i should also add that when i take both of the 512sticks out, it stays at 2gb. I heard that other hardware like the video card can take some of the physical memory.

Zelores 0 Newbie Poster

Hey guys,
I got another stupid question. For my last assignment, I have to take a .txt file that has contacts in it, import it into python (already did that) and use it to search with. the file goes
last name
first name
number # repeats about 4 more times.
the thing is, I dont know how to use the file to search a name or number. i have to put in a number or name and it comes back with all the info (first, last and number). How do I go about doing this?

i know the first part is
fileInput = open("entries.txt","r")
contacts = fileInput.read()

thx. also thanks for helping me on my last post too!!

Zelores 0 Newbie Poster

well, computer science isnt bad. heck its the only thing im good at schooling wise. im just waiting till i can create actual programs. not these little find the binary value or make a menu with 4 options on it.

Zelores 0 Newbie Poster

thanks for all the help everyone! it really helped me. im still a noob when it comes to programming, espically to python. its just to bad that after this quarter i wont be working with python anymore. its all java and c++ lol.

Zelores 0 Newbie Poster

Hi, I just joined today and i need some help with python. I just started using python not to long ago in my intro programming class. We have an assignment coming up and i need some help. How do you get the sum of an integer. ie: you put in 123 and the sum is 6. I cant seem to figure it out. how do i go about doing that?