avatar
bhau1

Guest 12 4th Nov, 2019

MARKUP 4.41 KB
                                           
                         import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class CourseDemo {

    
public static void main(String[] args) {
        
        
        Course[] inpCourseList = new Course[6];
        
        Scanner sc = new Scanner(System.in);
        
        //For courses
        for(int i = 0;i<6;i++)
        {
            String courseId=sc.nextLine();
            String name=sc.nextLine();
            int duration=sc.nextInt();
            sc.nextLine();
            int noOfLearners=sc.nextInt();
            sc.nextLine();
            double fees = sc.nextDouble();
            sc.nextLine();
            int maxCapacity=sc.nextInt();
            sc.nextLine();
            inpCourseList[i] = new Course(courseId, name, duration, noOfLearners, fees, maxCapacity);
        }
        
        int inpDuration=sc.nextInt();
        
        Course[] cNew=findCourses(inpCourseList,inpDuration);
        if(cNew!=null)
        {
            for(int i=0;i<cNew.length;i++)
            {
                System.out.println(cNew[i].getCourseID()+" "+cNew[i].getName()+" "+cNew[i].getDuration());
            }
        }
        
        System.out.println(updateFees(inpCourseList));
        for(int i=0;i<inpCourseList.length;i++)
        {
            System.out.println(inpCourseList[i].getCourseID()+" "+inpCourseList[i].getName()+" "+inpCourseList[i].getFees());
        }
        
        sc.close();
                
    }//Main methods end here
    
    //Implement the 2 static methods here
public static Course[] findCourses(Course[] courseList,int duration) 
    {
        int c=0;
        for(int i=0;i<courseList.length;i++)
        {
            int vc=(courseList[i].getMaxCapacity()-courseList[i].getNoOfLearners());
             if(courseList[i].getDuration()<duration && vc>10)
             {
                 c++;
             }

        }
        Course[] b=new Course[c];
        for(int i=0;i<courseList.length;i++)
        {
            int vc=(courseList[i].getMaxCapacity()-courseList[i].getNoOfLearners());
             if(courseList[i].getDuration()<duration && vc>10)
             {
                 b[i]=courseList[i];
             }
        }
        return b;
    }


    public static String updateFees(Course[] courseList)
    {
    int count=0;
    for(int i=0;i<courseList.length;i++)
    {
        if(courseList[i].getMaxCapacity()==courseList[i].getNoOfLearners())
        {
            double newFees=(courseList[i].getFees()-courseList[i].getFees()*0.1);
            courseList[i].setFees(newFees);
            count++;

        }

    }
    return "Fees has been updated for 2 number of Courses";
    
    
    }

}

class Course {

    //Implement the bean class here
    private String courseID;
    private String name;
    private int duration;
    private int noOfLearners;
    private double fees;
    private int maxCapacity;

    public Course(String courseID, String name, int duration, int noOfLearners, double fees, int maxCapacity) {
        
        this.courseID = courseID;
        this.name = name;
        this.duration = duration;
        this.noOfLearners = noOfLearners;
        this.fees = fees;
        this.maxCapacity = maxCapacity;
    }
    public String getCourseID() {
        return courseID;
    }
    public void setCourseID(String courseID) {
        this.courseID = courseID;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getDuration() {
        return duration;
    }
    public void setDuration(int duration) {
        this.duration = duration;
    }
    public int getNoOfLearners() {
        return noOfLearners;
    }
    public void setNoOfLearners(int noOfLearners) {
        this.noOfLearners = noOfLearners;
    }
    public double getFees() {
        return fees;
    }
    public void setFees(double fees) {
        this.fees = fees;
    }
    public int getMaxCapacity() {
        return maxCapacity;
    }
    public void setMaxCapacity(int maxCapacity) {
        this.maxCapacity = maxCapacity;
    }
    
}
                      
                                       
To share this paste please copy this url and send to your friends
RAW Paste Data