Download our latest MNC Answers Application at Play Store. Download Now

Classes and Objects, Packages Hands-Ons [Java > Classes and Objects, Packages] | Accenture TFA Training Pre-Learning Modules

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 Hands-On Present Below for Ease Use Ctrl + F with the question name to find the Question. All the Best!

1. Average and Grade Calculation


Path: JAVA/Classes and Objects, Packages/Average and Grade Calculation/Student.java

public class Student

{

    private int id;

    private String name;

    private int marks[];

    private float average;

    private char grade;

    public Student(int a,String b,int[] c)

    {

        id=a;

        name=b;

        marks=c;

    }

    public void setId(int n)

    {

        id=n;

    }

    public int getId()

    {

        return id;

    }

    public void setMarks(int[] marks)

    {

        this.marks=marks;

    }

    public int[] getMarks()

    {

        return marks;

    }

    public void setName(String n)

    {

        name=n;

        

    }

    public String getName()

    {

        return name;

    }

    public void setAverage(float n)

    {

        average=n;

    }

    public float getAverage()

    {

        return average;

    }

    public void setGrade(char n)

    {

        grade=n;

    }

    public char getGrade()

    {

        return grade;

    }

    public void calculateAvg()

    {

        float a1=0.0F;

        for(int a=0;a<this.getMarks().length;a++)

        {

            a1=a1+this.marks[a];

        }

        this.setAverage(a1/getMarks().length);

    }

    public void findGrade()

    {

        int min=this.marks[0];

        for(int b=0;b<this.getMarks().length;b++)

        {

            if(this.marks[b]<min) 

                {

                    min=this.marks[b];

                }

        }

        if(min<50)

        {

            this.setGrade('F');

        }

        else if(this.getAverage()>=80 && this.getAverage()<=100)

        {

            this.setGrade('O');

        }

        else

        {

            this.setGrade('A');

        }

    }

}


Path: JAVA/Classes and Objects, Packages/Average and Grade Calculation/StudentMain.java

import java.util.Scanner;

public class StudentMain

{

    public static void main(String[] args)

    {

        Student s=getStudentDetails();

        s.calculateAvg();

        s.findGrade();

        System.out.println("Id:" +s.getId());

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

        System.out.println("Average:"+String.format("%.2f",s.getAverage()));

        System.out.println("Grade:" +s.getGrade());

    }

    public static Student getStudentDetails()

    {

        Scanner sc=new Scanner(System.in);

        System.out.println("Enter the id:");

        int id=Integer.parseInt(sc.nextLine());

        String name=sc.nextLine();

        System.out.println("Enter the no of subjects:");

        int n=sc.nextInt();

        if(n<=0)

        {

            while(n<=0)

            {

                System.out.println("Invalid number of subject");

                System.out.println("Enter the no of subjects");

                n=sc.nextInt();

            }

        }

        int arr[]=new int[n];

        for(int a=0;a<n;a++)

        {

            System.out.println("Enter mark for subject "+(a+1)+":");

            int b=sc.nextInt();

            if(b<0||b>100)

            {

                System.out.println("Invalid Mark");

                System.out.println("Enter mark for subject "+(a+1)+":");

                b=sc.nextInt();

            }

            arr[a]=b;

        }

        Student obj=new Student(id,name,arr);

        obj.setId(id);

        obj.setName(name);

        return obj;

    }

}



2. Bank Account Details

Path: JAVA/Classes and Objects, Packages/BankAccountDetails/Account.java

public class Account

{

    private int accountId;

    private String accountType;

    private int balance;

    public int getAccountId()

    {

        return accountId;

        

    }

    public String getAccountType()

    {

        return accountType;

    }

    public int getBalance()

    {

        return balance;

        

    }

    public void setAccountId(int id)

    {

        accountId=id;

    }

    public void setAccountType(String s)

    {

        accountType=s;

    }

    public void setBalance(int b)

    {

        balance=b;

    }

    public boolean withdraw(int w)

    {

        if(getBalance()<w)

        {

            System.out.println("Sorry!!! No enough balance");

            return false;

        }

        else

        {

            System.out.println("Balance amount after withdraw: "+(getBalance()-w));

            return true;

        }

    }

}


Path: JAVA/Classes and Objects, Packages/BankAccountDetails/AccountDetails.java

import java.util.*;

public class AccountDetails

{

    public static Account getAccountDetails()

