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

Control Structures Hands-Ons [Java > Control Structures] | 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. Control Structures

Path: JAVA/Control Structures/Bill Generation/SnacksDetails.java

import java.util.Scanner;

public class SnacksDetails

{

    public static void main (String[] args) {

        Scanner sc=new Scanner(System.in);

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

        int piz=sc.nextInt();

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

        int puf=sc.nextInt();

        System.out.println("Enter the no of cool drinks bought:");

        int cdk=sc.nextInt();

        

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

        System.out.println("No of pizzas:"+piz);

        System.out.println("No of puffs:"+puf);

        System.out.println("No of cooldrinks:"+cdk);

        System.out.println("Total price="+(piz*100+puf*20+cdk*10));

        System.out.println("ENJOY THE SHOW!!!");

    }

}


2. Car Details

Path: JAVA/Control Structures/Car Details/CarDetails.java

import java.util.*;

import java.io.*;

public class CarDetails{

    public static void main(String args[]){

        Scanner sc= new Scanner(System.in);

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

        String name=sc.nextLine();

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

        int no=sc.nextInt();

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

        double price=sc.nextDouble();

        System.out.println("Carname:"+name);

        System.out.println("Carno:"+no);

        System.out.printf("Price:%.2f rs only",price);

    }

}


3. Celsius to Fahrenheit Conversion

Path: JAVA/Control Structures/Celsius to Fahrenheit Conversion/CelsiusConversion.java

import java.util.Scanner;

public class CelsiusConversion

{

    public static void main (String[] args) {

        Scanner sc=new Scanner(System.in);

        double cel=sc.nextDouble();

        double fah=((9*cel)/5)+32;

        System.out.println(fah);

    }

}


4. Check for Leap Year

Path: JAVA/Control Structures/Check for Leap Year/LeapYear.java

import java.util.Scanner;

public class LeapYear

{

    public static void main (String[] args) {

        Scanner sc=new Scanner(System.in);

        System.out.println("Enter the Year");

        

        int yr=sc.nextInt();

        

        if(yr>999 && yr<10000)

        {

            if(yr%4==0)

            {

                if(yr%100==0)

                {

                    if(yr%400==0)

                    {

                        System.out.println("Leap Year");

                    }

                    else

                    {

                        System.out.println("Not a Leap Year");

                    }

                }

                else

                {

                    System.out.println("Leap Year");

                }

            }

            else

            {

                System.out.println("Not a Leap Year");

            }

        }

        else

        {

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

        }

    }

}


5. Checking budget of mobile

Path: JAVA/Control Structures/Checking budget of mobile/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 cost of the mobile");

        //Fill the code here

        int c=sc.nextInt();

        if(c<=13000)

        {

            System.out.println("Mobile chosen is within the budget");

        }

        else

        {

            System.out.println("Mobile chosen is beyond the budget");

        }  

    }  

}


6. Compute Gain Percentage

Path: JAVA/Control Structures/Compute Gain Percentage/Gain.java

import java.io.*;

import java.util.*;

public class Gain{

    public static void main(String args[]){

        Scanner sc=new Scanner(System.in);

        System.out.println("Price of old scooter:");

        double old=sc.nextDouble();

        System.out.println("The amount spent for repair:");

        double pair=sc.nextDouble();

        System.out.println("Sold Price:");

        double sold=sc.nextDouble();

        if(old<=0){

            System.out.println("Incorrect Inputs");

        }

        else if(pair<0){

            System.out.println("Incorrect Inputs");

        }

        else if(sold<=0){

            System.out.println("Incorrect Inputs");

        }

        else if(sold<(old+pair)){

            System.out.println("Unable to calculate Gain Percentage");       

        }

        else{

            double g=0,l=0;

            g=sold-(old+pair);

            l=(g*100)/(old+pair);

            if(l>=0){

                System.out.printf("Gain percentage is %.2f",l);

            }

        }

    }

}


7. Compute Gain Percentage

Path: JAVA/Control Structures/Compute Gain Percentage/Gain.java

import java.io.*;

import java.util.*;

public class Gain{

