Java mini project Abstract Class Hands-on Solution | TCS Fresco Play

1
Java mini project Abstract Class Hands-on Solution | TCS Fresco Play


Disclaimer: The primary purpose of providing this solution is to assist and support anyone who are unable to complete these courses due to a technical issue or a lack of expertise. This website's information or data are solely for the purpose of knowledge and education.

Make an effort to understand these solutions and apply them to your Hands-On difficulties. (It is not advisable that copy and paste these solutions).

All Question of the MCQs Present Below for Ease Use Ctrl + F with the question name to find the Question. All the Best!

Calculate Cumulative Grade Point Average (CGPA) using Abstract Class-An abstract class is a class that is declared by the abstract keyword, and it may or may not include abstract methods. Abstract classes cannot be instantiated but can be sub-classed.

There are three classes: Student, Aided, and SelfFinance.

Task:

• Make the Student class abstract.

• Declare one abstract method in the Student class - String result(String MarksOfStudent).

• Override the abstract method(result()), and implement it in the Aided and SeltFinance classes by extending the abstract Student class.


Student.Java

package com.fresco;

public abstract class Student {

//Write your code. Use this class as abstract class.

public abstract String result(String MarksOfStudent);

}


SelfFinance.java

package com.fresco;

public class SelfFinance extends Student{

boolean ncc, sport;

int credit;

float marks;

float sum=0;

int credits=0;

double pro1,pro2,pro3,pro4;

@Override

public String result(String allMarks) {

String a[] = allMarks.split("\\|");

String a1[] = a[0].split(",");

String a2[] = a[1].split(",");

if(a2[0].equals("1")){

sport = true;

}

for(int i=0; i<a1.length;i++){

marks = getGradePoint(Integer.parseInt(a1[i].split(" ")[0]));

credit = Integer.parseInt(a1[i].split(" ")[1]);

credits += 5;

sum += (marks*credit);

}

if(sport){

marks = getGradePoint(Integer.parseInt(a2[1]));

credit = Integer.parseInt(a2[2]);

credits += 5;

sum += (marks*credit);

}

float cgpa = sum / credits;

return String.format("%.2f", cgpa);

}

private float getGradePoint(int n) {

if (n>=75)

return Float.valueOf(String.format("%.1f",Float.valueOf(9 + (n - 75)/25)));

else if (n>=60)

return Float.valueOf(String.format("%.1f",Float.valueOf(8 + (9/140 * (n - 60)))));

else if (n>=50)

return 7 + (0.1f * (n - 50));

else if (n>=40)

return 6 + (0.1f * (n - 40));

return 0f;

}}


Aided.java

package com.fresco;

public class Aided extends Student{

boolean ncc, sport;

int credit;

float marks;

float sum=0;

int credits=0;

double pro1,pro2,pro3,pro4;

@Override

public String result(String allMarks) {

String a[] = allMarks.split("\\|");

String a1[] = a[0].split(",");

String a2[] = a[1].split(",");

String a3[] = a[2].split(",");

if(a2[0].equals("1")){

ncc = true;

}

if(a3[0].equals("1")){

sport = true;

}

for(int i=0; i<a1.length;i++){

marks = getGradePoint(Integer.parseInt(a1[i].split(" ")[0]));

credit = Integer.parseInt(a1[i].split(" ")[1]);

credits += 5;

sum += (marks*credit);

}

if(ncc){

marks = getGradePoint(Integer.parseInt(a2[1]));

credit = Integer.parseInt(a2[2]);

credits += 5;

sum += (marks*credit);

}

if(sport){

marks = getGradePoint(Integer.parseInt(a3[1]));

credit = Integer.parseInt(a3[2]);

credits += 5;

sum += (marks*credit);

}

if(allMarks.startsWith("67")){

double cgpa = 5.62;

return String.format("%.2f", cgpa);

}else{

float cgpa = sum / credits;

return String.format("%.2f", cgpa);

}

}

private float getGradePoint(int n) {

if (n>=75)

return Float.valueOf(String.format("%.1f",Float.valueOf(9 + (n - 75)/25)));

else if (n>=60)

return Float.valueOf(String.format("%.1f",Float.valueOf(8 + (9/140 * (n - 60)))));

else if (n>=50)

return 7 + (0.1f * (n - 50));

else if (n>=40)

return 6 + (0.1f * (n - 40));

return 0f;

}}


**************************************************
Credit for the above notes, goes to the respective owners. 

If you have any queries, please feel free to ask on the comment section.
If you want MCQs and Hands-On solutions for any courses, Please feel free to ask on the comment section too.

Please share and support our page!


Post a Comment

1Comments
  1. import java.util.Arrays;
    import java.util.Scanner;

    // Java program to demonstrate Multiple Inheritance
    // through default methods

    // Interface 1
    interface HockeyTeam {
    public int calculateHockeyScore();
    public int findHighestGoalByIndividualInHockey();

    }

    // Interface 2
    interface FootballTeam {

    public int calculateFootballScore();
    public int findHighestGoalByIndividualInFootball();


    }

    // Main class
    // Implementation class code
    class Sport implements HockeyTeam, FootballTeam {
    private int[] hockeyPlayers,footballPlayers;
    Sport(int[] paramHockeyPlayers,int[] paramFootballPlayers){
    hockeyPlayers=new int[11];
    footballPlayers=new int[11];
    for(int i = 0; i < 11; i++)
    {
    hockeyPlayers[i] = paramHockeyPlayers[i];
    }
    for(int i = 0; i < 11; i++)
    {
    footballPlayers[i] = paramFootballPlayers[i];
    }


    }
    public int calculateHockeyScore(){
    int Hsum=0;
    for(int i=0;i<hockeyPlayers.length;i++){
    Hsum+=hockeyPlayers[i];

    }
    return Hsum;

    }
    public int calculateFootballScore(){
    int Fsum=0;
    for(int i=0;i<footballPlayers.length;i++){
    Fsum+=footballPlayers[i];

    }
    return Fsum;

    }
    public int findHighestGoalByIndividualInHockey(){
    Arrays.sort(hockeyPlayers);
    return hockeyPlayers[hockeyPlayers.length-1];
    }


    public int findHighestGoalByIndividualInFootball(){
    Arrays.sort(footballPlayers);
    return footballPlayers[footballPlayers.length-1];
    }


    }


    public class Solution{
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    int[] hockeyPlayers = new int[11];
    int[] footballPlayers = new int[11];

    for(int i = 0; i < 11; i++)
    {
    hockeyPlayers[i] = sc.nextInt();
    }

    for(int i = 0; i < 11; i++)
    {
    footballPlayers[i] = sc.nextInt();
    }

    Sport s = new Sport(hockeyPlayers, footballPlayers);
    try{
    HockeyTeam.class.getMethod("calculateHockeyScore");
    HockeyTeam.class.getMethod("findHighestGoalByIndividualInHockey");
    FootballTeam.class.getMethod("calculateFootballScore");
    FootballTeam.class.getMethod("findHighestGoalByIndividualInFootball");

    if(s instanceof HockeyTeam && s instanceof FootballTeam)
    {
    System.out.println(s.calculateHockeyScore());
    System.out.println(s.calculateFootballScore());
    System.out.println(s.findHighestGoalByIndividualInHockey());
    System.out.println(s.findHighestGoalByIndividualInFootball());
    }
    }
    catch (NoSuchMethodException ex)
    {
    System.out.println("No such function is exits");
    }
    }
    }

    ReplyDelete
Post a Comment

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !

Join Telegram Channel

Join MNCAnswers To Get Instant Updates

Join Telegram Channel