Hi!
Having programmed in non-object oriented programming languages for a pretty long time, thinking in terms of classes and objects hurts my brain.

I have written a program in BASIC (to print out the result sheet of a class after having obtained the data such as name of the student and their marks in each subject) which if you read is pretty easy to understand and is sufficiently well documented.

10 CLS
20 REM *** Dimensioning variables ***
30 DIM NAMES$(40)
40 DIM RESULT(40)
50 DIM GRADE$(40, 13)
60 DIM DIVISION(40)
70 DIM TMARKS(40)
80 DIM PERCENTAGE(40)
90 DIM MARKS(40, 13)
100 REM *** subject code list ***
110 REM 1 - English
120 REM 2 - Second Language
130 REM 3 - Mathematics
140 REM 4 - Physics
150 REM 5 - Chemistry
160 REM 6 - Biology
170 REM 7 - Geography
180 REM 8 - History / Civics
190 REM 9 - Sixth Subject
200 REM 10- SUPW
210 REM *** set variable to the number of student in the class ***
220 LET STRENGTH = 2
230 REM *** loop for inputting marks ***
240 FOR I = 1 TO STRENGTH
250 INPUT "Name of Student :"; NAMES$(I)
260 PRINT
270 INPUT "English :"; MARKS(I, 1)
280 PRINT
290 INPUT "Second Language :"; MARKS(I, 2)
300 PRINT
310 INPUT "Mathematics :"; MARKS(I, 3)
320 PRINT
330 INPUT "Physics :"; MARKS(I, 4)
340 PRINT
350 INPUT "Chemistry :"; MARKS(I, 5)
360 PRINT
370 INPUT "Biology :"; MARKS(I, 6)
380 PRINT
390 INPUT "Geography :"; MARKS(I, 7)
400 PRINT
410 INPUT "History / Civics :"; MARKS(I, 8)
420 PRINT
430 INPUT "Sixth Subject :"; MARKS(I, 9)
440 PRINT
450 INPUT "S.U.P.W. :"; MARKS(I, 10)
460 NEXT I
470 REM *** process result ***
480 PRINT "Processing result........"
490 PRINT "========================="
500 FOR I = 1 TO STRENGTH
510 PRINT
520 PRINT "Processing Roll Number:"; I
530 REM *** initialize tmarks(i) to zero
540 TMARKS(I) = 0
550 FOR J = 1 TO 10
560 REM *** process grades , total marks and percentage ***
570 IF MARKS(I, J) >= 0 AND MARKS(I, J) <= 9 THEN GRADE$(I, J) = "10*"
580 IF MARKS(I, J) >= 10 AND MARKS(I, J) <= 19 THEN GRADE$(I, J) = "09*"
590 IF MARKS(I, J) >= 20 AND MARKS(I, J) <= 29 THEN GRADE$(I, J) = "08*"
600 IF MARKS(I, J) >= 30 AND MARKS(I, J) <= 39 THEN GRADE$(I, J) = "07*"
610 IF MARKS(I, J) >= 40 AND MARKS(I, J) <= 49 THEN GRADE$(I, J) = "06"
620 IF MARKS(I, J) >= 50 AND MARKS(I, J) <= 59 THEN GRADE$(I, J) = "05"
630 IF MARKS(I, J) >= 60 AND MARKS(I, J) <= 69 THEN GRADE$(I, J) = "04"
640 IF MARKS(I, J) >= 70 AND MARKS(I, J) <= 79 THEN GRADE$(I, J) = "03"
650 IF MARKS(I, J) >= 80 AND MARKS(I, J) <= 89 THEN GRADE$(I, J) = "02"
660 IF MARKS(I, J) >= 90 AND MARKS(I, J) <= 100 THEN GRADE$(I, J) = "01"
670 REM *** add up marks to get the total marks ***
680 TMARKS(I) = TMARKS(I) + MARKS(I, J)
690 NEXT J
700 REM *** calculate percentage ***
710 PERCENTAGE(I) = (TMARKS(I) / 1000) * 100
720 NEXT I
730 REM *** process promoted/ detained ***
740 FOR I = 1 TO STRENGTH
750 REM *** processing for compulsory subjects ENGLISH & SUPW ***
760 REM *** rflag=0 means 'PROMOTED' rflag=1 means 'DETAINED'
770 LET RFLAG = 0
780 IF MARKS(I, 1) < 40 OR MARKS(I, 10) < 40 THEN RFLAG = 1
790 REM *** processing for two subject failure ***
800 REM *** fcounter stands for FAIL COUNTER ***
810 LET FCOUNTER = 0
820 FOR J = 1 TO 10
830 IF MARKS(I, J) < 40 THEN FCOUNTER = FCOUNTER + 1
840 NEXT J
850 IF FCOUNTER > 2 THEN RFLAG = 1
860 REM *** update result '1' means PROMOTED '0' means DETAINED ***
870 IF RFLAG = 1 THEN RESULT(I) = 0 ELSE RESULT(I) = 1
880 REM *** process division ***
890 IF PERCENTAGE(I) >= 80 AND RESULT(I) = 1 THEN DIVISION(I) = 1
900 IF PERCENTAGE(I) >= 60 AND PERCENTAGE(I) <= 79 AND RESULT(I) = 1 THEN DIVISION(I) = 2
910 IF PERCENTAGE(I) < 60 AND RESULT(I) = 1 THEN DIVISION(I) = 3
920 IF RESULT(I) = 0 THEN DIVISION(I) = 0
930 NEXT I
940 REM *** process printing of result ***
950 REM *** start loop ***
960 FOR I = 1 TO STRENGTH
970 LPRINT " St. Josephs Convent"
980 LPRINT " Kalimpong"
990 LPRINT
1000 LPRINT " Report Card"
1010 LPRINT " ( Class: VIII )"
1020 LPRINT
1030 LPRINT "Roll Number : ";I;" Name of Student : "; NAMES$(I)
1040 LPRINT "-------------------------------------------------------------"
1050 LPRINT "SUBJECT MARKS GRADE"
1060 LPRINT "-------------------------------------------------------------"
1070 LPRINT "English "; MARKS(I, 1); " "; GRADE$(I, 1)
1080 LPRINT "Second Language "; MARKS(I, 2); " "; GRADE$(I, 2)
1090 LPRINT "Mathematics "; MARKS(I, 3); " "; GRADE$(I, 3)
1100 LPRINT "Physics "; MARKS(I, 4); " "; GRADE$(I, 4)
1110 LPRINT "Chemistry "; MARKS(I, 5); " "; GRADE$(I, 5)
1120 LPRINT "Biology "; MARKS(I, 6); " "; GRADE$(I, 6)
1130 LPRINT "Geography "; MARKS(I, 7); " "; GRADE$(I, 7)
1140 LPRINT "History/Civics "; MARKS(I, 8); " "; GRADE$(I, 8)
1150 LPRINT "Sixth Subject "; MARKS(I, 9); " "; GRADE$(I, 9)
1160 LPRINT "S.U.P.W "; MARKS(I, 10); " "; GRADE$(I, 10)
1170 LPRINT "-------------------------------------------------------------"
1180 LPRINT "TOTAL MARKS: "; TMARKS(I); " PERCENTAGE : "; PERCENTAGE(I); "%"
1190 LPRINT
1200 IF RESULT(I) = 1 THEN RESULT$ = "Promoted" ELSE RESULT$ = "Detained"
1210 IF DIVISION(I) = 0 THEN DIVISION$ = " No Division Awarded"
1220 IF DIVISION(I) = 1 THEN DIVISION$ = " 1st"
1230 IF DIVISION(I) = 2 THEN DIVISION$ = " 2nd"
1240 IF DIVISION(I) = 3 THEN DIVISION$ = " 3rd"
1250 LPRINT "RESULT: "; RESULT$; " DIVISION:"; DIVISION$
1260 LPRINT
1270 LPRINT
1280 LPRINT "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = "
1290 LPRINT "Division will be awarded on the basis of the percengage of marks"
1300 LPRINT "----------------------------------------------------------------"
1310 LPRINT "1st Division ---> 80% and above"
1320 LPRINT "2nd Division ---> 60% - 79%"
1330 LPRINT "3rd Division ---> Below 60% provided the student passes"
1340 LPRINT "Failed student will not be awarded any division"
1350 LPRINT "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = "
1360 LPRINT
1370 LPRINT
1380 LPRINT "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = "
1390 LPRINT "Grade intervals for the subjects are as follows"
1400 LPRINT "-----------------------------------------------"
1410 LPRINT "90 - 100 ---> 01 50 - 59 ---> 05 10 - 19 ---> 09*"
1420 LPRINT "80 - 89 ---> 02 40 - 49 ---> 06 00 - 09 ---> 10*"
1430 LPRINT "70 - 79 ---> 03 30 - 39 ---> 07*"
1440 LPRINT "60 - 69 ---> 04 20 - 29 ---> 08* * -----> FAIL"
1450 LPRINT "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = "
1460 REM *** Send Form Feed character to the printer to move to the next page ***
1470 LPRINT CHR$(12)
1480 NEXT I

