Slip29

 Q1) Write a program to create a class Customer(custno,custname,contactnumber,custaddr). Write a method to search the customer name with given contact number and display the details. [10 marks] 

import java.util.*;

class Customer 

{

    int custno;

    String custname,contactnumber,custaddr;

    public Customer(int custno, String custname, String contactnumber, String custaddr) {

        this.custno = custno;

        this.custname = custname;

        this.contactnumber = contactnumber;

        this.custaddr = custaddr;

    }

    public void displayDetails() 

    {

        System.out.println("Customer Number: " +  custno);

        System.out.println("Customer Name: " + custname);

        System.out.println("Contact Number: " + contactnumber);

        System.out.println("Customer Address: " + custaddr);

    }

    public static void searchCustomer(Customer[] c,String cno) 

    {

boolean flag=false;

        for (Customer ctemp : c) {

            if (ctemp.contactnumber.equals(cno))

    { 

flag=true;

                ctemp.displayDetails();

break;

    }

            }

if(!flag)

        System.out.println("Customer Not Found");

        }

        

    }

class Slip29_2

{

    public static void main(String[] args) 

    {

        Customer[] cList = new Customer[3];     

        cList[0] = new Customer(1, "aaaa", "1234567890", "123 Elm St");

        cList[1] = new Customer(2, "bbbb", "0987654321", "456 Oak St");

        cList[2] = new Customer(3, "cccc", "5555555555", "789 Pine St");

        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter contact number to search for customer: ");

        String contactnumber = scanner.nextLine();

        Customer.searchCustomer(cList,contactnumber);

        scanner.close();

    }

}

Q2) Write a program to create a super class Vehicle having members Company and price. Derive two different classes LightMotorVehicle(mileage) and HeavyMotorVehicle (capacity_in_tons). Accept the information for "n" vehicles and display the information in appropriate form. While taking data, ask user about the type of vehicle first. [20 marks]

import java.io.*;

class Vehicle

{

int price;

String company;

   Vehicle(String c,int p)

   {

       company=c;

       price=p;

   }

   public void display()

   {

System.out.print("Company : "+company+"\tPrice : "+price);

   }

}

class LightMotorVehicle extends Vehicle

{

   int mileage;

   LightMotorVehicle(String c,int p,int m) 

   {

super(c,p);

        mileage=m;

   }

    public void display()

   {

super.display();

System.out.println("\tMileage : "+mileage);

   }

}

class HeavyMotorVehicle extends Vehicle

{

   int cap_in_tons;

   HeavyMotorVehicle(String c,int p,int cap) 

   {

super(c,p);

        cap_in_tons=cap;

   }

    public void display()

   {

super.display();

System.out.println("\tCapacity_in_tons : "+cap_in_tons);

   }

}  

class Ass3_SetA3

{       

        public static void main(String args[]) throws IOException

        {

                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

                System.out.println("Enter Total No. Vehicles");

                int n=Integer.parseInt(br.readLine());

Vehicle[] c=new Vehicle[n];           

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

{

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

String com=br.readLine();

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

    int p=Integer.parseInt(br.readLine());        

    System.out.println("Enter 1:Light Motor Vehicle  2: Heavy Motor Vehicle");

    int ch=Integer.parseInt(br.readLine());

switch(ch)

    {

case 1:

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

              int m=Integer.parseInt(br.readLine());

                                 c[i]=new LightMotorVehicle(com,p,m);         

break;

case 2:

System.out.println("Enter Capacity in tons");

        int cap=Integer.parseInt(br.readLine());                   

                        c[i]=new HeavyMotorVehicle(com,p,cap);

                        break;

   }

}

System.out.println("---------------Vehicle Information---------------");

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

   c[i].display();                             

        }        

}

Comments

Popular posts from this blog

Slip1

Slip3

Slip2