0% found this document useful (0 votes)
807 views31 pages

Exp 07

The document describes an application for calculating stipends for post-graduate students. It defines a Student class with methods to set student ID and marks, get base stipend amount, and calculate total stipend which is increased based on performance. It creates two Student objects, sets their IDs and marks, and prints their total stipends.

Uploaded by

Shubham Bayas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
807 views31 pages

Exp 07

The document describes an application for calculating stipends for post-graduate students. It defines a Student class with methods to set student ID and marks, get base stipend amount, and calculate total stipend which is increased based on performance. It creates two Student objects, sets their IDs and marks, and prints their total stipends.

Uploaded by

Shubham Bayas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 31

Name : Shubham Bayas

Roll No : 66

Div : B

Experiment No : 7

Problem Statement 1

An educational institution provides stipends for post-graduate students every year.


For calculating the stipend, the institution has fixed a base amount of $100 which is
provided to all the students. The students who perform exceptionally well during
the academics get an extra amount based on their performance.

class Student

private final int STIPEND=100;

private int studentId;

private int aggregateMarks;

public int getStudentId()

return studentId;

public void setStudentId(int studentId)

this.studentId=studentId;

public int getAggregateMarks()

return aggregateMarks;

public void setAggregateMarks(int aggregateMarks)


{

this.aggregateMarks=aggregateMarks;

public int getSTIPEND()

return STIPEND;

public double calculateTotalStipend()

if(aggregateMarks>=85 && aggregateMarks<90)

return STIPEND+10;

else if(aggregateMarks>=90 && aggregateMarks<95)

return STIPEND+15;

else if(aggregateMarks>=95 && aggregateMarks<=100)

return STIPEND+20;

else

return STIPEND;

}
class Tester {

public static void main(String[] args) {

Student student1 = new Student();

student1.setStudentId(1212);

student1.setAggregateMarks(93);

double totalStipend = student1.calculateTotalStipend();

System.out.println("The final stipend of " + student1.getStudentId()+" is $" +


totalStipend);

Student student2 = new Student();

student2.setStudentId(1222);

student2.setAggregateMarks(84);

totalStipend = student2.calculateTotalStipend();

System.out.println("The final stipend of " + student2.getStudentId()+" is $" +


totalStipend);

}
Problem Statement 2

An e-commerce company has made it mandatory for all the customers to pay tax
on every purchase and also for all the sellers to pay a certain amount of tax based
on their location. You need to help the e-commerce company by implementing an
application for paying tax based on the class diagram and description given below.

interface tax

public double calculateTax(double price);

class PurchaseDetails implements tax

private String purchaseId;

private String paymentType;

private double taxPercentage;

public PurchaseDetails(String purchaseId,String paymentType)

this.purchaseId=purchaseId;

this.paymentType=paymentType;

public String getPurchaseId()

{
return purchaseId;

public void setPurchaseId(String purchaseId)

this.purchaseId=purchaseId;

public String getPaymentType()

return paymentType;

public void setPaymentType(String paymentType)

this.paymentType=paymentType;

public double getTaxPercentage()

return taxPercentage;

public void setTaxPercentage(double taxPercentage)

this.taxPercentage=taxPercentage;

public double calculateTax(double price)

if(this.paymentType.equals("Debit"))
{

this.taxPercentage=2;

else if(this.paymentType.equals("Credit"))

this.taxPercentage=3;

else

this.taxPercentage=4;

return price+(price*this.taxPercentage/100);

class Seller implements tax

private String location;

private double taxPercentage;

public Seller(String location)

this.location=location;

public String getLocation()

return location;
}

public void setLocation(String location)

this.location=location;

public double getTaxPercentage()

return taxPercentage;

public void setTaxPercentage(double taxPercentage)

this.taxPercentage=taxPercentage;

public double calculateTax(double price)

if(this.location.equals("Middle east"))

this.taxPercentage=15;

else if(this.location.equals("Europe"))

this.taxPercentage=25;

else if(this.location.equals("Canada"))

{
this.taxPercentage=22;

else

this.taxPercentage=12;

return price+(price*this.taxPercentage/100);

class Tester{

public static void main(String args[]) {

System.out.println("Purchase Details\n***************");

PurchaseDetails purchaseDetails = new PurchaseDetails("P1001","Credit Card");

System.out.println("Total purchase amount: " +


Math.round(purchaseDetails.calculateTax(100)*100)/100.0);

System.out.println("Tax percentage: "+purchaseDetails.getTaxPercentage());

System.out.println("Seller Details\n***************");

Seller seller = new Seller("Canada");

System.out.println("Tax to be paid by the seller: " +


Math.round(seller.calculateTax(100)*100)/100.0);

System.out.println("Tax percentage: "+seller.getTaxPercentage());


//Create more objects for testing your code

Problem statement 3

IndianValley University provides education in different courses and has more than
200 faculties working in various departments. The university wants to calculate the
annual salary for each faculty member. Basic salary is provided for all faculties and
an additional component is paid based on their designation or qualification. You
need to help the university in creating an application for them by implementing the
classes based on the class diagram and description given below.

class Faculty

private String name;

private float basicSalary;

private float bonusPercentage;

private float carAllowancePercentage;


public Faculty(String name,float basicSalary)

this.name=name;

this.basicSalary=basicSalary;

this.bonusPercentage=4f;

this.carAllowancePercentage=2.5f;

public String getName()

return name;

public void setName(String name)

this.name=name;

public float getBasicSalary()

return basicSalary;

public void setBasicSalary(float basicSalary)

this.basicSalary=basicSalary;

public float getBonusPercentage()

{
return bonusPercentage;

public void setBonusPercentage(float bonusPercentage)

this.bonusPercentage=bonusPercentage;

public float getCarAllowancePercentage()

return carAllowancePercentage;

public void setCarAllowancePercentage(float carAllowance)

this.carAllowancePercentage=carAllowancePercentage;

double calculateSalary()

double salary=basicSalary+basicSalary*0.04f+basicSalary*0.025f;

return salary;

class OfficeStaff extends Faculty

{
private String designation;

public OfficeStaff(String name,float basicSalary,String designation)

super(name,basicSalary);

this.designation=designation;

public String getDesignation()

return designation;

public void setDesignation(String designation)

this.designation=designation;

public double calculateSalary()

double sal=super.calculateSalary();

if(this.designation.equals("Accountant")) return sal+10000.0;

else if(this.designation.equals("Clerk")) return sal+7000.0;

else if(this.designation.equals("peon")) return sal+4500.0;

else

return sal;

}
class Teacher extends Faculty

private String qualification;

public Teacher(String name,float basicSalary,String qualification)

super(name,basicSalary);

this.qualification=qualification;

public String getQualification()

return qualification;

public void setDesignation(String qualification)

this.qualification=qualification;

public double calculateSalary()

double sal=super.calculateSalary();

if(this.qualification.equals("Doctaral")) return sal+20000.0;

else if(this.qualification.equals("Masters")) return sal+18000.0;

else if(this.qualification.equals("Bachelors")) return sal+15550.0;

else if(this.qualification.equals("Associate")) return sal+10000.0;

else return sal;


}

class Tester

public static void main(String[] args)

Teacher teacher = new Teacher("Caroline", 30500f, "Masters");

OfficeStaff officeStaff = new OfficeStaff("James", 24000f, "Accountant");

System.out.println("Teacher Details\n***************");

System.out.println("Name: "+teacher.getName());

System.out.println("Qualification: "+teacher.getQualification());

System.out.println("Total salary: $" +


Math.round(teacher.calculateSalary()*100)/100.0);

System.out.println();

System.out.println("Office Staff Details\n***************");

System.out.println("Name: "+officeStaff.getName());

System.out.println("Designation: "+officeStaff.getDesignation());

System.out.println("Total salary: $" +


Math.round(officeStaff.calculateSalary()*100)/100.0);

}
Problem statement 4

An e-commerce company wants to start a payment service application for allowing


payments using debit card and credit card. You need to help them in creating the
application by implementing the classes based on the class diagram and description
given below.

abstract class Payment


{
    private int customerId;
    protected String paymentId;
    protected double serviceTaxPercentage;
    public Payment(int customerId)
    {
        this.customerId=customerId;
    }
    public int getCustomerId()
    {
        return customerId;
    }
    public void setCustomerId(int customerId)
    {
        this.customerId=customerId;
    }
    public String getPaymentId()
    {
        return paymentId;
    }
    public void setPaymentId(String paymentId)
    {
        this.paymentId=paymentId;
    }
    public double getServiceTaxPercentage()
    {
        return serviceTaxPercentage;
    }
    public void setServiceTaxPercentage(double serviceTaxPercentage)
    {
        this.serviceTaxPercentage=serviceTaxPercentage;
    }
    public abstract double payBill(double amount);

class DebitCardPayment extends Payment


{
    //Implement your code here
    private static int counter=1000;
    private double discountPercentage;
    public DebitCardPayment(int customerId)
    {
        super(customerId);
        counter++;
        paymentId="D"+counter;

       
    }
    public static  int getCounter()
    {
        return counter;
    }
    public static void setCounter(int counter)
    {
        DebitCardPayment.counter=counter;
    }
    public double getDiscountPercentage()
    {
        return discountPercentage;
    }
    public void setDiscountPercentage(double discountPercentage)
    {
        this.discountPercentage=discountPercentage;
    }
    public double payBill(double amount)
    {
        double serviceTaxAmount=0;
        double discountAmount=0;
        if(amount<=500) serviceTaxPercentage=2.5;
        else if(amount >500 && amount<=1000) serviceTaxPercentage=4;
        else if(amount>2000) serviceTaxPercentage=5;

        serviceTaxAmount=amount*serviceTaxPercentage/100;
        if(amount<=500) discountPercentage=1;
        else if(amount >500 && amount<=1000) discountPercentage=2;
        else if(amount>2000) discountPercentage=3;

        discountAmount=amount*discountPercentage/100;
        return amount+serviceTaxAmount-discountAmount;
    }
}

class CreditCardPayment extends Payment


{
    //Implement your code here
    private static int counter=1000;
    public CreditCardPayment(int customerId)
    {
        super(customerId);
        counter++;
        paymentId="C"+counter;
    }
    public static int getCounter()
    {
        return counter;
    }
    public static void setCounter(int counter)
    {
        CreditCardPayment.counter=counter;
    }
    public double payBill(double amount)
    {
        double serviceTaxAmount=0;
        if(amount<=500) serviceTaxPercentage=3;
        else if(amount<=1000) serviceTaxPercentage=5;
        else serviceTaxPercentage=6;

        serviceTaxAmount=amount*serviceTaxPercentage/100;
        return amount*serviceTaxAmount;
    }
}

class Tester{
    public static void main(String args[]){
        DebitCardPayment debitCardPayment = new DebitCardPayment(101);
        double billAmount=Math.round(debitCardPayment.payBill(500)*100)/100.0;
        System.out.println("Customer Id: " + debitCardPayment.getCustomerId());
        System.out.println("Payment Id: " + debitCardPayment.getPaymentId());
        System.out.println("Service tax percentage: " +
debitCardPayment.getServiceTaxPercentage());
        System.out.println("Discount percentage: " +
debitCardPayment.getDiscountPercentage());
        System.out.println("Total bill amount: " + billAmount);
       
        CreditCardPayment creditCardPayment = new CreditCardPayment(102);
        billAmount=Math.round(creditCardPayment.payBill(1000)*100)/100.0;
        System.out.println("Customer Id: " + creditCardPayment.getCustomerId());
        System.out.println("Payment Id: " + creditCardPayment.getPaymentId());
        System.out.println("Service tax percentage: " +
creditCardPayment.getServiceTaxPercentage());
        System.out.println("Total bill amount: " + billAmount);
    }
}
Problem Statement 5

A college cultural event "Show Your Talent" is being conducted and the organizing
committee has decided to open online registration for the same. The students can
participate in solo events as well as team events. You need to develop an
application for the online registration by implementing the classes based on the
class diagram and description given below.

class Event
{
    //Implement your code here
    private String eventName;
    private String participantName;
    private double registrationFee;
    public Event(String eventName,String participantName)
    {
        this.eventName=eventName;
        this.participantName=participantName;
    }
    public String getEventName()
    {
        return eventName;
    }
    public void setEventName(String eventName)
    {
        this.eventName=eventName;
    }
    public String getParticipantName()
    {
        return participantName;
    }
    public void setParticipantName(String participantName)
    {
        this.participantName=participantName;
    }
    public double getRegistrationFee()
    {
       
        return registrationFee;
    }
    public void setRegistrationFee(double registrationFee)
    {
        this.registrationFee=registrationFee;
    }
    public void registerEvent()
    {
        if(eventName.equals("Singing")) registrationFee=8;
        else if(eventName.equals("Dancing")) registrationFee=10;
        else if(eventName.equals("DigitalArt")) registrationFee=12;
        else if(eventName.equals("Acting")) registrationFee=15;
        else registrationFee=0;
    }
}

class SoloEvent extends Event


{
    //Implement your code here
    private int participantNo;
    public SoloEvent(String eventName,String participantName,int participantNo)
    {
        super(eventName, participantName);
        this.participantNo=participantNo;

    }
    public int getParticipantNo()
    {
        return participantNo;
    }
    public void  setParticipantNo(int participantNo)
    {
        this.participantNo=participantNo;
    }
    public void registerEvent()
    {
        super.registerEvent();
    }

class TeamEvent extends Event


{
    //Implement your code here
    private int noOfParticipants;
    private int teamNo;
    public TeamEvent(String eventName,String participantName,int
noOfParticipants,int teamNo)
    {
        super(eventName,participantName);
        this.noOfParticipants=noOfParticipants;
        this.teamNo= teamNo;
    }
    public int getNoOfParticipants()
    {
        return noOfParticipants;
    }
    public void setNoOfParticipants(int noOfParticipants)
    {
        this.noOfParticipants=noOfParticipants;
    }
    public int getTeamNo()
    {
        return teamNo;
    }
    public void setTeamNo(int teamNo)
    {
        this.teamNo=teamNo;
    }
    public void registerEvent()
    {
        int baseFee=0;
        if(super.getEventName().equals("Singing")) baseFee=4;
        else if(super.getEventName().equals("Dancing")) baseFee=6;
        else if(super.getEventName().equals("DigitalArt")) baseFee=8;
        else if(super.getEventName().equals("Acting")) baseFee=10;
        else super.setRegistrationFee(0);

        super.setRegistrationFee(this.noOfParticipants*baseFee);

       

       

    }
}

class Tester {

      public static void main(String[] args) {


           
        SoloEvent soloEvent = new SoloEvent("Dancing", "Jacob", 1);
        soloEvent.registerEvent();
        if (soloEvent.getRegistrationFee() != 0) {
            System.out.println("Thank You " + soloEvent.getParticipantName()
                    + " for your participation! Your registration fee is $" +
soloEvent.getRegistrationFee());
            System.out.println("Your participant number is " +
soloEvent.getParticipantNo());

        } else {
            System.out.println("Please enter a valid event");
        }

        System.out.println();
        TeamEvent teamEvent = new TeamEvent("Acting", "Serena", 5, 1);
        teamEvent.registerEvent();
        if (teamEvent.getRegistrationFee() != 0) {
            System.out.println("Thank You " + teamEvent.getParticipantName()
                    + " for your participation! Your registration fee is $" +
teamEvent.getRegistrationFee());
            System.out.println("Your team number is " + teamEvent.getTeamNo());
        } else {
            System.out.println("Please enter a valid event");
        }
    }
}

Problem statement 6

Implement the following class based on the class diagram and description given be

class Circle
{
    private final double PI=3.14;
    private double diameter;
    private double circumference;
    private double area;
    public Circle(double diameter)
    {
         this.diameter=diameter;
    }
    public double getDiameter()
    {
        return diameter;
    }
    public void setDiameter(double diameter)
    {
        this.diameter=diameter;
    }
    public double getCircumference()
    {
        return circumference;
    }
    public void setCircumference(double circumference)
    {
        this.circumference=circumference;
    }
    public double getArea()
    {
        return area;
    }
    public void setArea(double area)
    {
        this.area=area;
    }
   
    public void calculateCircumference()
    {
          this.circumference=this.PI*this.diameter;
       
    }
    public void calculateArea()
    {
        this.area=this.PI*Math.pow(diameter/2,2);
    }

class Tester{
     
    public static void main(String[] args) {
           
        Circle circle1 = new Circle(10.2);
        Circle circle2 = new Circle(5.7);

        //Create more objects of Circle class and add to the array given below
for testing your code    
        Circle[] circles = {circle1, circle2};
           
        for (Circle circle : circles) {
                 
            circle.calculateCircumference();
            circle.calculateArea();
                 
            System.out.println("Diameter of the circle is
"+circle.getDiameter());
            System.out.println("Circumference of the circle is " +
Math.round(circle.getCircumference()*100)/100.0);
            System.out.println("Area of the circle is " +
Math.round(circle.getArea()*100)/100.0);
            System.out.println();
        }          
    }
}

Problem statement 7

Happy Mobiles is a mobile manufacturer and they want to increase the rate
of production. So, they have decided to add a feature for easily testing the
compatibility of mobile operating system with generation of cellular network.
You need to help them by creating an application based on the class diagram
and description given below.
interface Testable
{
    //Implement your code here
    public boolean testCompatibility();
}

class Mobile
{
    //Implement your code here
    private String name;
    private String brand;
    private String operatingSystemName;
    private String operatingSystemVersion;
    public Mobile(String name,String brand, String operatingSystemName,String
operatingSystemVersion)
     {
        this.name=name;
        this.brand=brand;
        this.operatingSystemName=operatingSystemName;
        this.operatingSystemVersion=operatingSystemVersion;
     }
     public String getName()
        {
            return name;
        }
        public void setName(String name)
        {
             this.name=name;
        }
        public String getBrand()
        {
            return brand;
        }
        public void setBrand(String brand)
        {
             this.brand=brand;
        }
        public String getOperatingSystemName()
        {
            return operatingSystemName;
        }
        public void setOperatingSystemName(String operatingSystemName)
        {
             this.operatingSystemName=operatingSystemName;
        }
        public String getOperatingSystemVersion()
        {
            return operatingSystemVersion;
        }
        public void setOperatingSystemVersion(String operatingSystemVersion)
        {
             this.operatingSystemVersion=operatingSystemVersion;
        }

class SmartPhone extends Mobile implements Testable


 {
    //Implement your code here
    private String networkGeneration;
    public SmartPhone(String name,String brand, String
operatingSystemName,String operatingSystemVersion,String networkGeneration)
    {
        super(name, brand, operatingSystemName, operatingSystemVersion);
        this.networkGeneration=networkGeneration;
    }
    public String getNetworkGeneration()
    {
        return networkGeneration;
    }
    public void setNetworkGeneration(String networkGeneration)
    {
        this.networkGeneration=networkGeneration;
    }
    public boolean testCompatibility()
    {
        if(super.getOperatingSystemName().equals("Saturn"))
        {
            if(networkGeneration.equals("3G"))
            {
                if(super.getOperatingSystemVersion().equals("1.1") ||
super.getOperatingSystemVersion().equals("1.2") ||
super.getOperatingSystemVersion().equals("1.3"))
                {
                    return true;
                }
            }        
            else if(networkGeneration.equals("4G"))
            {
                if(super.getOperatingSystemVersion().equals("1.1") ||
super.getOperatingSystemVersion().equals("1.2"))
                {
                    return true;
                }
            }  
            else if(networkGeneration.equals("5G"))
            {
                if(super.getOperatingSystemVersion().equals("1.3"))
                {
                    return true;
                }
            }
        }
       
        else if(super.getOperatingSystemName().equals("Gara"))
        {
            if(networkGeneration.equals("3G"))
            {
                if(super.getOperatingSystemVersion().equals("EXRT.1") ||
super.getOperatingSystemVersion().equals("EXRT.2") ||
super.getOperatingSystemVersion().equals("EXRU.1"))
                {
                    return true;
                }
            }        
            else if(networkGeneration.equals("4G"))
            {
                if(super.getOperatingSystemVersion().equals("EXRT.2") ||
super.getOperatingSystemVersion().equals("EXRU.1"))
                {
                    return true;
                }
            }  
            else if(networkGeneration.equals("5G"))
            {
                if(super.getOperatingSystemVersion().equals("EXRU.1"))
                {
                    return true;
                }
            }
        }
        return false;
    }
}
class Tester {
    public static void main(String args[]){
        SmartPhone smartPhone = new SmartPhone("KrillinM20", "Nebula", "Saturn",
"1.3", "5G");
        if(smartPhone.testCompatibility())
            System.out.println("The mobile OS is compatible with the network
generation!");
        else
            System.out.println("The mobile OS is not compatible with the network
generation!");
       
        //Create more objects for testing your code
    }
}

Problem Statement 8

Anchor College offers both graduate and postgraduate programs. The college stores
the names of the students, their test scores and the final result for each student.
Each student has to take 4 tests in total. You need to create an application for the
college by implementing the classes based on the class diagram and description
given below.

abstract class Student


{
    //Implement your code here
    private String studentName;
    private int[] testScores=new int[4];
    private String testResult;
    public Student(String studentName)
    {
        this.studentName=studentName;
    }
    public int[] getTestScores()
    {
        return testScores;
    }
    public void setTestScore(int testNumber,int testScore)
    {
        this.testScores[testNumber]=testScore;
    }
    public String getStudentName()
    {
        return studentName;
    }
    public void setStudentName(String studentName)
    {
        this.studentName=studentName;
    }
    public String getTestResult()
    {
        return testResult;
    }
    public void setTestResult(String testResult)
    {
        this.testResult=testResult;
    }
    public abstract void generateResult();
}

class UndergraduateStudent extends Student


{
    //Implment your code here
    public UndergraduateStudent(String studentName)
    {
        super(studentName);
    }
    public void generateResult()
    {
        int[] testScores=new int[4];
        int sum=0,avg;
       testScores=getTestScores();
       for(int i=0;i<testScores.length;i++)
       {
            sum=sum+testScores[i];
       }
       avg=sum/testScores.length;
       if(avg>=60) setTestResult("Pass");
       else setTestResult("Fail");
    }

class GraduateStudent extends Student


{
    //Implment your code here
    public GraduateStudent(String studentName)
    {
        super(studentName);
    }
    public void generateResult()
    {
        int[] testScores=new int[4];
        int sum=0,avg;
       testScores=getTestScores();
       for(int i=0;i<testScores.length;i++)
       {
            sum=sum+testScores[i];
       }
       avg=sum/testScores.length;
       if(avg>=70) setTestResult("Pass");
       else setTestResult("Fail");
    }
}

class Tester {

    public static void main(String[] args) {


        UndergraduateStudent undergraduateStudent = new
UndergraduateStudent("Philip");
        undergraduateStudent.setTestScore(0, 70);
        undergraduateStudent.setTestScore(1, 69);
        undergraduateStudent.setTestScore(2, 71);
        undergraduateStudent.setTestScore(3, 55);
           
        undergraduateStudent.generateResult();
           
        System.out.println("Student name:
"+undergraduateStudent.getStudentName());
        System.out.println("Result: "+undergraduateStudent.getTestResult());
           
        System.out.println();
           
        GraduateStudent graduateStudent = new GraduateStudent("Jerry");
        graduateStudent.setTestScore(0, 70);
        graduateStudent.setTestScore(1, 69);
        graduateStudent.setTestScore(2, 71);
        graduateStudent.setTestScore(3, 55);
           
        graduateStudent.generateResult();
           
        System.out.println("Student name: "+graduateStudent.getStudentName());
        System.out.println("Result : "+graduateStudent.getTestResult());
       
        //Create more objects of the classes for testing your code
    }
}

You might also like