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:
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();
}
}
}
Your help would be greatly appreciated as i have to hand in the application to my boss tomorrow.
Cheers
Mishka
Tags: build, C#, Error, Studio, Visual