    {

        Account acc=new Account();

        Scanner sc=new Scanner(System.in);

        System.out.println("Enter account id: ");

        acc.setAccountId(sc.nextInt());

        sc.nextLine();

        System.out.println("Enter account type: ");

        acc.setAccountType(sc.nextLine());

        int b;

        do

        {

        System.out.println("Enter Balance");

        acc.setBalance(sc.nextInt());

        b=acc.getBalance();

        if(b<=0)

        System.out.println("Balance should be positive");

        }

        while(b<=0);

        return acc;

    }

    public static int getWithdrawAmount()

    {

        Scanner sc=new Scanner(System.in);

        int w;

        do

        {

            System.out.println("Enter amount to be withdrawn:");

            w=sc.nextInt();

            if(w<=0)

            System.out.println("Amount should be positive");

        }

        while(w<=0);

        return w;

    }

    public static void main(String[] args)

    {

        Account accObj=new Account();

        accObj=getAccountDetails();

        int c=getWithdrawAmount();

        accObj.withdraw(c);

    }

}



3. Book Detail

Path: JAVA/Classes and Objects, Packages/Book Detail/Book.java

public class Book

{

    private String bookName;

    private int bookPrice;

    private String authorName;

    

    public void setBookName(String bookName)

    {

        this.bookName=bookName;

    }

    

    public String getBookName()

    {

        return this.bookName;

    }

    

    public void setBookPrice(int bookPrice)

    {

        this.bookPrice=bookPrice;

    }

    

    public int getBookPrice()

    {

        return this.bookPrice;

    }

    

    public void setAuthorName(String authorName)

    {

        this.authorName=authorName;

    }

    

    public String getAuthorName()

    {

        return this.authorName;

    }

}


Path: JAVA/Classes and Objects, Packages/Book Detail/TestBook.java

import java.util.Scanner;

public class TestBook

{

    public static void main (String[] args) {

        Scanner sc=new Scanner(System.in);

        

        System.out.println("Enter the Book name:");

        String bookname=sc.nextLine();

        

        System.out.println("Enter the price:");

        int price=sc.nextInt();

        sc.nextLine();

        

        System.out.println("Enter the Author name:");

        String authorname=sc.nextLine();

        

        Book obj=new Book();

        obj.setBookName(bookname);

        obj.setBookPrice(price);

        obj.setAuthorName(authorname);

        System.out.println("Book Details");

        System.out.println("Book Name :"+obj.getBookName());

        System.out.println("Book Price :"+obj.getBookPrice());

        System.out.println("Author Name :"+obj.getAuthorName());

    }

}


4. Calculate Expiry Date - Use Calendar

Path: JAVA/Classes and Objects, Packages/Calculate Expiry Date - Use Calendar/Main.java

import java.util.Scanner;

import java.util.Calendar;

import java.util.Date;

import java.text.SimpleDateFormat;

import java.text.ParseException;

public class Main {


public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

String d=sc.next();

int n=sc.nextInt();

SimpleDateFormat sdf=new SimpleDateFormat("dd/MM/yyyy");

    //FILL THE CODE

    try{

        Date date=sdf.parse(d);

        Calendar c= Calendar.getInstance();

        c.setTime(date);

        c.add(Calendar.MONTH, n);

        Date expiry=c.getTime();

        String strDate=sdf.format(expiry);

        System.out.println(strDate);

    }

    catch(ParseException e){

        System.out.println("dn");

    }

}

}


5. Calculate Years of Experience

Path: JAVA/Classes and Objects, Packages/Calculate Years of Experience/Main.java

import java.util.*;

import java.text.*;

public class Main 

{

public static void main(String[] args) 

{

Scanner sc=new Scanner(System.in);

String join = sc.next();

SimpleDateFormat sdf=new SimpleDateFormat("dd/MM/yyyy");

try 

{ sdf.setLenient(false); 

Date d1 = sdf.parse(join); 

Date d2 = new Date(); 

long diff = d2.getTime() - d1.getTime(); 

long l1 = (24*60*60*1000); 

long l = l1*365; 

long year=diff/l; 

System.out.println(year+" years"); 

catch(ParseException e) {} 

}

}


6. Call Details

Path: JAVA/Classes and Objects, Packages/Call Details/Call Details/Call.java

public class Call{

    private int callId;

    private long calledNumber;

    private float duration;

    

    public void Call()

    {


    }

    

    public void parseData(String data)

    {

        this.callId=Integer.parseInt(data.substring(0,3));

        this.calledNumber=Long.parseLong(data.substring(4,14));

        this.duration=Float.parseFloat(data.substring(15));

    }

    

    public int getCallId()

