school assignments


  1. Write a program to input 10 numbers into an integer array and find the average of two-digit numbers only.
 import java.util.Scanner;  
 class JavaTest1 {  
      public static void main(String argc[]) {  
           Scanner sc = new Scanner(System.in);  
           int a[] = new int[10];  
           int i, s = 0, c = 0;  
           System.out.println("Enter 10 numbers:");  
           for (i = 0; i < a.length; i++) {  
                a[i] = sc.nextInt();  
                if (a[i] >= 10 && a[i] <= 99) {  
                     s = s + a[i];  
                     c++;  
                }  
           }  
           if (c > 0)  
                System.out.println("Average of 2-digit numbers:" + (float) s / c);  
           else  
                System.out.println("No 2-digit numbers present");  
      }  
 }  

2. Write a program to input 10 numbers into an integer array and print the position of the largest number.
 import java.util.Scanner;  
 class JavaTest2 {  
      public static void main(String argc[]) {  
           Scanner sc = new Scanner(System.in);  
           int a[] = new int[10];  
           int i, l = 0;  
           System.out.println("Enter 10 numbers:");  
           for (i = 0; i < a.length; i++) {  
                a[i] = sc.nextInt();  
                if (i == 0)  
                     l = a[i];  
                if (a[i] > l)  
                     l = a[i];  
           }  
           System.out.println("Positions, where largest number is present, are:");  
           for (i = 0; i < a.length; i++) {  
                if (a[i] == l)  
                     System.out.print(i + " ");  
           }  
      }  
 }  
 Output

Enter 10 numbers:
12 23 45 66 534 56 35 5 3 55
Positions, where largest number is present, are:
4

3. Write a program to initialize the seven wonders of the world along with their location in two different arrays. Search for a name of the country input by the use. If found, display the name of the country along with its wonders, otherwise display "Sorry Bot Found" .
Seven Wonders : - Chichen Itza,Christ Redeemer,Taj Mahal, The Great Wall of China,Machu Picchu,Petra,Colosseum
Location : - Mexico,Brazil,India,China,Peru,Jordan,Italy

 import java.util.Scanner;  
 class JavaTest3 {  
      public static void main(String argc[]) {  
           Scanner sc = new Scanner(System.in);  
           int i =0;  
           String wonders[] ={"Chichen Itza","Christ Redeemer","TajMahal", "The Great Wall of China","Machu Picchu","Petra,Colosseum"};  
           String location[] = {"Mexico","Brazil","India","China","Peru","Jordan","Italy"};  
           System.out.println("Enter Country name ");  
           String country = sc.nextLine();  
           boolean flag =false;  
           for(i=0;i<wonders.length;i++){  
                if(location[i].equalsIgnoreCase(country)){  
                     flag =true;  
                     break;  
                }  
           }  
           if(flag==true){  
                System.out.println(wonders[i]+"--"+location[i]);  
           }else{  
                System.out.println("Sorry Not Found");  
           }  
      }  
  }  

Output :
Enter Country name
china

China--The Great Wall of China

4. Write a program to input five names in an array. Arrange these names in descending order of alphabets, using bubble sort technique.

 import java.util.Scanner;  
 class JavaTest1 {  
      public static void main(String argc[]) {  
           Scanner sc = new Scanner(System.in);  
           int i =0;  
           String names[] = new String[5];  
           String temp;  
           for(i=0;i<names.length;i++){  
                System.out.println("Enter name");  
                names[i]= sc.nextLine();  
           }  
           int comLength =names.length-1;  
           for(i=0;i<comLength;i++){  
                for(int j=0;j<comLength-i;j++){  
                     if(names[j].compareToIgnoreCase(names[j+1])<0){  
                          temp = names[j];  
                          names[j] =names[j+1];  
                          names[j+1]=temp;  
                     }  
                }  
           }  
           System.out.println("After sorting");  
           for(i=0;i<names.length;i++){  
                System.out.println(names[i]);  
           }  
      }  
  }  
Output

Enter name
anjan
Enter name
amit
Enter name
debadittya
Enter name
suman
Enter name
suresh

After sorting
suresh
suman
debadittya
anjan
amit

