Ahmed Mohamed

Greenhorn
+ Follow
since Oct 25, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Ahmed Mohamed

well....as i understand so far....i have analyzed the problem..and i have come up with the following solution ...

1. FOUR FILES : for this there will be a class to read those files.
2. The Class Schedule: in this class all the methods that contains the logic of the algorithm will be implemented .
3. Class SchduleTest : the main method will go here.

is that the correct way?

thnkx
19 years ago
hi fellows.....
i am trying to write a program to solve class scheduling program....the problem is based on implementing the walksat algorithm or hill climbing algorithm.....i have looked at these algorithms but unfortunalely i was not be able to understand them and how to code them.......i was thinking that i can get some tips and ideas that will help me in solving this problem.....what functions i need....how do i relate things together by coding ?.......the problem statement as follows:


Input:
Four files with the following information:
(class id, session id, type of activity (class, Tutorial) no. of hours, preferred room id)

(student id, class id)

(room id, size)

(faculty id, class id, session id)


Constraint:
No student has conflict (two activities) at the same time.
A student has to take more than one Tutorial per course
Faculty should not teach two consecutive courses. Two course without any break in between them.

Requirement:
The program should read the above information and create a schedule as follows:
(Class id, session id, type of activity, room id)

The schedule should not violate any of the above mentioned constraint. A generate and test or random walk algorithm such as Hill Climbing or WALKSAT could be used in implementation of this program.


thank you very much.
19 years ago
hi friends,

i have been stuck with this prototype for 2 weeks.........i have 2 java files.....the first code is the interface code....and the second code is a code that reads the contents of a file.

the thing is ...i want to make the contents of the file appear in the TextBox of the interface.........i dont know how to do that..?......how i can link the 2 files together....how can i direct the file contents to appear in the TextBox in my interface........

HERE IS MY CODES..

1....INTERFACE CODE......

import javax.swing.*;
import javax.swing.border.*;

public class sanesense
{








public static void main (String[] args)
{





// creating the components
// Paragraph TextField + Question TextField + Answer TextField + ASK Button



JLabel Paragraph = new JLabel("Please Enter a Text..");
JTextArea ParagraphText = new JTextArea(6, 30);


ParagraphText.setEditable(true); // thi function disallow the user from changing the information in the text area.




JLabel Question = new JLabel("Your Question");
JTextArea QuestionText = new JTextArea(2,30);



JLabel Answer = new JLabel("The Answer");
JTextArea AnswerText = new JTextArea(5,30);

JButton button = new JButton ("ASK");
button.setLocation(100,200);








// creating the panel

JPanel panel = new JPanel();
Border etched = BorderFactory.createEtchedBorder();
Border titled = BorderFactory.createTitledBorder(etched, "");
panel.setBorder(titled);


panel.add(Paragraph);
panel.add(ParagraphText);
panel.add(Question);
panel.add(QuestionText);
panel.add(Answer);
panel.add(AnswerText);
panel.add(button);



// creating the frame


JFrame frame = new JFrame();
frame.setTitle("THE SANESENSE PROJECT");
frame.setContentPane(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,450);
frame.setResizable(true);


frame.setVisible(true);
frame.show();

}
}






2...CODE TO READ FROM A FILE....

import java.io.*;

class FileReadTest {



public static void main (String[] args)
{
FileReadTest t = new FileReadTest();
t.readMyFile();
}




void readMyFile()
{

String record = null;
int recCount = 0;

try {

FileReader fr = new FileReader("mydata");
BufferedReader br = new BufferedReader(fr);

record = new String();
while ((record = br.readLine()) != null) {
recCount++;
System.out.println(recCount + ": " + record);
}

} catch (IOException e) {
// catch possible io errors from readLine()
System.out.println("an IOException error!");
e.printStackTrace();
}

}

}


i will be very grateful for any comments or help.........even my bect coffee didnt help me to figure this out


Thank you very much

19 years ago
hi friends,
can any one direct me in how to display the contents of a file in a textArea of a GUI.....for example

the program should read a paragraph from a file ...this paragraph should be displayed in the TextArea in the GUI which is designed previously....how do i do that...?

THANKS
19 years ago
i understand that i have to modify my code to look like this :



public interface Course
{
public void courseName();


public void term();

}


public class CourseTest implements Course

{

public void CourseName()
{

System.out.println("JAVA PROGRAMMING");
}

public void term()
{

System.out.println("FALL 2004");

}


public static void main(String[] args)

{
CourseTest C = new CourseTest();

C.courseName();
C.term();

}

}

but do i have to save the file with the interface name or the class name?
20 years ago
hi people...and merry christmass .

i do have a question about interfaces....i was working on this code.

interface Courses
{
public void courseName();
public void term();
}

public class CoursesTest implements Courses
{
public static void main(String[] args)
{
CoursesList C = new CoursesList();
C.courseName();
C.term();
}
}

my question is : how do i dispalay this text for example
JAVA PROGRAMMING
SPRING 2004.

i have tried to put these strings in the interface but, i got an error says that an interface cannot have a body...

then i have done the following:

public class CourseTest implements Course
{
public static void main(String[] args)

{
Course C = new Course();
C.courseName();
{
System.out.println("JAVA PROGRAMMING");
}

C.term();
{
System.out.println("Fall 2004");
}

}

}

