Menu
Question Index
...


Write a program to convert from section to fixed format.

Input (Section object) Output (Fixed Format String)(New lines are shown as $ for display purpose)
sectionName = MPC
classTeacher = 'Srinivas K'
numberOfStudents = 3
1st Student : Raju : 1 : 98 : 76.5 : M
2nd Student : Mohini : 2 : 88 : 92.5 : F
3rd Student : Anand : 3 : 75 : 98.5 : M
MPC            Srinivas K     3 $Raju           1 98 076.50M$Mohini         2 88 092.50F$Anand          3 75 098.50M$
sectionName = BiPC
classTeacher = 'Rama S'
numberOfStudents =2
1st Student : Mohit : 1 : 67 : 96.5: M
2nd Student :Kavya, 2, 88, 92.5, F
BiPC           Rama S         2 $Mohit          1 67 096.50M$Kavya          2 88 092.50F$
sectionName = HEC
classTeacher = 'Lavanya M'
numberOfStudents = 1
1st Student : Ashok: 1 : 89 : 76.5 : M
HEC            Lavanya M      1 $Ashok          1 89 076.50M$

class ConvertSectionToFixedFormat

{    public static void main(String s[])
    {
        Section section = new Section("MPC", "Srinivas K", 3);
        section.addStudent(new Student("Raju", 1, 98, 76.5, 'M'));
        section.addStudent(new Student("Mohini", 2, 88, 92.5, 'F'));
        section.addStudent(new Student("Anand", 3, 75, 98.5, 'M'));
        System.out.println("Fixed length format is : \n" + convertToFixedFormat(section));

    }


public static String convertToFixedFormat(Section section) {
String result = null;
//Write code here to convert Section object to fixed format.
return result;
}

//If required write any other methods here
}
class Section {

String sectionName;
String classTeacher;
int numberOfStudents;
ArrayList<Student> students = new ArrayList<Student>();

public Section(String sectionName, String classTeacher, int numberOfStudents) {
this.sectionName = sectionName;
this.classTeacher = classTeacher;
this.numberOfStudents = numberOfStudents;
}

public void addStudent(Student student) {
students.add(student);
}

public String getAllStudentsInFixedFormat() {
String result = "";
for (int i = 0; i < students.size(); i++) {
result += students.get(i).fixedFormat() + "\n";
}
return result;
}
}

class Student {

String name;
int roll_number;
int marks;
double percentage;
char gender;

public Student(String name, int roll_number, int marks, double percentage, char gender) {
this.name = name;
this.roll_number = roll_number;
this.marks = marks;
this.percentage = percentage;
this.gender = gender;
}

public String fixedFormat() {
String result = "";
//Write code here to get the student details in fixed format
return result;
}
}

Doubts

Problems

Topic: Collection Framework In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App