    {

        return this.callId;

    }

    

    public long getCalledNumber()

    {

        return this.calledNumber;

    }

    

    public float getDuration()

    {

        return this.duration;

    }

}


Path: JAVA/Classes and Objects, Packages/Call Details/Call Details/Main.java

import java.util.*;

public class Main{

    public static void main (String[] args) {

        

        Scanner sc=new Scanner(System.in);

        Call obj=new Call();

        System.out.println("Enter the call details:");

        String data=sc.nextLine();

        

        obj.parseData(data);

        System.out.println("Call id:"+obj.getCallId());

        System.out.println("Called number:"+obj.getCalledNumber());

        System.out.println("Duration:"+obj.getDuration());

    }

}



7. Date Validation - Use Simple Date Format

Path: JAVA/Classes and Objects, Packages/Date Validation - Use SimpleDateFormat/Main.java

import java.util.*;

import java.text.*;


public class Main {


public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

    //FILL THE CODE

    String d=sc.nextLine();

    SimpleDateFormat sdf=new SimpleDateFormat("dd/MM/yyy");

    sdf.setLenient(false);

    try{

        Date javaDate=sdf.parse(d);

        System.out.printf(d+" is a valid date");

    }

    catch(ParseException e){

        System.out.println(d+" is not a valid date");

    }

}

}



8. DreamTek Company

Path: JAVA/Classes and Objects, Packages/DreamTek Company/DreamTek Company/Associate.java

public class Associate{

    private int associateId;

    private String associateName;

    private String workStatus;

    

    public int getAssociateId()

    {

        return this.associateId;

    }

    

    public void setAssociateId(int associateId)

    {

        this.associateId=associateId;

    }

    

    public String getAssociateName()

    {

        return this.associateName;

    }

    

    public void setAssociateName(String associateName)

    {

        this.associateName=associateName;

    }

    

    public String getWorkStatus()

    {

        return this.workStatus;

    }

    

    public void setWorkStatus(String workStatus)

    {

        this.workStatus=workStatus;

    }

    

    public void trackAssociateStatus(int days)

    {   

        //days=abs(days);

        

        if(days>=1&&days<=20)

        {

            this.setWorkStatus("Core skills");

        }

        

        else if(days>=21 && days<=40)

        {

            this.setWorkStatus("Advanced modules");

        }

        

        else if(days>=41 && days<=60)

        {

            this.setWorkStatus("Project phase");

        }

        

        else

        {

            this.setWorkStatus("Deployed in project");

        }

    }

}

Path: JAVA/Classes and Objects, Packages/DreamTek Company/DreamTek Company/Main.java

import java.util.Scanner;

public class Main{

    public static void main (String[] args) {

        Scanner sc=new Scanner(System.in);

        System.out.println("Enter the associate id:");

        int ass_Id=sc.nextInt();

        sc.nextLine();

        

        System.out.println("Enter the associate name:");

        String name=sc.nextLine();

        

        System.out.println("Enter the number of days:");

        int days=sc.nextInt();

        

        Associate obj=new Associate();

        

        obj.setAssociateName(name);

        obj.trackAssociateStatus(days);

        

        System.out.println("The associate "+obj.getAssociateName()+" work status:"+obj.getWorkStatus());        

    }

}


9. Employee Salary Calculation

Path: JAVA/Classes and Objects, Packages/Employee Salary Calculation/Employee.java

public class Employee{

    

    private int employeeId;

    private String employeeName;

    private double salary;

    private double netSalary;

    

    /***** Getters **********/

    public int getEmployeeId()

    {

        return employeeId;

    }

    public String getEmployeeName()

    {

        return employeeName;

    }

    public double getSalary()

    {

        return salary;

    }

    public double getNetSalary()

    {

        return netSalary;

    }

    

    /******* Setters ***********/

    public void setEmployeeId(int employeeId)

    {

        this.employeeId = employeeId;

    }

    public void setEmployeeName(String employeeName)

    {

        this.employeeName = employeeName;

    }

    public void setSalary(double salary)

    {

        this.salary = salary;

    }

    public void setNetSalary(double netSalary)

    {

        this.netSalary = netSalary;

    }

    

    public void calculateNetSalary(int pfpercentage)

    {

        double pfamount;

        pfamount = salary * pfpercentage/100;

        netSalary = salary - pfamount;

    }

}


Path: JAVA/Classes and Objects, Packages/Employee Salary Calculation/Main.java

import java.util.*;


public class Main{