    public static void main(String args[]){

        Scanner sc=new Scanner(System.in);

        System.out.println("Price of old scooter:");

        double old=sc.nextDouble();

        System.out.println("The amount spent for repair:");

        double pair=sc.nextDouble();

        System.out.println("Sold Price:");

        double sold=sc.nextDouble();

        if(old<=0){

            System.out.println("Incorrect Inputs");

        }

        else if(pair<0){

            System.out.println("Incorrect Inputs");

        }

        else if(sold<=0){

            System.out.println("Incorrect Inputs");

        }

        else if(sold<(old+pair)){

            System.out.println("Unable to calculate Gain Percentage");        

        }

        else{

            double g=0,l=0;

            g=sold-(old+pair);

            l=(g*100)/(old+pair);

            if(l>=0){

                System.out.printf("Gain percentage is %.2f",l);

            }

        }

    }

}


9. Convert Numbers into Months

Path: JAVA/Control Structures/Convert Numbers into Months/NumToMonth.java

import java.util.*;

public class NumToMonth

{

    public static void main (String[] args) {

        Scanner sc=new Scanner(System.in);

        int n=sc.nextInt();

        String mon[]={"January", "February", "March","April", "May", "June", "July", "August", "September", "October", "November", "December"};

        if(n>12||n<1)

        {

            System.out.println("No month for the number "+n);

        }

        else

        {

            System.out.println(mon[n-1]);

        }

    }

}


10. Display Characters

Path: JAVA/Control Structures/Display Characters/AsciValue.java

import java.util.*;

public class AsciValue{

    public static void main(String args[]){

        Scanner sc=new Scanner(System.in);

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

        int n1=sc.nextInt();

        int n2=sc.nextInt();

        int n3=sc.nextInt();

        int n4=sc.nextInt();

        char c1=(char)n1;

        char c2=(char)n2;

        char c3=(char)n3;

        char c4=(char)n4;

        System.out.print("\n"+n1+"-"+c1);

        System.out.print("\n"+n2+"-"+c2);

        System.out.print("\n"+n3+"-"+c3);

        System.out.print("\n"+n4+"-"+c4);

    }

}


11. Electricity bill calculation

Path: JAVA/Control Structures/Electricity bill calculation/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 units consumed");

       float u=sc.nextFloat();

       if(u<=20)

       {

           System.out.println("No Charge");

       }

       else if(u<100&&u>20)

       {    double bill=u*3.5;

           System.out.println("You have to pay Rs."+bill);

       }

       else

       {

           double bill=u*5.0;

           System.out.println("You have to pay Rs."+bill);

       }

        //Fill the code here

    }  

}


12. Find Season

Path: JAVA/Control Structures/Find Season/Season.java

import java.util.Scanner;

public class Season 

{

    public static void main (String[] args) {

        Scanner sc = new Scanner(System.in);

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

            int mon=sc.nextInt();

            if(mon>12||mon<1)

            {

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

            }

            else if(mon>=3&&mon<=5)

            {

                System.out.println("Season:Spring");

            }

            else if(mon>=6&&mon<=8)

            {

                System.out.println("Season:Summer");

            }

            else if(mon>=9&&mon<=11)

            {

                System.out.println("Season:Autumn");

            }

            else if(mon==12||mon==1||mon==2)

            {

                System.out.println("Season:Winter");

            }

    }

}


13. Find Range of the Number

Path: JAVA/Control Structures/Finding Range Of The Number/Main.java

import java.util.Scanner;


public class Main{

    

    public static void main(String[] args){

        

       Scanner sc=new Scanner(System.in);

        //Fill the code here

        Scanner s=new Scanner(System.in);

        System.out.println("Enter the number");

        int n=s.nextInt();

        if(n>0&&n<=100)

        {

            System.out.println("Range of the number " +n +" is 0 to 100");

        }

        else if(n>100&&n<=200)

        {

            System.out.println("Range of the number " +n +" is 100 to 200");

        }

        else if(n>200&&n<=500)

        {

            System.out.println("Range of the number " +n +" is 200 to 500");

        }

        else

        {

            System.out.println("Entered number " +n +" is not in the expected range");

        }

    }  

}


14. Finding even number

Path: JAVA/Control Structures/Finding even number/Main.java

import java.util.Scanner;

public class Main {

   public static void main(String args[]){

      //Reading number from user

      Scanner sc = new Scanner(System.in);

      System.out.println("Enter the number" );

      int num = sc.nextInt();

      if (num % 2 == 0){

         System.out.println(+num+" is an even number");

      } else {

         System.out.println(+num+" is an odd number");

      }

   }

}


15. Highest Placement

Path: JAVA/Control Structures/Highest Placement/Placement.java

import java.util.Scanner;

public class Placement

{