I want to write the same program in JAVA. What are the classes and functions that I will need? The kind of help that I need here is that if you could let me know which classes I need to break up the above BASIC program into and which function should the classes contain. I have picked up the basics of the input/output/process of JAVA and am pretty confident I can write the program (though I *may* just need help!).

Thanks for reading this post. I will be more thankful, if you could give me a postive response.

Regards,
Rupesh Pradhan

Hi everyone,
Java is more similar to the C language than basic. There is no convention as how many functions can be used as by looking at your program i can break it into 2 functions or even 10 functions. it really depends what you want you want your functions to do. The best thing is to try to learn the awt classes first as they are the basic foundation of Java and after that then try learning swing.

Since you are a basic programmer you can try moving to envelop 1.4 or
rapid-q (much better) as i know of some people finding it easier to move to java awt from rapid-q and envelop 1.4 but the ultimate decision is yours.

Take things step by step, it'll be easier

Yours Sincerely

Richard West

Hi,

Your program seems very sequential. In Any programming language it is generally bad form to have an extremely long function, so we can do better by dividing the task here into many functions executed sequentially.

You don't need to have object oriented code in Java. Something like this:

public class Program {

    // REM *** Dimensioning variables ***
    // REM NAMES$(40)

    // VARIABLES HERE
    // Notice the "static"
    public static String[] names;