    public static Employee getEmployeeDetails() {

        

        Scanner sc = new Scanner(System.in);

        

        Employee emp = new Employee();

        

        System.out.println("Enter Id:");

        int id = sc.nextInt();

        emp.setEmployeeId(id);

        System.out.println("Enter Name:");

        String name = sc.next();

        emp.setEmployeeName(name);

        System.out.println("Enter salary:");

        double salary = sc.nextDouble();

        emp.setSalary(salary);

        return emp;

    }

    

    public static int getPFPercentage()

    {

        Scanner sc_1 = new Scanner(System.in);

        

        System.out.println("Enter PF percentage:");

        int pfper = sc_1.nextInt();

        return pfper;

    }

    

    public static void main(String[] args)

    {

        Employee emp1;

        emp1 = Main.getEmployeeDetails();

        int pf = Main.getPFPercentage();

        emp1.calculateNetSalary(pf);

        

        System.out.println("Id : "+emp1.getEmployeeId());

        System.out.println("Name : "+emp1.getEmployeeName());

        System.out.println("Salary : "+emp1.getSalary());

        System.out.println("Net Salary : "+emp1.getNetSalary());

    }

}


10. Employee Rating

Path: JAVA/Classes and Objects, Packages/Employee rating/Employee rating/Employee.java

public class Employee{

    private String employeeId;

    private double salary;

    private String[] certification;

    private int rating;

    

    public Employee(){

        

    }

    

    public Employee(String id, double sal, String[] certi){

        employeeId = id;

        salary = sal;

        certification = certi;

    }

    

    public void findRating(){

        rating = 0;

        for(int j = 0; j < certification.length; j++){

            if(certification[j].equals("JAVA") || certification[j].equals("ORACLE") || certification[j].equals("GCUX") || certification[j].equals("CCNA") || certification[j].equals("AWS"))

                rating++;

        }

    }

    

    public double getSalary(){

        return salary;

    }

    

    public int getRating(){

        this.findRating();

        return rating;

    }

    

    public double calculateIncrement(){

        this.findRating();

        double increment = 0;

        switch(rating){

            case 1:

                increment = salary * 2 / 100;

                salary = salary + increment;

                return increment;

            case 2:

                increment = salary * 3.5 / 100;

                salary = salary + increment;

                return increment;

            case 3:

                increment = salary * 5 / 100;

                salary = salary + increment;

                return increment;

            case 4:

                increment = salary * 7.5 / 100;

                salary = salary + increment;

                return increment;

            case 5:

                increment = salary * 10 / 100;

                salary = salary + increment;

                return increment;

            default:

                salary += increment;

                return increment;

        }

    }

}


Path: JAVA/Classes and Objects, Packages/Employee rating/Employee rating/Main.java

import java.util.Scanner;

public class Main{

    public static void main (String[] args) {

        Scanner sc = new Scanner(System.in);

        String[] certification;

        System.out.println("Enter the employee id:");

        String eid = sc.next();

        System.out.println("Enter the salary:");

        double sal = sc.nextDouble();

        System.out.println("Enter the no of certification complete:");

        int certi = sc.nextInt();

        certification = new String[certi];

        if(certi > 0){

            System.out.println("Enter the Certification names:");

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

                certification[i] = sc.next();

            }

        }

        

        Employee e1 = new Employee(eid, sal, certification);

        System.out.println("Your rating is " + e1.getRating());

        System.out.println("Increment amount is " + String.format("%.2f", e1.calculateIncrement()));

        System.out.println("Current salary " + String.format("%.2f", e1.getSalary()));

    }

}


11. Movie Ticket Calculation

Path: JAVA/Classes and Objects, Packages/Movie Ticket Calculation/Main.java

import java.util.*;


public class Main{

    

    public static Movie getMovieDetails(){

        

        Movie m = new Movie();

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter the movie name:");

        String name=sc.nextLine();

        m.setMovieName(name);

        System.out.println("Enter the movie category:");

        String cat=sc.nextLine();

        m.setMovieCategory(cat);

        return m;

    }

    

    public static String getCircle(){

        Scanner sc= new Scanner(System.in);

        System.out.println("Enter the circle:");

        String c=sc.nextLine();

        return c;

    }

    

