Menu
Question Index
...


Write a program to convert from section to comma delimited format.

Input (Section object) Output (Delimited Format String)(New lines are shown as $ for display purpose)
sectionName = MPC
classTeacher = Suraj
numberOfStudents = 2
1st Student : Raju : 1 : 98 : 76.5 : M
2nd Student : Mohini : 2 : 88 : 92.5 : F
MPC,Suraj,2$Raju,1,98,76.5,M$Mohini,2,88,92.5,F$
sectionName = BiPC
classTeacher = 'Rama S'
numberOfStudents = 3
1st Student : Mohit : 1 : 67 : 96.5: M
2nd Student :Kavya, 2, 88, 92.5, F
3rd Student : Sandhya :3 :98 :92.5 : F
BiPC,Rama S,3$Mohit,1,67,96.5,M$Kavya,2,88,92.5,F$Sandhya,3,98,92.5,F$
sectionName = CSE
classTeacher = 'Lavanya M'
numberOfStudents = 1
1st Student : Ashok: 1 : 89 : 76.5 : M
CSE,Lavanya M,1$Ashok,1,89,76.5,M$

class ConvertSectionToDelimitedFormat

{    public static void main(String s[])
    {
        Section section = new Section("SSC", "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("Delimited Format is : " + convertToDelimitedFormat(section));

    }


public static String convertToDelimitedFormat(Section section) {
String result = null;
//Write code here to convert Section object to delimited format.
return result;
}
}
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);
}
}

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 delimitedFormat() {
//Write code here to get the delimited format and return t.
}
}

Doubts

Problems

Topic: Java Formatter Methods

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App