    public static void main(String args[]) {

        displayMenu();

        getUserInput();

        calculateGrade();

        // etc.
    }


    public static void displayMenu() {
        // print the subjects here
        // *** subject code list ***
   } 
}

Hope this helps!


Ed

Hi!
Having programmed in non-object oriented programming languages for a pretty long time, thinking in terms of classes and objects hurts my brain.

I have written a program in BASIC (to print out the result sheet of a class after having obtained the data such as name of the student and their marks in each subject) which if you read is pretty easy to understand and is sufficiently well documented.

10 CLS
20 REM *** Dimensioning variables ***
30 DIM NAMES$(40)
40 DIM RESULT(40)
50 DIM GRADE$(40, 13)
60 DIM DIVISION(40)
70 DIM TMARKS(40)
80 DIM PERCENTAGE(40)
90 DIM MARKS(40, 13)
100 REM *** subject code list ***
110 REM 1 - English
120 REM 2 - Second Language
130 REM 3 - Mathematics
140 REM 4 - Physics
150 REM 5 - Chemistry
160 REM 6 - Biology
170 REM 7 - Geography
180 REM 8 - History / Civics
190 REM 9 - Sixth Subject
200 REM 10- SUPW
210 REM *** set variable to the number of student in the class ***
220 LET STRENGTH = 2
230 REM *** loop for inputting marks ***
240 FOR I = 1 TO STRENGTH
250 INPUT "Name of Student :"; NAMES$(I)
260 PRINT
270 INPUT "English :"; MARKS(I, 1)
280 PRINT
290 INPUT "Second Language :"; MARKS(I, 2)
300 PRINT
310 INPUT "Mathematics :"; MARKS(I, 3)
320 PRINT
330 INPUT "Physics :"; MARKS(I, 4)
340 PRINT
350 INPUT "Chemistry :"; MARKS(I, 5)
360 PRINT
370 INPUT "Biology :"; MARKS(I, 6)
380 PRINT
390 INPUT "Geography :"; MARKS(I, 7)
400 PRINT
410 INPUT "History / Civics :"; MARKS(I, 8)
420 PRINT
430 INPUT "Sixth Subject :"; MARKS(I, 9)
440 PRINT
450 INPUT "S.U.P.W. :"; MARKS(I, 10)
460 NEXT I
470 REM *** process result ***
480 PRINT "Processing result........"
490 PRINT "========================="
500 FOR I = 1 TO STRENGTH
510 PRINT
520 PRINT "Processing Roll Number:"; I
530 REM *** initialize tmarks(i) to zero
540 TMARKS(I) = 0
550 FOR J = 1 TO 10
560 REM *** process grades , total marks and percentage ***
570 IF MARKS(I, J) >= 0 AND MARKS(I, J) <= 9 THEN GRADE$(I, J) = "10*"
580 IF MARKS(I, J) >= 10 AND MARKS(I, J) <= 19 THEN GRADE$(I, J) = "09*"
590 IF MARKS(I, J) >= 20 AND MARKS(I, J) <= 29 THEN GRADE$(I, J) = "08*"
600 IF MARKS(I, J) >= 30 AND MARKS(I, J) <= 39 THEN GRADE$(I, J) = "07*"
610 IF MARKS(I, J) >= 40 AND MARKS(I, J) <= 49 THEN GRADE$(I, J) = "06"
620 IF MARKS(I, J) >= 50 AND MARKS(I, J) <= 59 THEN GRADE$(I, J) = "05"
630 IF MARKS(I, J) >= 60 AND MARKS(I, J) <= 69 THEN GRADE$(I, J) = "04"
640 IF MARKS(I, J) >= 70 AND MARKS(I, J) <= 79 THEN GRADE$(I, J) = "03"
650 IF MARKS(I, J) >= 80 AND MARKS(I, J) <= 89 THEN GRADE$(I, J) = "02"
660 IF MARKS(I, J) >= 90 AND MARKS(I, J) <= 100 THEN GRADE$(I, J) = "01"
670 REM *** add up marks to get the total marks ***
680 TMARKS(I) = TMARKS(I) + MARKS(I, J)
690 NEXT J
700 REM *** calculate percentage ***
710 PERCENTAGE(I) = (TMARKS(I) / 1000) * 100
720 NEXT I
730 REM *** process promoted/ detained ***
740 FOR I = 1 TO STRENGTH
750 REM *** processing for compulsory subjects ENGLISH & SUPW ***
760 REM *** rflag=0 means 'PROMOTED' rflag=1 means 'DETAINED'
770 LET RFLAG = 0
780 IF MARKS(I, 1) < 40 OR MARKS(I, 10) < 40 THEN RFLAG = 1
790 REM *** processing for two subject failure ***
800 REM *** fcounter stands for FAIL COUNTER ***
810 LET FCOUNTER = 0
820 FOR J = 1 TO 10
830 IF MARKS(I, J) < 40 THEN FCOUNTER = FCOUNTER + 1
840 NEXT J
850 IF FCOUNTER > 2 THEN RFLAG = 1
860 REM *** update result '1' means PROMOTED '0' means DETAINED ***
870 IF RFLAG = 1 THEN RESULT(I) = 0 ELSE RESULT(I) = 1
880 REM *** process division ***
890 IF PERCENTAGE(I) >= 80 AND RESULT(I) = 1 THEN DIVISION(I) = 1
900 IF PERCENTAGE(I) >= 60 AND PERCENTAGE(I) <= 79 AND RESULT(I) = 1 THEN DIVISION(I) = 2
910 IF PERCENTAGE(I) < 60 AND RESULT(I) = 1 THEN DIVISION(I) = 3
920 IF RESULT(I) = 0 THEN DIVISION(I) = 0
930 NEXT I
940 REM *** process printing of result ***
950 REM *** start loop ***
960 FOR I = 1 TO STRENGTH
970 LPRINT " St. Josephs Convent"
980 LPRINT " Kalimpong"
990 LPRINT
1000 LPRINT " Report Card"
1010 LPRINT " ( Class: VIII )"
1020 LPRINT
1030 LPRINT "Roll Number : ";I;" Name of Student : "; NAMES$(I)
1040 LPRINT "-------------------------------------------------------------"
1050 LPRINT "SUBJECT MARKS GRADE"
1060 LPRINT "-------------------------------------------------------------"
1070 LPRINT "English "; MARKS(I, 1); " "; GRADE$(I, 1)
1080 LPRINT "Second Language "; MARKS(I, 2); " "; GRADE$(I, 2)
1090 LPRINT "Mathematics "; MARKS(I, 3); " "; GRADE$(I, 3)
1100 LPRINT "Physics "; MARKS(I, 4); " "; GRADE$(I, 4)
1110 LPRINT "Chemistry "; MARKS(I, 5); " "; GRADE$(I, 5)
1120 LPRINT "Biology "; MARKS(I, 6); " "; GRADE$(I, 6)
1130 LPRINT "Geography "; MARKS(I, 7); " "; GRADE$(I, 7)
1140 LPRINT "History/Civics "; MARKS(I, 8); " "; GRADE$(I, 8)
1150 LPRINT "Sixth Subject "; MARKS(I, 9); " "; GRADE$(I, 9)
1160 LPRINT "S.U.P.W "; MARKS(I, 10); " "; GRADE$(I, 10)
1170 LPRINT "-------------------------------------------------------------"
1180 LPRINT "TOTAL MARKS: "; TMARKS(I); " PERCENTAGE : "; PERCENTAGE(I); "%"
1190 LPRINT
1200 IF RESULT(I) = 1 THEN RESULT$ = "Promoted" ELSE RESULT$ = "Detained"
1210 IF DIVISION(I) = 0 THEN DIVISION$ = " No Division Awarded"
1220 IF DIVISION(I) = 1 THEN DIVISION$ = " 1st"
1230 IF DIVISION(I) = 2 THEN DIVISION$ = " 2nd"
1240 IF DIVISION(I) = 3 THEN DIVISION$ = " 3rd"
1250 LPRINT "RESULT: "; RESULT$; " DIVISION:"; DIVISION$
1260 LPRINT
1270 LPRINT
1280 LPRINT "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = "
1290 LPRINT "Division will be awarded on the basis of the percengage of marks"
1300 LPRINT "----------------------------------------------------------------"
1310 LPRINT "1st Division ---> 80% and above"
1320 LPRINT "2nd Division ---> 60% - 79%"
1330 LPRINT "3rd Division ---> Below 60% provided the student passes"
1340 LPRINT "Failed student will not be awarded any division"
1350 LPRINT "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = "
1360 LPRINT
1370 LPRINT
1380 LPRINT "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = "
1390 LPRINT "Grade intervals for the subjects are as follows"
1400 LPRINT "-----------------------------------------------"
1410 LPRINT "90 - 100 ---> 01 50 - 59 ---> 05 10 - 19 ---> 09*"
1420 LPRINT "80 - 89 ---> 02 40 - 49 ---> 06 00 - 09 ---> 10*"
1430 LPRINT "70 - 79 ---> 03 30 - 39 ---> 07*"
1440 LPRINT "60 - 69 ---> 04 20 - 29 ---> 08* * -----> FAIL"
1450 LPRINT "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = "
1460 REM *** Send Form Feed character to the printer to move to the next page ***
1470 LPRINT CHR$(12)
1480 NEXT I