    public static void main(String[] args){

        Movie m1 = getMovieDetails();

        String c=getCircle();

        int a=m1.calculateTicketCost(c);

        System.out.println("Movie name = "+m1.getMovieName());

        System.out.println("Movie category = "+m1.getMovieCategory());

        

        if(a==-1)

        {

            System.out.println("Sorry there is no "+m1.getMovieCategory()+" type of category in theater.");

        }

        else if(a==-2)

        {

            System.out.println("Sorry!!! Circle is Invalid.");

        }

        else if(a==-3)

        {

            System.out.println("Sorry!!! Both circle and category are Invalid.");

        }

        else if(a==0)

        {

            System.out.println("The ticket cost is = "+m1.getTicketCost());

        }

    }

}


Path: JAVA/Classes and Objects, Packages/Movie Ticket Calculation/Movie.java

public class Movie{

    

    private String movieName,movieCategory;

    private int ticketCost;

    

    public void setMovieName(String movieName)

    {

        this.movieName=movieName;

    }

    public String getMovieName()

    {

        return movieName;

    }

    public void setMovieCategory(String cat)

    {

        this.movieCategory=cat;

    }

    public String getMovieCategory(){

        return movieCategory;

    }

    public void setTicketCost(int cost){

        this.ticketCost=cost;

    }

    public int getTicketCost(){

        return ticketCost;

    }

    

    public int calculateTicketCost(String circle)

    {

        if(!circle.equalsIgnoreCase("GOLD") && !circle.equalsIgnoreCase("SILVER") && (movieCategory.equalsIgnoreCase("2D") || movieCategory.equalsIgnoreCase("3D")))

        {

            return -2;

        }

        else if((circle.equalsIgnoreCase("GOLD") || circle.equalsIgnoreCase("SILVER")) && !movieCategory.equalsIgnoreCase("2D") && !movieCategory.equalsIgnoreCase("3D"))

        {

            return -1;

        }

        else if((!circle.equalsIgnoreCase("GOLD")) && (!circle.equalsIgnoreCase("SILVER")) && (!movieCategory.equalsIgnoreCase("2D")) && (!movieCategory.equalsIgnoreCase("3D")))

        {

            return -3;

        }

        else{

            if(circle.equalsIgnoreCase("GOLD") && movieCategory.equalsIgnoreCase("2D"))

                ticketCost=300;

            else if(circle.equalsIgnoreCase("GOLD") && movieCategory.equalsIgnoreCase("3D"))

                ticketCost=500;

            else if(circle.equalsIgnoreCase("SILVER") && movieCategory.equalsIgnoreCase("2D"))

                ticketCost=250;

            else if(circle.equalsIgnoreCase("SILVER") && movieCategory.equalsIgnoreCase("3D"))

                ticketCost=450;

                return 0;

        }

    }

}


12. Student Details - Constructor

Path: JAVA/Classes and Objects, Packages/Student Details - Constructor/Student.java

public class Student

{

    private int studentId;

    private String studentName, studentAddress, collegeName;

    

    public Student(int studentId, String studentName, String studentAddress)

    {

        this.studentAddress=studentAddress;

        this.studentName=studentName;

        this.studentId=studentId;

        this.collegeName="NIT";

    }

    

    public Student(int studentId, String studentName, String studentAddress, String collegeName)

    {

        this(studentId, studentName, studentAddress);//invoking a constructor

        this.collegeName=collegeName;

    }

    

    public int getStudentId()

    {

        return this.studentId;

    }

    

    public String getStudentName()

    {

        return this.studentName;

    }

    

    public String getStudentAddress()

    {

        return this.studentAddress;

    }

    

    public String getCollegeName()

    {

        return this.collegeName;

    }

}


Path: JAVA/Classes and Objects, Packages/Student Details - Constructor/StudentMain.java

import java.util.Scanner;

public class StudentMain

{   public static void main (String[] args) 

    {

        

       Scanner sc=new Scanner(System.in);

       System.out.println("Enter Student's Id:");

       int studentId=sc.nextInt();

       sc.nextLine();

       

       System.out.println("Enter Student's Name:");

       String studentName=sc.nextLine();

       

       System.out.println("Enter Student's address:");

       String studentAddress=sc.nextLine();

       

       while(true)

       {

            System.out.println("Whether the student is from NIT(Yes/No):");

            String answer=sc.nextLine();

       

            if(answer.equalsIgnoreCase("yes"))

            {

                Student obj = new Student(studentId, studentName, studentAddress);

                System.out.println("Student id:"+obj.getStudentId());

                System.out.println("Student name:"+obj.getStudentName());

                System.out.println("Address:"+obj.getStudentAddress());

                System.out.println("College name:"+obj.getCollegeName());

                break;

            }

           

            else if(answer.equalsIgnoreCase("no"))

            {       

                System.out.println("Enter the college name:");

                String collegename=sc.nextLine();

                

                Student obj = new Student(studentId, studentName, studentAddress, collegename);

                

                System.out.println("Student id:"+obj.getStudentId());

                System.out.println("Student name:"+obj.getStudentName());

                System.out.println("Address:"+obj.getStudentAddress());

                System.out.println("College name:"+obj.getCollegeName());

                break;

            }

            

            else

            {

                System.out.println("Wrong Input");

            }

       }

    }

}