    public static void main (String[] args) {

        Scanner sc=new Scanner(System.in);

        System.out.println("Enter the no of students placed in CSE:");

            int CSE= sc.nextInt();

        System.out.println("Enter the no of students placed in ECE:");

            int ECE=sc.nextInt();

        System.out.println("Enter the no of students placed in MECH:");

            int MECH=sc.nextInt();

            

        if(CSE<0||ECE<0||MECH<0)

        {

            System.out.println("Input is Invalid");

        }

        

        else if(CSE==ECE && ECE==MECH)

        {

            System.out.println("None of the department has got the highest placement");

        }

        

        else if(CSE==ECE && MECH<CSE)

        {

            System.out.println("Highest placement");

            System.out.println("CSE");

            System.out.println("ECE");

        }

        

        else if(CSE==MECH && ECE<MECH)

        {

            System.out.println("Highest placement");

            System.out.println("CSE");

            System.out.println("MECH");

        }

        

        else if(ECE==MECH && CSE<MECH)

        {

            System.out.println("Highest placement");

            System.out.println("ECE");

            System.out.println("MECH");

        }

        

        else if(CSE>ECE&&CSE>MECH)

        {

            System.out.println("Highest placement");

            System.out.println("CSE");

        }

        

        else if(ECE>CSE && ECE>MECH)

        {

            System.out.println("Highest placement");

            System.out.println("ECE");

        }

        

        else if(MECH>CSE&&MECH>ECE)

        {

            System.out.println("Highest placement");

            System.out.println("MECH");

        }

    }

}


16. Income Calculation

Path: JAVA/Control Structures/Income Calulation/IncomeCal.java

import java.util.*;

import java.io.*;

public class IncomeCal{

    public static void main(String args[]){

        Scanner sc=new Scanner(System.in);

        System.out.println("Enter no of hours worked in a day:");

        int hr=sc.nextInt();

        if(hr>=0 && hr<=24){

            int total=(hr * 100 * 365);

            System.out.println("Total income in a year:"+total);

        }

        else{

            System.out.println("Unable to calculate the earnings");

        }

    }

}


17. Increment Calculation

Path: JAVA/Control Structures/Increment Calculation/IncrementCalculation.java

import java.io.*;

import java.util.*;

public class IncrementCalculation{

    public static void main(String args[]){

        Scanner sc=new Scanner(System.in);

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

        int sal=sc.nextInt();

        System.out.println("Enter the Performance appraisal rating");

        float rate=sc.nextFloat();

        if(sal>0 && rate>=1 && rate<=5){

            if(rate>=1 && rate<=3){

                sal+=((sal*10)/100);

            }

            else if(rate>=3.1 && rate<=4){

                sal+=((sal*25)/100);

            }

            else{

                sal+=((sal*30)/100);

            }

            System.out.println(sal);

       }

       else{

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

       }

    }

}


18. Movie Ticket Calculation

Path: JAVA/Control Structures/Movie Ticket Calculation/CinemaTicket.java

import java.io.*;

import java.util.*;

public class CinemaTicket{

    public static void main(String args[]){

        Scanner sc=new Scanner(System.in);

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

        int ticket=sc.nextInt();

        if(ticket>=5 && ticket<=40){

            System.out.println("Do you want refreshment:");

            String refreshment=sc.next();

            System.out.println("Do you have coupon code:");

            String code=sc.next();

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

            String circle=sc.next();

            double cost=0;

            switch(circle){

                case "k":

                    {

                        int value=75;

                        cost=(ticket * value);

                        if(ticket>20) cost-=(0.10 * cost);

                        if(code.equals("y")) cost-=(0.02* cost);

                        if(refreshment.equals("y")) cost+=(50 * ticket);

                        System.out.println("Ticket Cost:"+String.format("%.2f",cost));

                        break;

                    

                }

                case "q":

                    {

                        int value=150;

                        cost=(ticket * value);

                        if(ticket > 20) cost-=(0.10 * cost);

                        if(code.equals("y")) cost-=(0.02 * cost);

                        if(refreshment.equals("y")) cost+=(50 * ticket);

                        System.out.println("Ticket Cost:"+String.format("%.2f",cost));

                        break;

                    }

                default:

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

                

            }

        }

        else{

            System.out.println("Minimum of 5 and Maximum of 40 Tickets");

        }

    }

}


19. Print Customer Details

Path: JAVA/Control Structures/Print Customer Details/Customer.java

import java.util.*;

import java.io.*;

