Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: embedded classes issue

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default embedded classes issue

    I'm having trouble calling a function from a class (from another class). The very last call is the one with the error. here's the complete code:

    import java.util.Scanner;
    import java.util.Random;
    import java.text.DecimalFormat;

    //student class
    class Student {
    Scanner scan = new Scanner(System.in);
    String Name, Address, Major;
    double gpa;

    Random generator = new Random();
    DecimalFormat df = new DecimalFormat("#.##");



    //constructor
    public Student (String name, String address, String major){
    Name = name;
    Address = address;
    Major = major;
    computeGPA();
    };

    //default constructor
    Student(String name, String address){
    Name = name;
    Address = address;
    Major = "undefined";
    computeGPA();
    }

    Student(){};


    public void computeGPA() {
    gpa = generator.nextFloat() * 3.51 + 0.5;
    }

    void listStudent(){
    System.out.println("Name\taddress\tmajor\tgpa");
    System.out.println(Name + "\t" + Address + "\t" + Major + "\t" + (df.format(gpa)));
    }
    }
    public class Class
    {

    int studentcount = 0;
    String classname, instructor;
    int numofstudents;
    double avGPA;
    public Student[] studentlist = new Student[5];

    //default constructor
    void Class(String teacher)
    {
    instructor = teacher;
    }



    //increase size of array
    void increaseSize()
    {
    Student[] temp = new Student[studentlist.length + 5];
    for (int a = 0; a < studentlist.length; a++)
    temp[a] = studentlist[a];

    studentlist = temp;
    }

    //add a student
    void addStudent(String enroll, String address)
    {
    if (studentcount == studentlist.length)
    increaseSize();
    studentlist[studentcount].Student(name, address);
    }
    }

    and here's the error:

    1 error found:
    File: C:\Users\devon\Desktop\DevonLab7\Class.java [line: 83]
    Error: C:\Users\devon\Desktop\DevonLab7\Class.java:83: cannot find symbol
    symbol : variable name
    location: class Class

    ___________________________________
    any help would be GREATLY appreciated- thanks!


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,307
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: embedded classes issue

    First, I highly recommend you rename your 'Class' - it conflicts with a J2SE class java.lang.Class and has the potential to cause a lot of confusion. Second, the error is fairly explanatory - go to line 83 and look at the variable name...where is it defined?

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: embedded classes issue

    Heh, yeah I noticed that about two minutes after I posted. The most simple thing is always the cause...

Similar Threads

  1. [SOLVED] Java DB embedded
    By potatostar in forum JDBC & Databases
    Replies: 5
    Last Post: July 20th, 2011, 11:17 AM
  2. Need Help with using classes [HELP]
    By dragon40226 in forum Java Theory & Questions
    Replies: 4
    Last Post: May 19th, 2011, 01:59 PM
  3. Managing an embedded database
    By jstn455 in forum JDBC & Databases
    Replies: 1
    Last Post: April 24th, 2011, 10:06 AM
  4. Help with JavaDB embedded
    By jstn455 in forum JDBC & Databases
    Replies: 2
    Last Post: March 17th, 2011, 03:27 PM
  5. Issue with abstract classes
    By zaphod2003 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 7th, 2011, 01:25 AM