13. Student and Department Detail

Path: JAVA/Classes and Objects, Packages/Student and Department Detail/Department.java

public class Department

{

    private int did;

    private String dname;

    public int getDid()

    {

        return did;

    }

    public String getDname()

    {

        return dname;

    }

    public void setDid(int d)

    {

        did=d;

    }

    public void setDname(String name)

    {

        dname=name;

    }

}


Path: JAVA/Classes and Objects, Packages/Student and Department Detail/Student.java

import java.util.*;

public class Student

{

    private int sid;

    private String sname;

    private Department department;

    public Department getDepartment()

    {

        System.out.println("Department id:"+department.getDid());

        System.out.println("Department name:"+department.getDname());

        return department;

    }

    public int getSid()

    {

        return sid;

    }

    public String getSname()

    {

        return sname;

    }

    public void setSid(int id)

    {

        sid=id;

    }

    public void setSname(String name)

    {

        sname=name;

    }

    public void setDepartment(Department d)

    {

        department=new Department();

        department=d;

    }

}


Path: JAVA/Classes and Objects, Packages/Student and Department Detail/TestMain.java

import java.util.*;

public class TestMain

{

    public static Student createStudent()

    {

        Scanner sc=new Scanner(System.in);

        Student s=new Student();

        System.out.println("Enter the Departmant id:");

        int did=sc.nextInt();

        sc.nextLine();

        System.out.println("Enter the Departmant name:");

        String dname=sc.nextLine();

        Department d=new Department();

        d.setDid(did);

        d.setDname(dname);

        s.setDepartment(d);

        System.out.println("Enter the student id:");

        s.setSid(sc.nextInt());

        sc.nextLine();

        System.out.println("Enter the Student name:");

        s.setSname(sc.nextLine());

        return s;

    }

    public static void main(String[] args)

    {

        Student st=new Student();

        st=createStudent();

        st.getDepartment();

        System.out.println("Student id:"+st.getSid());

        System.out.println("Student name:"+st.getSname());

    }

}


14. Ticket Price Calculation- Static

Path: JAVA/Classes and Objects, Packages/Ticket Price Calculation - Static/Main.java

import java.util.Scanner;

public class Main 

{

    public static void main (String[] args) {

        Scanner sc=new Scanner(System.in);

        Ticket obj=new Ticket();

        

        System.out.println("Enter no of bookings:");

        int no_bookings=sc.nextInt();

        

        System.out.println("Enter the available tickets:");

        obj.setAvailableTickets(sc.nextInt());

        

        while(no_bookings>0)

        {

        System.out.println("Enter the ticketid:");

        obj.setTicketid(sc.nextInt());

        

        System.out.println("Enter the price:");

        obj.setPrice(sc.nextInt());

        

        System.out.println("Enter the no of tickets:");

        int no_tickets=sc.nextInt();

        if(obj.calculateTicketCost(no_tickets)==-1)

        {

            continue;

        }

        

        System.out.println("Available tickets: "+obj.getAvailableTickets());

        

        System.out.println("Total amount:"+obj.calculateTicketCost(no_tickets));

        

        System.out.println("Available ticket after booking:"+obj.getAvailableTickets());

        

            no_bookings--;

        }

    }

}


Path: JAVA/Classes and Objects, Packages/Ticket Price Calculation - Static/Ticket.java

public class Ticket

{

    private int ticketid;

    private int price;

    private static int availableTickets;

    

    public void setTicketid(int ticketid)

    {

        this.ticketid=ticketid;

    }

    

    public int getTicketid()

    {

        return this.ticketid;

    }

    

    public void setPrice(int price)

    {

        this.price=price;

    }

    

    public int getPrice()

    {

        return this.price;

    }

    

    public static void setAvailableTickets(int availableTickets1)

    {   if(availableTickets1>=0)

        {

            availableTickets=availableTickets1;

        }

    }

    

    public static int getAvailableTickets()

    {

        return availableTickets;

    }

    

    public int calculateTicketCost(int nooftickets)

