OOP lab 4





SOURCE CODE:
public class car {
     Scanner s=new Scanner(System.in);
  String b_name;
   String Color;
   double new_price;
   double odometer;
   car()
   {
       input();
   }
   public void input()
   {
       System.out.println("Enter Brand:");
       b_name=s.nextLine();
       System.out.println("Enter Color:");
       Color=s.nextLine();
       System.out.println("Enter New Price:");
       new_price=s.nextInt();
       System.out.println("Enter Od0meter:");
       odometer=s.nextInt();
      
   }
   public double get_used_price()
   {
       return new_price*(1-odometer/600000);
   }
   public void update_milage(double a)
  { odometer=odometer+a;}
   public void out_display()
   {System.out.println("Brand:"+b_name);
       System.out.println("Color:"+Color);
       System.out.println("New Price:"+new_price);
       System.out.println("Odometer:"+odometer);
       System.out.println("Price After use:"+get_used_price()):}}


public class CaRmain {
     public static void main(String[] args) {
      car obj=new car();
        obj.out_display();
        obj.update_milage(10000);
        obj.out_display();
        obj.update_milage(20000);
        obj.out_display();
        // TODO code application logic here
    }}




SOURCE CODE:
public class flight {
    Scanner s=new Scanner(System.in);
    private int flight_no;
    private int aval_seats;
    private String destination;
    private String source;
    int total_seats=340;
 
    flight(int fn,int av_s,String s,String d){
        flight_no=fn;
        aval_seats=av_s;
        destination=short_and_cap(d);
        source=short_and_cap(s);
       
    }
      private String short_and_cap(String name)
    {
        if(name.length()<=3)
        {
            return name.toUpperCase();
        }
        else
        {
              return name.substring(0,3).toUpperCase();
        }
    }
    flight(int fn,int av_s)
    {
        flight_no=fn;
        aval_seats=av_s;
        destination=" ";
        source=" ";
       
    }
    flight(int fn)
    {
        flight_no=fn;
        aval_seats=0;
        destination=" ";
        source=" ";
    }
     public void setflight_no(int fn)
    {
        flight_no=fn;
    }
    public int getflight_no(){
        return flight_no;
    }
  
    public void set_avl_seats(int av_s)
    {
         aval_seats=av_s;
       
    }
    public int get_avl_seats(){
        return aval_seats;
    }
    public void set_source(String s)
    {
        source=s;
       
    }
    public String get_source(){
        return source;
    }
  
    public void set_destination(String d)
    {
         destination=d;
       
    }
    public String get_destination(){
        return destination;
    }
    public void reserve(int no_of_seats){
         if(no_of_seats<total_seats){
        aval_seats=total_seats-no_of_seats;
             System.out.println("Reserve Seats : "+no_of_seats+"\nAvalaible Seats Seats : "+aval_seats);
    }
         else
             System.out.println("There is not enough Space");
    }
    public void cancel_seats(int no_of_seats){
            if(total_seats>aval_seats&&aval_seats>no_of_seats)
            {
                System.out.println("Your seats are cancel");
                aval_seats=aval_seats+no_of_seats;
            }
            else
                System.out.println("Sorry!we cannot cancel your seat");
       
}
    public Boolean equals(flight f)
    {
        return (f.flight_no==flight_no);
    }
    public String flight_info()
    {
       return "Flight No:"+flight_no+"\nSource:"+ source+"\nDestination:"+ destination;
      
    }
    }
public class FlightMain {
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner s=new Scanner(System.in);
        flight []flght=new flight[2];
        int flt_no=0,n_seats=0;
        String dest;
        String src;
        for(int i=0;i<2;i++){
        System.out.println("Enter Data Of Flight "+(i+1)+":");
        System.out.println("Enter Flight NO:");
        flt_no=s.nextInt();
        System.out.println("Enter No of seats:");
        n_seats=s.nextInt();
        System.out.println("Enter Source:");
        src=s.next();
        System.out.println("Enter Destination:");
        dest=s.next();
        flght[i]=new flight(flt_no,n_seats,src,dest);
        flght[i].reserve(n_seats);
        }
        System.out.println("Flight 1 Info");
        System.out.println(flght[0].flight_info());
        System.out.println("Flight 2 Info");
        System.out.println(flght[1].flight_info());
    if(flght[0].equals(flght[1]).equals(true))  
    {
        System.out.println("Two Flights are Same");
    }
    else{
        System.out.println("Two Flights are not Same");}
}}

SOURCE CODE:
public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        int no_bags,l = 0,m=0,sm=0;
        final double large_box_price=1.80;
        final double medium_box_price=1.00;
        final double small_box_price=0.60;
        final double price_of_each_bag=5.50;
        System.out.println("Enter no of bags:");
        no_bags=s.nextInt();
        double total_cost_Of_order=price_of_each_bag*no_bags;
        System.out.println("Total Cost of Order:"+total_cost_Of_order);
        if(no_bags>=20)
        {
        l=no_bags/20;
        no_bags=no_bags-20*l;
        }
         if(no_bags>=10)
        {
         m=no_bags/10;
         no_bags=no_bags-10*m;

        }
          if(no_bags>=5&&no_bags<10)
        {
           m++;
        }
          if(no_bags<5)
          {
              sm++;
          }
          System.out.println("Large Boxes:"+l);
          System.out.println("Medium Boxes:"+m);
          System.out.println("Small Boxes:"+sm);
          System.out.println("Total Cost :"+(l*large_box_price+m*medium_box_price+sm*small_box_price+total_cost_Of_order));
       
        // TODO code application logic here
    } }

Comments

  1. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work... programming lab

    ReplyDelete
  2. Hey what a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you. programming lab

    ReplyDelete
  3. their is a error in code

    ReplyDelete

Post a Comment

Popular posts from this blog

Computer Programming Lab 5

Computer Programming lab 11

Computer Programming Lab 4