I want to write the same program in JAVA. What are the classes and functions that I will need? The kind of help that I need here is that if you could let me know which classes I need to break up the above BASIC program into and which function should the classes contain. I have picked up the basics of the input/output/process of JAVA and am pretty confident I can write the program (though I *may* just need help!).

Thanks for reading this post. I will be more thankful, if you could give me a postive response.

Regards,
Rupesh Pradhan

Thanks cosi. I will give it a try starting from the template that you have provided.
Regards
Rupesh

I have gotten this far but I am getting a NullPointer Exception.

/**
* To generate examination result
*
* @author (your name)
* @version (a version number or a date)
*/
// Declare packages to be imported
import java.io.*;


public class Result
{
// instance variables
int rollNumber;
String name;
int marks[];
int totalMarks;
float aggPercentage;


// for reading users input
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);


int i;


/**
* Constructor for objects of class Result
*/
public Result()
{
// initialise instance variables
rollNumber = 0;
name = "";
marks = new int[10];
totalMarks = 0;
aggPercentage = 0.0F;


}


/**
* Method to input data
*
* @param  nothing
* @return     nothing
*/
public void inputData()
{
try
{
System.out.println("Enter the information requested:");
System.out.println("--------------------------------");


System.out.print("Roll Number : ");
rollNumber = Integer.parseInt(br.readLine());


System.out.print("Name        : ");
name = br.readLine();


for (i = 0; i < 2; i++)
{
System.out.print("Subject  "+(i+1)+" : ");
marks[i+1] = Integer.parseInt(br.readLine());
} // end of for loop


}  // end of try


catch (IOException ioe)
{
System.out.println("Error is : "+ioe.toString());
} // end of catch


System.out.println("Data that you have just entered");
System.out.println("--------------------------------");
System.out.println("Roll Number : "+ rollNumber);
System.out.println("Name        : "+ name);


for (i = 0; i < 2; i++)
{
System.out.println("Subject  "+(i+1)+" : "+marks[i+1]);
} // end of for loop


} // end of inputData() method