    {   

        if(availableTickets>=nooftickets)

        {   

            availableTickets-=nooftickets;

            return nooftickets*this.price;

        }

        else

        {

            return -1;

        }

    }

}


15. Token Automation in Bank

Path: JAVA/Classes and Objects, Packages/Token Automation in Bank/Main.java

import java.util.*;


public class Main{

    public static void main (String[] args) {

        

        Scanner sc=new Scanner(System.in);

        String service;

        System.out.println("Enter the service type for first customer:");

        service=sc.nextLine();

        

        Token t=new Token(service);

        System.out.println("Your Token number is:"+t.getTokenNumber()+" and Counter number is:"+t.getCounterNumber());

        System.out.println("Enter the service type for next customer:");

        service=sc.nextLine();

        Token t1=new Token(service);

        System.out.println("Your Token number is:"+t1.getTokenNumber()+" and Counter number is:"+t1.getCounterNumber());

    }    

}


Path: JAVA/Classes and Objects, Packages/Token Automation in Bank/Token.java

public class Token{

    

    private static int tokenNumber;

    private int counterNumber;

    private String serviceType;

    

    public Token(String serviceType){

        tokenNumber=tokenNumber+1;

        if(serviceType.equals("Others"))

            counterNumber=4;

        else if(serviceType.equals("Deposit"))

            counterNumber=3;

        else if(serviceType.equals("Withdraw"))

            counterNumber=2;

        else if(serviceType.equals("Cheque deposit"))

            counterNumber=1;

    }

    

    public static int getTokenNumber(){

        return tokenNumber;

    }

    

    public int getCounterNumber(){

        return counterNumber;

    }

    

    public String getServiceType(){

        return serviceType;

    }

}


16. Travel Details

Path: JAVA/Classes and Objects, Packages/Travel Details/BusTicket.java

public class BusTicket{

    

    private int ticketNo;

    private float ticketPrice;

    private float totalAmount;

    private Person person;

    

    /*********** Getters ***************/

    public int getTicketNo()

    {

        return ticketNo;

    }

    public float getTicketPrice()

    {

        return ticketPrice;

    }

    public float getTotalAmount()

    {

        return totalAmount;

    }

    public Person getPerson()

    {

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

        return person;

    }

    

    /************** Setters *********/

    public void setTicketNo(int ticketNo)

    {

        this.ticketNo = ticketNo;

    }

    public void setTicketPrice(float ticketPrice)

    {

        this.ticketPrice = ticketPrice;

    }

    public void setTotalAmount(float totalAmount)

    {

        this.totalAmount = this.totalAmount;

    }

    public void setPerson(Person p)

    {

        this.person = p;

    }

    

    public void calculateTotal()

    {

        int age1=person.getAge();

        char g=person.getGender();

        float Amount=0;

        

        if(age1<16)

        {

            Amount=(ticketPrice*50)/100;

            totalAmount=ticketPrice - Amount;

        }

        else if(age1>=60)

        {

            Amount=(ticketPrice*25)/100;

            totalAmount=ticketPrice - Amount;

        }

        else if(age1>=16 && age1<60)

        {

            if(g=='f' || g=='F')

            {

                Amount=(ticketPrice*10)/100;

                totalAmount=ticketPrice - Amount;

            }

            else

            {

                totalAmount = ticketPrice;

            }

        }

        else

        {

            totalAmount = ticketPrice;

        }

        setTotalAmount(totalAmount);

    }

}


Path: JAVA/Classes and Objects, Packages/Travel Details/Person.java
public class Person{
    
    private String name;
    private char gender;
    private int age;
    
    /******* Getters ************/
    public String getName()
    {
        return name;
    }
    public char getGender()
    {
        return gender;
    }
    public int getAge()
    {
        return age;
    }
    
    /******** Setters ***********/
    public void setName(String name)
    {
        this.name = name;
    }
    public void setGender(char gender)
    {
        this.gender = gender;
    }
    public void setAge(int age)
    {
        this.age = age;
    }
}


Path: JAVA/Classes and Objects, Packages/Travel Details/TestMain.java
import java.util.*;

public class TestMain{
    