public class Customer{

    public static void main(String args[]){

        Scanner sc=new Scanner(System.in);

        System.out.println("Enter your name:");

        String name=sc.nextLine();

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

        int age=sc.nextInt();

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

        String gender=sc.next();

        sc.nextLine();

        System.out.println("Hailing from:");

        String from=sc.nextLine();

        System.out.println("Welcome," +name+"!");

        System.out.println("Age:"+age);

        System.out.println("Gender:"+gender);

        System.out.println("City:"+from);

    }

}


20. Print Message

Path: JAVA/Control Structures/Print Message/PrintMessage.java

public class PrintMessage{

    public static void main(String args[]){

        System.out.println("Welcome to object oriented programming");

    }

}


21. Print Username

Path: JAVA/Control Structures/Print Username/Username.java

import java.util.Scanner;

public class Username

{

    public static void main (String[] args) {

        Scanner sc=new Scanner(System.in);

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

        String name=sc.nextLine();

        System.out.println("Welcome "+name+".");

    }

}


22. Registration Details

Path: JAVA/Control Structures/Registration Details/RegistrationDetails.java

import java.util.*;

import java.io.*;

import java.lang.*;

public class RegistrationDetails{

    public static void main(String args[]){

        Scanner sc=new Scanner(System.in);

        System.out.println("Enter your name:");

        String name=sc.nextLine();

        System.out.println("Enter your age:");

        int age=sc.nextInt();

        System.out.println("Enter your phoneno:");

        String  phone=sc.next();

        System.out.println("Enter your qualification:");

        sc.nextLine();

        String qual=sc.nextLine();

        System.out.println("Enter your email id[Please provide valid id, after registering your registration id will be mailed]:");

        String email=sc.nextLine();

        System.out.println("Enter your noofexperience[if any]:");

        double experience=sc.nextDouble();

        System.out.printf("Dear %s, Thanks for registering in our portal, registration id will be mailed to %s within 2 working days",name,email);

    }

}


23. Road Signaling

Path: JAVA/Control Structures/Road Signaling/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 color");

       String col=sc.nextLine();

       if(col.equals("red"))

       {

           System.out.println("stop");

       }

       else if(col.equals("yellow"))

       {

           System.out.println("proceed with caution");

       }

       else if(col.equals("green"))

       {

           System.out.println("go");

       }

       else

       {

           System.out.println("prepare to go");

       }

        //Fill the code here

    }

    

}


24. Spell Check

Path: JAVA/Control Structures/Spell Check/Character.java

import java.util.Scanner;

public class Character

{

    public static void main (String[] args) {

        int flag=0;

        Scanner sc=new Scanner(System.in);

        System.out.println("Enter the first letter:");

            {if(sc.next().charAt(0)!='R')

                flag++;

        System.out.println("Enter the second letter:");

            if(sc.next().charAt(0)!='A')

                flag++;

        System.out.println("Enter the third letter:");

            if(sc.next().charAt(0)!='I')

                flag++;

        System.out.println("Enter the fourth letter:");

            if(sc.next().charAt(0)!='N')

                flag++;

        System.out.println("Enter the fifth letter:"); 

            if(sc.next().charAt(0)!='B')

                flag++;

        System.out.println("Enter the sixth letter:");

            if(sc.next().charAt(0)!='O')

                flag++;

        System.out.println("Enter the seventh letter:");

            if(sc.next().charAt(0)!='W')

                flag++;

            }    

        if(flag==0)

        {

            System.out.println("RAINBOW");

        }

        else

        {

            System.out.println("The spelling is wrong");

        }

    }

}


25. Triangle Validation

Path: JAVA/Control Structures/Triangle Validation/Triangle.java

import java.io.*;

import java.util.*;

public class Triangle{

    public static void main(String args[]){

        Scanner sc=new Scanner(System.in);

        System.out.println("Enter the value for side1");

        int s1=sc.nextInt();

        System.out.println("Enter the value for side2");

        int s2=sc.nextInt();

        System.out.println("Enter the value for side3");

        int s3=sc.nextInt();

        if(s1<=0 || s2<=0 || s3<=0){

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

            

        }

        else{

            int d=s1+s2;

            int e=s2+s3;

            int f=s3+s1;

            if((d>s3)&&(e>s1)&&(f>s2)){

                System.out.println("Sides form a Triangle");

            }

            else{

                System.out.println("Sides does not form a Triangle");

            }

        }

    }

}



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!