public static void main (String args[])
{
Result Class8C[] = new Result[10];
Class8C[1].inputData();                 // I am gettin NullPointerException here


} // end main


} // end of class

Advice please.
Rupesh

Result Class8C[] = new Result[10];
Class8C[1].inputData(); // I am gettin NullPointerException here

You're constructing an array of 10 results, which makes sense. The error seems to be coming from the inputData method, so let's look more closely there.

public void inputData()
{
try
{
System.out.println("Enter the information requested:");
System.out.println("--------------------------------");

System.out.print("Roll Number : ");
rollNumber = Integer.parseInt(br.readLine());

System.out.print("Name : ");
name = br.readLine();

for (i = 0; i < 2; i++)
{
System.out.print("Subject "+(i+1)+" : ");
marks[i+1] = Integer.parseInt(br.readLine());
} // end of for loop

} // end of try

The first possible problem is at RollNumber = Integer.parseInt(br.readLine());
Looking through your code, I don't see a 'br' which could be part of the problem. Since the 'br' doesn't exist, it would probably be throwing the error (which you seem to have a bunch of. Now I could be missing something, but you also should probably have println instead of print somewhere there, to get a new line of text. Also, I don't see anything that allows you to input, if I remember right you usually can't just type stuff in there.

Hope some of that helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.