C# School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C# Expert!

Join 300,469 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,734 people online right now. Registration is fast and FREE... Join Now!




Build Error in Visual studio 8

 

Build Error in Visual studio 8, The type or namespace name 'student' could not be found (are y

Xander_X

4 Jul, 2009 - 01:56 AM
Post #1

New D.I.C Head
*

Joined: 30 Jun, 2009
Posts: 2

Hi,

This is the first time im creating a project using C# and its a course management system in which you can add a student, see the course figures, see students details and withdraw or enrol a student in a particular course and handle their fees etc.

and at the moment when i build the code i get
these three errors which are all basically the same.

Error 1 The type or namespace name 'student' could not be found (are you missing a using directive or an assembly reference?)

Error 2 The type or namespace name 'course' could not be found (are you missing a using directive or an assembly reference?)

Error 3 The type or namespace name 'Scanner' could not be found (are you missing a using directive or an assembly reference?)


Here is my code:

CODE


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Course_Management
{
    class Main
    {
    private static student [] students = new student[320];
    private static course [] courses = new course[5];
    private static int studentCount = 0;
    private static int courseCount = 0;
    private static int repeatDiscount = 0;
    private static int ageDiscount = 0;
    private static Scanner console = new Scanner(System);
    
    
    public static void main (String [] args)
       {
      char choice;
      String inputLine;
      
      loadsettingsanddata();

      do
      {
         Console.WriteLine();
         Console.WriteLine("Course Management System");
         Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~");
         Console.WriteLine("1. Add a Student");
         Console.WriteLine("2. Withdraw a Student");
         Console.WriteLine("3. Display a List of Students for a Course");
         Console.WriteLine("4. Display Course Figures");
         Console.WriteLine("5. Exit");
         Console.WriteLine();
         Console.WriteLine("Enter Option:");

         choice = ' ';
         inputLine = console.nextLine();

         if (inputLine.length() == 1)
            choice = inputLine.charAt(0);

         choice = Character.toUpperCase(choice);

         switch(choice)
         {
            case '1':
                addstudent();
                break;

            case '2':
                withdrawstudent();
                break;
              
            case '3':
                displaystudents();
                break;
                
            case '4':
                displaycoursefigures();
                break;

            case '5':
               savesettingsanddata();
               Console.WriteLine("Exiting Program... ");
               Console.WriteLine();
               break;

            default:
               Console.WriteLine("Error!  Thats an Invalid Selection - " +
                                  "Try again please...");
               Console.WriteLine();
         }

      } while (choice != '5');
   }
  
   /* adding student - Checks whether space is availabe within the desired course
    * then records students details, and updates neccessary figures for the course
    * such as income, and current enrollments
    */
   public static void addstudent()
   {
      String studname;
      String address;
      int age = 0;
      String course_ID;

      student tmpy = null;

      if (studentCount == students.length)
      {
         Console.WriteLine("Error - Students Full!");
         return;
      }

      Console.WriteLine("Enter ID of the Course: ");
      course_ID = console.nextLine();

      int spacesAvail = 0;
      for (int i = 0; i < courseCount; i++)
             {
                 if (courses[i].courseID.equalsIgnoreCase(course_ID))
                 {
                     spacesAvail = courses[i].checkSpaceAvail();
                 }
             }
         if (spacesAvail > 0)
         {
                 Console.WriteLine("Spaces Available: " + spacesAvail);
                 Console.WriteLine("Enter Student's Name: ");
              studname = console.nextLine();

              Console.WriteLine("Enter Student's Address: ");
              address = console.nextLine();
      
              if (address.equalsIgnoreCase("Enter Students Address: "))
              {
                  address = "Address Unknown";
              }
              
              Console.WriteLine("Enter Student's Age: ");
              age = Convert.ToInt16(entry);

              if (console.hasNextLine())
                console.nextLine();
            
              int feeOwing = calFees(course_ID);
              Console.WriteLine("Fees Owing: " + feeOwing);
              int rptdiscount = 0;
              String repeatingStudent = repeatStudent(studname);
              if (repeatingStudent.equals("Y"))
              {
                  rptdiscount = (feeOwing/100)* repeatDiscount;
              }else
              {
                  rptdiscount = 0;
              }
              int adiscount = 0;

              int newFees = feeOwing - rptdiscount - adiscount;
      
              Console.WriteLine("Repeat Discount: " + rptdiscount);
              Console.WriteLine("Age Discount: " + adiscount);
              Console.WriteLine("New Fees Owing: " + newFees);
      
              tmpy[counter] = new Student(course_ID, studname, address, age, feeOwing, 0, rptdiscount, adiscount);
              students[studentCount] = tmpy;
              studentCount++;
              for (int i = 0; i < courseCount; i++)
                     {
                         if (courses[i].courseID.equalsIgnoreCase(course_ID))
                         {
                             courses[i].adjustcourseincome(feeOwing,rptdiscount,adiscount);
                         }
                     }
         }else
         {
             Console.WriteLine("There are no spaces available in this Course");
         }
   }
  
   /* calculate course fee - retrieves the fees for selected course
    */
   public static int calFees(String courseID)
   {
           int fees = 0;
           for (int i = 0; i < courseCount; i++)
             {
                 if (courses[i].courseID.equalsIgnoreCase(courseID))
                 {
                     fees = courses[i].getChargeStudent();
                 }
             }
           
           return fees;
   }
  
   /* repeating student - determines whether the student being added is a repeat student,
    * so that the discount can be applied for the student
    */
   public static String repeatStudent(String name)
   {
           String repeatingStud = "N";
           
           for (int i=0; i < studentCount; i++)
           {
               if (students[i].studName.equalsIgnoreCase(name))
               {
                   repeatingStud = "Y";
               }
           }
           return repeatingStud;
   }
  
   /* withdraw student - checks that a valid course code is enters, then checks to see whether
    * the entered student has been enrolled in that course. If so, then the amount that should
    * be refunded to the student. Also updates the course details, such as income and the
    * number of students enrolled in the course.
    */
   public static void withdrawstudent()
   {
           String stuName;
           String course_ID;
           String addy = "";
           int age = 0;
           String corsName = "";
           String Scourse = "";
           String ans = "";
           
           Console.WriteLine("Enter the Course Id: ");
           course_ID = console.nextLine();
           int crecnum = 0;
           for (int i = 0; i < courseCount; i++)
           {
                if (courses[i].courseID.equalsIgnoreCase(course_ID))
                 {
                     corsName = courses[i].getCourseName();
                     crecnum = i;
                 }
           }
           if (corsName.equals("")){
                 Console.WriteLine("Error! Course not found, unable to withdraw student");
           }else
           {
               Console.WriteLine("Enter Student's Name: ");
               stuName = console.nextLine();
               int srecnum = 0;
               for (int i = 0; i < studentCount; i++)
              {
                  if (students[i].studName.equalsIgnoreCase(stuName))
                  {
                      if (students[i].courseID.equalsIgnoreCase(course_ID))
                      {
                          addy = students[i].getAddress();
                          age = students[i].getAge();
                          srecnum = i;
                      }
                  }
                }
           
               if (age == 0)
               {
                   Console.WriteLine("Error! Unable to withdraw student, student was not found in this course.");
               }else
               {
                     Console.WriteLine("Withdrawing Student: " + stuName + ", " + addy + ", " + age);
                     Console.WriteLine("From Course " + corsName);
                Console.WriteLine("Correct? Continue?(Y/N) :");
                ans = console.nextLine();
                if (ans.equalsIgnoreCase("Y"))
                {
                    students[srecnum].withdrawstudent();
                    int refund = students[srecnum].getAmtPaid();
                    int feeOwing = students[srecnum].getFeesOwing();
                    int rptDiscount = students[srecnum].getRDiscount();
                    int aDiscount = students[srecnum].getADiscount();
                    courses[crecnum].withdrawadjustment(feeOwing, rptDiscount,aDiscount);
                    Console.WriteLine("Amount to be refunded to student: " + refund);
                }
                 }
           }
   }
  
   /* display students - displays the students currently enrolled within the required
    * course. If no students enrolled, then message displayed.
    */
   public static void displaystudents()
   {
         if (studentCount > 0)
         {
               String courseID;
       
               Console.WriteLine("Enter Course ID: ");
             courseID = console.nextLine();
             Console.WriteLine();
             
             
             for (int i = 0; i < courseCount; i++)
             {
                 if (courses[i].courseID.equalsIgnoreCase(courseID))
                 {
                     courses[i].printstudentlist(courseID);
                 }
             }
        
          for (int i = 0; i < studentCount; i++)
          {
                  if (students[i].courseID.equalsIgnoreCase(courseID))
                  {
                      students[i].print();
                  }
            }
         }else
         {
             Console.WriteLine();
             Console.WriteLine("Error! There hasn't been any students added, unable to display list");
             Console.WriteLine();
         }
   }
  
   /* displays figures for each course
    */
   public static void displaycoursefigures()
   {
           Console.WriteLine();
           for (int i = 0; i < courseCount; i++)
           {
               courses[i].printcoursefigures();
           }
   }
  
   /*controls the loading of data when application started
    */
   public static void loadsettingsanddata()
   {
           Console.WriteLine("Loading Data");
           loadcourses();
           loadstudents();
           loaddiscounts();
   }
  
   /* load courses from file to be used while application is being used.
    */
   public static void loadcourses()
   {
           String ID;
           String name;
           String group;
           String tname;
           int stuenrolled;
           int stumax;
           int stucharge;
           int corscost;
           int cpstud;
           
           String inputLine;
           course tmpy = null;
           
           StreamReader SR;
  try
       {
            SR = File.OpenText("courselist.txt");
            inputLine = SR.ReadLine();
            while (inputLine != null) {
            ID = inputLine;
            inputLine = br.readLine();
            name = inputLine;
            inputLine = br.readLine();
            group = inputLine;
            inputLine = br.readLine();
            tname = inputLine;
            inputLine = br.readLine();
            stuenrolled = Integer.parseInt(inputLine);
            inputLine = br.readLine();
            stumax = Integer.parseInt(inputLine);
            inputLine = br.readLine();
            stucharge = Integer.parseInt(inputLine);
            inputLine = br.readLine();
            corscost = Integer.parseInt(inputLine);
            inputLine = br.readLine();
            cpstud = Integer.parseInt(inputLine);
            
            tmpy[counter] = new course(ID, name, group, tname,stuenrolled, stumax, stucharge,corscost, cpstud, 0);
            courses[courseCount] = tmpy;
            courseCount++;
            
            inputLine = br.readLine();
        }
        br.close();

      }
      catch (IOException exc)
{
    Console.WriteLine(exc.Message + "\nError Opening File");
    return;
      }
   }
  
   /* loads student details from file to be used while application being run
    */
   public static void loadstudents()
   {
           String ID;
           String name;
           String addy;
           int age;
           int feeOwing;
           int amtPaid;
           int rptDiscount;
           int aDiscount;
           
           String inputLine;
           student tmpy = null;
           
           StreamReader SR;
    try
         {
                SR = File.OpenText("studentlist.txt");
                inputLine = SR.ReadLine();
                while (inputLine != null) {
                ID = inputLine;
                inputLine = br.readLine();
                name = inputLine;
                inputLine = br.readLine();
                addy = inputLine;
                inputLine = br.readLine();
                age = Integer.parseInt(inputLine);
                inputLine = br.readLine();
                feeOwing = Integer.parseInt(inputLine);
                inputLine = br.readLine();
                amtPaid = Integer.parseInt(inputLine);
                inputLine = br.readLine();
                rptDiscount = Integer.parseInt(inputLine);
                inputLine = br.readLine();
                aDiscount = Integer.parseInt(inputLine);
            
            tmpy[counter] = new student(ID, name, addy, age, feeOwing,amtPaid,rptDiscount , aDiscount);
            students[studentCount] = tmpy;
            studentCount++;
            for (int i = 0; i < courseCount; i++)
                 {
                     if (courses[i].courseID.equals(ID))
                     {
                         courses[i].adjustcourseincome(feeOwing,rptDiscount,aDiscount);
                     }
                 }
            
            inputLine = br.readLine();
        }
        br.close();

    }
catch (IOException exc)
{
    Console.WriteLine(exc.Message + "\nError Opening File");
    return;
}
   }
  
   /* loads settings from file, the percentage for repeating students, the age at which
    * the age discount should be applied and the discount given when students meets the age
    * discount. This is stored within a file, so that should a change be required then changes
    * to the actual application is not required.
    */
   public static void loaddiscounts()
   {
           String inputLine;
           
           StreamReader SR;
    try
        {
            SR = File.OpenText("discounts.txt");
            inputLine = SR.ReadLine();
            while (inputLine != null) {
            repeatDiscount = Integer.parseInt(inputLine);
            inputLine = br.readLine();
            ageStartDiscount = Integer.parseInt(inputLine);
            inputLine = br.readLine();
            ageDiscount = Integer.parseInt(inputLine);
            inputLine = br.readLine();
        }
        br.close();

        }
      catch (IOException exc)
    {
    Console.WriteLine(exc.Message + "\nError Opening File");
    return;
    }
   }
  
   /* controls the saving of data to file
    */
   public static void savesettingsanddata()
   {
           Console.WriteLine();
           Console.WriteLine("Backing up data");
           Console.WriteLine();
           writecoursefiles();
           writestudentfiles();
   }
  
   /* writes all course details to file, so that they have been saved for
    * when the application is next run.
    */
   public static void writecoursefiles()
   {
           PrintWriter pw = new PrintWriter(
                              new BufferedWriter(
                                new FileWriter("courselist.txt")));
        
        int studentsEnrolled = 0;                        
        
        for (int i = 0; i< courseCount; i++)
        {
            pw.println(courses[i].getCourseId());
            pw.println(courses[i].getCourseName());
            pw.println(courses[i].getCoursegroup());
            pw.println(courses[i].getTeachersName());
            pw.println(studentsEnrolled);
            pw.println(courses[i].getMaxStudents());
            pw.println(courses[i].getChargeStudent());
            pw.println(courses[i].getCourseRunningCost());
            pw.println(courses[i].getCoursePStudent());
        }
        
        pw.close();
   }
  
   /* writes all student details to file for use when application is next used.
    * does not save data of withdrawn students, via this these details are removed from
    * the system.
    */
   public static void writestudentfiles()
   {
           PrintWriter pw = new PrintWriter(
                              new BufferedWriter(
                                new FileWriter("studentlist.txt")));
        
        for (int i = 0; i< studentCount; i++)
        {
            if (!students[i].courseID.equalsIgnoreCase("---"))
            {
                pw.println(students[i].getCourseID());
                pw.println(students[i].getStudName());
                pw.println(students[i].getAddress());
                pw.println(students[i].getAge());
                pw.println(students[i].getFeesOwing());
                pw.println(students[i].getAmtPaid());
                pw.println(students[i].getRDiscount());
                pw.println(students[i].getADiscount());
            }
        }
        
        pw.close();
   }
}
        }





Any help would be greatly appreciated as im usually using java and not so familiar with C#.

Thanks in advance.

Cheers

Misha


User is offlineProfile CardPM
+Quote Post


Renagado

RE: Build Error In Visual Studio 8

4 Jul, 2009 - 05:27 AM
Post #2

D.I.C Head
Group Icon

Joined: 14 Jun, 2009
Posts: 180



Thanked: 16 times
Dream Kudos: 100
My Contributions
You are referring to a class called students() and want to put them in an array called student[] but in your text I see here I can't find a class student().
( am talking about this line: private static student [] students = new student[320]; )


So you should make one, and put some variables in the constructor that can be instanciated for each student seperate.(things like their name, fees they owe, courses they follow etc) Same with the other 2 errors.

Just thought it also could be you have the student() and course() classes in a seperate file, in that case check if they are visible in the solution explorer(something like student.cs) and if they are using the same namespace(Course_Management), if not import the namespace with using......

Oh and this line:

CODE
private static Scanner console = new Scanner(System);


It could be some Java thing(I wouldnt know) like this it isn't going to work in c#. What are you trying to do there?

This post has been edited by Renagado: 4 Jul, 2009 - 05:56 AM
User is offlineProfile CardPM
+Quote Post

eclipsed4utoo

RE: Build Error In Visual Studio 8

4 Jul, 2009 - 08:26 AM
Post #3

Not Your Ordinary Programmer
Group Icon

Joined: 21 Mar, 2008
Posts: 1,808



Thanked: 201 times
Dream Kudos: 500
Expert In: .NET

My Contributions
where are your declarations for these classes?
User is offlineProfile CardPM
+Quote Post

Xander_X

RE: Build Error In Visual Studio 8

5 Jul, 2009 - 01:54 AM
Post #4

New D.I.C Head
*

Joined: 30 Jun, 2009
Posts: 2

Hi Guys,

I figured what my problem was, i had an array named student as well as a class.

yeah the scanner bit is java, like i said i know java and i have no idea about C#, i dont quite like C# either (no offense to those who like it)

Thank you for your help.

Xander_X
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 02:41AM

Live C# Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month