School project Movie Management System

 package core;  
 import java.util.Date;  
 import java.util.Scanner;  
 public class Movie {  
      public String[] movieNames = {"Golmaal Again","Ittefaq","Kutumb The Family","Thor: Ragnarok","Geostorm"};  
      public String [][] showTime = {  
                {"9.10AM"},  
                {"9.45 AM","4.00 PM" ,"7.05 PM"},  
                {"1.00 PM","5.10 PM" , "8.30 PM"},  
                {"3.00 PM","9.10 PM" , "11.30 PM"},  
                {"8.00 am","6.10 PM" , "10.20 PM"}  
           };  
      public float [][]price={  
                {120},  
                {90,150,120},  
                {90,120,100},  
                {170,220,250},  
                {100,190,220}  
      };   
      public String BEVERAGESandPRICE[][]={  
                {"1 REGULAR POPCORN (SALTED) + 1 REGULAR PEPSI","338.00"},  
                {"NACHOS COMBO (1 NACHOS WITH SALSA AND CHIESE DIP+ 1 REGULAR PEPSI)","345.00"},  
                {"COMBO FOR 2 (1 LARGE POPCORN (SALTED) + 2 REGULAR PEPSI","518.00"},  
                {"FAMILY COMBO (2 LARGE POPCORN (SALTED) + 4 REGULAR PEPSI","897.00"},  
                {"PVR VEG BURGER","180.00"}  
      };  
      public String seatType[]=  
                {"ROYAL RECLINER","ROYAL","EXECUTIVE","CLUB"};  
      public String cityNames[] ={"Mumbai","Pune","bengaluru","Chennai","Kolkata"};  
      public int numberOfSeat=1;  
      Date date;  
      float totalCost=0;  
      float moviePrice=0;  
      float snacksAndbeveragesCost=0;  
      String cityName;  
      static int seatSelection;  
      static int movieSelection;  
      static int citySelection;  
      static int showSelection;  
      static int foodSelection;  
      Scanner sc =new Scanner(System.in);  
      public void displayMovieList(){  
           System.out.println("--------------------- Choose you movie--------------------");  
           for(int i=0;i<movieNames.length;i++){  
                System.out.println(i+1+" ------------  "+movieNames[i]);  
           }  
      }  
      public void displayCityNames(){  
           System.out.print("--------------------- Choose your City--------------------");  
           for(int i=0;i<cityNames.length;i++){  
                System.out.println("1 ------------  "+cityNames[i]);  
           }  
      }  
      public void seats(){  
           System.out.print("--------------------- Seat Selection--------------------");  
           int x=0;  
           for(int i=0;i<3;i++){  
                for(int j=0;j<10;j++){  
                     System.out.print(x+" ");  
                }  
                System.out.println();  
           }  
           System.out.println("-----------------------------------------------");  
           for(int i=0;i<3;i++){  
                for(int j=0;i<10;j++){  
                     System.out.print(x+" ");  
                }  
                System.out.println();  
           }  
      }  
      public void snacksAndbeverages(){  
           System.out.println("--------------------- Select you Snacks And Beverages--------------------\n\n\n");  
           for(int i=0;i<5;i++){  
                System.out.println(i+1 + "----- "+BEVERAGESandPRICE[i][0]+"   ---->"+ BEVERAGESandPRICE[i][1]);            
           }  
      }  
      public void displayShowTiming(int movieSelection){  
           System.out.println("--------------------- Show Timing--------------------\n\n");  
           for(int i=0;i<showTime[movieSelection-1].length;i++){  
                     System.out.println(i+1 +"------------------ " +showTime[movieSelection-1][i]+"  ");  
                }  
                System.out.println();  
      }  
      public float calculatePrice(int movieSelection,int timeSelection){  
           moviePrice = price[movieSelection-1][timeSelection-1];  
           //System.out.println(moviePrice);  
           return moviePrice;  
      }  
      public void calculatePricesnacksAndbeverages(int Selection){  
           snacksAndbeveragesCost = Float.parseFloat(BEVERAGESandPRICE[Selection-1][1]);  
           System.out.println(snacksAndbeveragesCost);  
      }  
      public void calculatTotalcost(){  
           System.out.println("--------------------- Cost Calculation--------------------\n\n");  
           totalCost=snacksAndbeveragesCost+(moviePrice*numberOfSeat);  
           System.out.println("Movie Price X "+numberOfSeat+"="+ moviePrice);  
           System.out.println("snacks And beveragesCost ="+ snacksAndbeveragesCost);  
           System.out.println("------------------------------------------------");  
           System.out.println("Total cost ="+ totalCost);  
           System.out.println("\n\n\n\n");  
      }  
      public void displayCity(){  
           System.out.println("--------------------- City List--------------------\n\n");  
           for(int i=0;i<cityNames.length;i++){  
                     System.out.println(i+1 +"------------------ " +cityNames[i]+"  ");  
                }  
                System.out.println();  
      }  
      public void displaySeat(){  
           System.out.println("--------------------- Seat Type--------------------\n\n");  
           for(int i=0;i<seatType.length;i++){  
                     System.out.println(i+1 +"------------------ " +seatType[i]+"  ");  
                }  
                System.out.println();  
      }  
      public int entervalue(String tag){  
           System.out.println("***************Please select your "+tag+" ********************\n\n\n");  
           Scanner sc =new Scanner(System.in);  
           int value = sc.nextInt();  
           return value;  
      }  
      public static void main(String[] args) {  
           // TODO Auto-generated method stub  
           System.out.println("***************Welcome to Movie Management System********************\n\n\n");  
           Movie movie = new Movie();  
           Scanner sc =new Scanner(System.in);  
           while(true){  
                System.out.println("***************Please select ********************\n\n\n");  
                System.out.println("1  -> Movie List");  
                System.out.println("2  -> City Names");  
                System.out.println("3  -> Catagory of Seat");  
                System.out.println("4  -> Show timing");  
                System.out.println("5  -> Price and number of seat");  
                System.out.println("6  -> Snacks and beverage");  
                System.out.println("7  -> Total Expense");  
                System.out.println("8  -> Exit");  
                int value = sc.nextInt();  
                switch(value){  
                case 1:  
                     movie.displayMovieList();  
                     movieSelection=movie.entervalue("Movie");  
                     break;  
                case 2:  
                     movie.displayCity();  
                     citySelection=movie.entervalue("City");  
                     break;  
                case 3:  
                     movie.displaySeat();  
                     seatSelection=movie.entervalue("Seat");  
                     break;  
                case 4:  
                     movie.displayShowTiming(movieSelection);  
                     showSelection=movie.entervalue("Show");  
                     movie.calculatePrice(movieSelection, showSelection);  
                     break;  
                case 5:  
                     System.out.println("******* Movie Details******\n\n\n\n\n");  
                     System.out.println("Movie name is = "+movie.movieNames[movieSelection-1]);  
                     System.out.println("Movie cost = "+movie.calculatePrice(movieSelection, showSelection));  
                     movie.numberOfSeat=movie.entervalue("Number of seat");  
                     break;  
                case 6:  
                     movie.snacksAndbeverages();  
                     foodSelection=movie.entervalue("Snacks And beverages");  
                     movie.calculatePricesnacksAndbeverages(foodSelection);  
                     break;  
                case 7:  
                     movie.calculatTotalcost();  
                     break;  
                case 8:  
                     System.out.println("***********Thank You for using this system***********");  
                     System.exit(0);  
                }  
      }  
      }  
 }  



Write a program in java to accept a string in lowercase and change the first of every word to upper case. Display the new string.

 import java.util.Scanner;  
 public class Main2 {  
      public static void main(String[] args) {  
           // TODO Auto-generated method stub  
           Scanner sc = new Scanner(System.in);  
           String str = sc.nextLine();  
           int i =0;  
           StringBuffer fb = new StringBuffer(str);  
           do{  
                fb.setCharAt(0, Character.toUpperCase(fb.charAt(0)));  
                char ch = fb.charAt(i);  
                if(ch ==' '){  
                     fb.setCharAt(i+1, Character.toUpperCase(fb.charAt(i+1)));  
                }  
                i++;  
           }while(i<fb.length());  
           System.out.println(fb);  
      }  
 }  




your ad