but i got an error saying : course is abstract and cannot be instantiated.
Can anyone help me to figure out whats wrong?

thank alot
20 years ago
hi.....i have finished the program that determines if the students fails or not..according to the grades.....well....i have an error..i dont know how to overcome it...it says " class expexted...here is the code :

import java.util.Vector;
import javax.swing.JOptionpane;
import java.io.InputStreamReader;
import java.io.BufferedReader;

public class student

{
double mark[]= new double[5];
String grade;
string name;
int id;

Vector v=new Vector();


student()

{

grade="";
name="";
id=0;

for(int i=0; i<5; i++)
{
mark[i]=0;
}

}


student (double d[], String g, String n, int idno)

{

mark =d;
grade=g;
name=n;
id=idno;
}



public void menu()

{
int choice = Integer.parseInt(JOptionPane.showInputDialog (" Enter No. for the Operation"
+"\n 1. Add a student."
+"\n 2. Total number of student."
+"\n 3. No. of students falling."
+"\n 4. Generate an annual report."
+"\n 5. Continue."
+"\n 6. Exit."));


if (choice ==1)
{ getValues(); }

else if (choice==2)
{ getTotalNumber(); }

else if(choice==3)
{ getfallgrade();}

else if(choice==4)
{display();}

else if(choice==5)
{menu();}

else
{ System.exit(0); }

menu();

}


public void getValues()

{

student s=new student();
s.name = JOptionPane.showInputDialog("Input student name:");
String idno = JOptionPane.showInputDialog("Enter ID:");
s.id =Integer.parseInt(idno);

String m = JOptionPane.showInputDialog("Marks for Mathematics");
String m1 = JOptionPane.showInputDialog("Marks for Arts");
String m2 = JOptionPane.showInputDialog("Marks for Science");
String m3 = JOptionPane.showInputDialog("Marks for Games");
String m4 = JOptionPane.showInputDialog("Marks for Computers");


s.mark[0]= double.parseDouble(m);
s.mark[1]= double.parseDouble(m1);
s.mark[2]= double.parseDouble(m2);
s.mark[3]= double.parseDouble(m3);
s.mark[4]= double.parseDouble(m4);

v.add(s);

}



public void getmark()

{

for (int i=0; i<5; i++)
{
System.out.println(mark[i]);
}
}



public void getfallgrade()

{

int acount=0;
int bcount=0;
int ccount=0;
int dcount=0;
int fcount=0;

for (int i=0; i<v.size(); i++)
{
student s = (student) v.elementAt(i);

if(s.grade=='A')
acount++;
else if(s.grade=='B')
bcount++;
else if(s.grade=='c')
ccount++;
else if(s.grade=='D')
dcount++;

}


System.out.println("students under A:"+acount);
System.out.println("students under B:"+bcount);
System.out.println("students under C:"+ccount);
System.out.println("students under D:"+dcount);
System.out.println("students under F:"+fcount);

}


public void getgrade()

{


double sum=0, avg=0;

for (int j=0; j<5; j++)
{
sum+= mark[j];
}

avg=sum/5;

System.out.println(avg);

if(avg>=90) grade="A";
else if (avg>=80) grade ="B";
else if (avg>=70) grade ="C";
else if (avg>=60) grade ="D";
else grade="F";
System.out.println(grade);
}


void getTotalNumber()

{

System.out.println( "Total number of students =" + v.size());
}

public void getname()
{
System.out.println(name);
}

public void getid()
{
System.out.println("ID:"+id);
}

void display()

{

for (int i=0; i<v.size(); i++)
{
student s =(sudent) v.elementAt(i);
System.out.println("Marks for students");
s.getmark();
s.getgrade();
s.getname();
s.getid();
}
}


public static void main( String args[]) throws Exception

{
student s = new student();
s.menu();
}
}


the error i get is in this part :

s.mark[0]= double.parseDouble(m);
^
s.mark[1]= double.parseDouble(m1);
^
s.mark[2]= double.parseDouble(m2);
^
s.mark[3]= double.parseDouble(m3);
^
s.mark[4]= double.parseDouble(m4);
^

thannks
20 years ago
I have to implement a class that will read marks of every student in different subjects and determine his grade. Grades are based on the average marks.

Given below are the criteria for deciding grades:

Average mark Below 40 Grade = �F�
Between 40 to 54 Grade = �D�
Between 55 to 69 Grade = �C�
Between 70 to 84 Grade = �B�
Above 85 Grade = �A�

Write a well-designed class having default and parameterized constructors to instantiate the class.
Also write different functions to:
1)take user inputs for student name, id and marks for various subjects,
2)get the total number of students entered,
3)number of students falling under every grade, and
4)Generate an annual report for a student in five subjects: Mathematics, Computers, Science, Arts and Games.

* Use Vectors to store every student record


i need only help about the idea of this question......ok..so far i understand that ... here is an outline of my idea :

public class Student
{
string name;
int mark;
int id;

void getInfo()
{}

void getTotalNumber()
{}

}

then i have to start the main function

public static void main (string[] args)
{

// i have to create objects to access the functions
}


please..is this design i correct so far?
i have some doubts about the fucntions point(3) and (4)
also...im confused about the the step of asking the user to input someting.... where do i have to use JOptionpane....inside the main fuction or outside?

thank you very much for help.
20 years ago