practice-program-2

Create a class Car and make any three methods?class should have variable and constructor?

package webprograms;

import java.util.Scanner;

/**
Create a class Car and make any three methods? class should have variable and constructor?
 */
public class car 
{
    public int speed;
    public int price;
    public String model;

    public car() {
        this.speed =0;
        this.price = 0;
        this.model = "";
    }
     public car(int speed) {
        this.speed = speed;
        this.price = 0;
        this.model = "";
    }
      public car(int speed, int price) {
        this.speed = speed;
        this.price = price;
        this.model = "";
    }
       public car(int speed, int price, String model) {
        this.speed = speed;
        this.price = price;
        this.model = model;
    }
      
       void Speed()
       {
           Scanner input=new Scanner(System.in);
           System.out.println("Enter Speed");
           this.speed=input.nextInt();
           
           System.out.println("Speed is "+this.speed);
       }
        void Price()
       {
           Scanner input=new Scanner(System.in);
           System.out.println("Enter Price");
           this.price=input.nextInt();
           
           System.out.println("Price is "+this.price);
       }
         void Model()
       {
           Scanner input=new Scanner(System.in);
           System.out.println("Enter Model");
           this.model=input.next();
           
           System.out.println("Model is "+this.model);
       }
}


Previous Lecture                                                                                                                    Next lecture