Write the code of a class named EXAM with following description
Private Members;
1. exmCode of type string, 6 characters.
2. exmDescription of type string, 40 characters.
3. noCandidate of type integer.
4. centersReqd (number of centers required) of type integer.
5. A member function CALCNTR( ) to calculate and return the number of
centers as (noCandidates/100+1).
Public Members;
1. A function SCHEDULE( ) to allow user to enter values for exmCode,
xmDescription, noCandidate and call function CALCNTR( ) to calculate the
number of centers.
2. A function DISPXM( ) to allow user to view the content of all the member data.
(The functions should be prototyped within the class and their definitions placed
outside the class)
import java.io.IOException;
import java.util.Scanner;
public class EXAM {
private String exmCode;
private String exmDescription;
private int noCandidate;
private int centersReqd;
private int CALCNTR(){
this.centersReqd = this.noCandidate / 100 + 1;
return this.centersReqd;
}
public void SCHEDULE() throws IOException {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter Exam Code: ");
char[] charactersExmCode = new char[6];
String str1 = scanner.nextLine();
for (int i = 0; i < 6; i++){
charactersExmCode[i] = str1.charAt(i);
}
this.exmCode = String.valueOf(charactersExmCode);
System.out.print("Enter Exam Description: ");
char[] charactersExmDescription = new char[40];
String str2 = scanner.nextLine();
for (int i = 0; i < 40; i++){
charactersExmDescription[i] = str2.charAt(i);
}
this.exmDescription = String.valueOf(charactersExmDescription);
System.out.print("Enter number of value noCandidate: ");
this.noCandidate = scanner.nextInt();
CALCNTR();
}
public void DISPXM(){
System.out.println("Exam Code: " + this.exmCode);
System.out.println("Exam Description: " + this.exmDescription);
System.out.println("Number of value noCandidate: " + this.noCandidate);
System.out.println("Number of centers required: " + CALCNTR());
}
public static void main(String args[]) throws IOException {
EXAM exam = new EXAM();
exam.SCHEDULE();
exam.DISPXM();
}
}
Comments
Leave a comment