    public static BusTicket getTicketDetails()
    {
        Scanner sc = new Scanner(System.in);
        BusTicket bt = new BusTicket();
        
        System.out.println("Enter the passenger name:");
        String name = sc.nextLine();
        System.out.println("Enter the gender(M or F / m or f):");
        char gender = sc.next().charAt(0);
        System.out.println("Enter the age:");
        int age=sc.nextInt();
        sc.nextLine();
        
        Person p = new Person();
        p.setName(name);
        p.setGender(gender);
        p.setAge(age);
        bt.setPerson(p);
        
        System.out.println("Enter the ticket no:");
        int ticketNo = sc.nextInt();
        bt.setTicketNo(ticketNo);
        sc.nextLine();
        System.out.println("Enter the ticket price:");
        float ticketprice = sc.nextFloat();
        bt.setTicketPrice(ticketprice);
        
        return bt;
    }
    
    public static void main(String[] args)
    {
        TestMain tm = new TestMain();
        BusTicket bt_1 = new BusTicket();
        
        bt_1 = tm.getTicketDetails();
        bt_1.calculateTotal();
        System.out.println("Ticket no:"+bt_1.getTicketNo());
        bt_1.getPerson();
        System.out.println("Price of a ticket :"+bt_1.getTicketPrice());
        System.out.println("Total Amount :"+bt_1.getTotalAmount());
    }
}


17. Volume calculator- Over Loading

Path: JAVA/Classes and Objects, Packages/Volume calculator- Over Loading/TestMain.java
import java.util.*;

public class TestMain{
    
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        VolumeCalculator vc = new VolumeCalculator();
        System.out.println("Enter the choice");
        System.out.println("1.Find Volume For Cylinder");
        System.out.println("2.Find Volume For Cuboid");
        int ch=sc.nextInt();
        
        if(ch==1)
        {
            System.out.println("Enter the radius");
            double r=sc.nextDouble();
            System.out.println("Enter the height");
            double h=sc.nextDouble();
            double result=vc.calculateVolume(r,h);
            System.out.println("Volume of the Cylinder is "+result);
        }
        else if(ch==2)
        {
            System.out.println("Enter the length");
            int length=sc.nextInt();
            System.out.println("Enter the breadth");
            int breadth=sc.nextInt();
            System.out.println("Enter the height");
            int height=sc.nextInt();
            double rs=vc.calculateVolume(length,breadth,height);
            System.out.println("Volume of the Cuboid is "+rs);
        }
    }
}


Path: JAVA/Classes and Objects, Packages/Volume calculator- Over Loading/VolumeCalculator.java
public class VolumeCalculator{
    
    public double calculateVolume(double radius,double height)
    {
        double volume;
        volume=(3.14)*radius*radius*height;
        double answer=Math.round(volume*100.0)/100.0;
        return answer;
    }
    
    public double calculateVolume(int length,int breadth, int height)
    {
        double cuboid;
        cuboid=length*breadth*height;
        double answer1=Math.round(cuboid*100.0)/100.0;
        return answer1;
    }
}


18. ZeeZee Bank

Path: JAVA/Classes and Objects, Packages/ZeeZee bank/ZeeZee bank/Account.java
public class Account{
    private long accountNumber;
    private double balanceAmount;
    
    public Account(long accountNumber, double balanceAmount)
    {
        this.accountNumber=accountNumber;
        this.balanceAmount=balanceAmount;
    }
    
    public int withdraw(double amount)
    {
        if((this.balanceAmount-amount)>0)
        {   
            this.balanceAmount-=amount;
            return 1;
        }
        else
        {
            return -1;
        }
    }
    
    public void deposit(double amount)
    {
        this.balanceAmount+=amount;
    }
    
    public double getBalanceAmount()
    {
        return this.balanceAmount;
    }
    
}

Path: JAVA/Classes and Objects, Packages/ZeeZee bank/ZeeZee bank/Main.java
import java.util.Scanner;
import java.text.DecimalFormat;
public class Main{
    public static void main (String[] args) {
        Scanner sc=new Scanner(System.in);
        DecimalFormat df=new DecimalFormat("########0.00");
        System.out.println("Enter the account number:");
        long acc_num=sc.nextLong();
        
        System.out.println("Enter the available amount in the account:");
        double bal_amt=sc.nextDouble();
        
        System.out.println("Enter the amount to be deposited:");
        double dep_amt=sc.nextDouble();
        
        Account obj= new Account(acc_num, bal_amt);
        
        obj.deposit(dep_amt);
        System.out.println("Available balance is:"+df.format(obj.getBalanceAmount()));
        
        System.out.println("Enter the amount to be withdrawn:");
        double wdw_amt=sc.nextDouble();
        
        if(obj.withdraw(wdw_amt)==-1)
        {
            System.out.println("Insufficient balance");
        }
        
        System.out.println("Available balance is:"+df.format(obj.getBalanceAmount()));
    }
    
}



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!