Java mini project Abstract Class Hands-on Solution | TCS Fresco Play
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!
1 comment
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++){
…