Question

In: Computer Science

Please give me an example of this java code. Vehicle - number: int - color: String...

Please give me an example of this java code.

Vehicle

- number: int

- color: String

- price: double

- horsepower: double

+ Vehicle ( )

+ Vehicle (int number)

+ Vehicle (int number, String color)

+ Vehicle (int number, String color, double price)

+ Vehicle (int number, String color, double price, double horsepower)

+getnumber( ):int

+setnumber(int number):void

+getcolor( ):String

+setcolor(String color):void

+getprice( ):double

+setprice(double price):void

+gethorsePower( ):double

+sethorsePower(double horsePower):void

toString( ):String

public String toString( )

{

return "\n\n number = " + number

+ "\n color = " + color

+ "\n price = " + price

+ "\n horsePower = " + horsePower;

public class VehicleTester

{

public static void main(String[] args)

{

Vehicle nissan1 = new Vehicle( );

nissan1.vehicleInformation( );

System.out.println(nissan1.toString( ));

}

}

Solutions

Expert Solution

class Vehicle {
   private int number;
   private String color;
   private double price;
   private double horsepower;

   Vehicle() {

   }

   public Vehicle(int aNumber) {
       super();
       number = aNumber;
   }

   public Vehicle(int aNumber, String aColor) {
       super();
       number = aNumber;
       color = aColor;
   }

   public Vehicle(int aNumber, String aColor, double aPrice) {
       super();
       number = aNumber;
       color = aColor;
       price = aPrice;
   }

   public Vehicle(int aNumber, String aColor, double aPrice, double aHorsepower) {
       super();
       number = aNumber;
       color = aColor;
       price = aPrice;
       horsepower = aHorsepower;
   }

   public int getNumber() {
       return number;
   }

   public void setNumber(int aNumber) {
       number = aNumber;
   }

   public String getColor() {
       return color;
   }

   public void setColor(String aColor) {
       color = aColor;
   }

   public double getPrice() {
       return price;
   }

   public void setPrice(double aPrice) {
       price = aPrice;
   }

   public double getHorsepower() {
       return horsepower;
   }

   public void setHorsepower(double aHorsepower) {
       horsepower = aHorsepower;
   }

   public String toString()

   {

       return "\n\n number = " + number

               + "\n color = " + color

               + "\n price = " + price

               + "\n horsePower = " + horsepower;
   }

   public void vehicleInformation() {
       System.out.println(this);
   }
}

public class VehicleTester

{

   public static void main(String[] args)

   {

       Vehicle nissan1 = new Vehicle();

       nissan1.vehicleInformation();

       System.out.println(nissan1.toString());

   }

}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

JAVA JAVA JAVA . I need to convert a string input to int array, for example...
JAVA JAVA JAVA . I need to convert a string input to int array, for example if user enters 12 / 27 / 2020 , I want to store each value in a separate array and add them afterwards.
Could you please also give me a code that does not use the string split method...
Could you please also give me a code that does not use the string split method but instead gives an input and output file that you have to compile using "type output.txt" in java. This is the code: Record.java public class Record { private String stateCode, districCode, districtName; private int totalPopulation, childPopulation, childPovertyPopulation; private String miscStats; public Record(String stateCode, String districCode, String districtName, int totalPopulation, int childPopulation, int childPovertyPopulation, String miscStats) { this.stateCode = stateCode; this.districCode = districCode; this.districtName =...
int bintodec(string); // converts a binary number (represented as a STRING) to decimal int hextodec(string); //...
int bintodec(string); // converts a binary number (represented as a STRING) to decimal int hextodec(string); // converts a hexadecimal number (represented as a STRING) to decimal string dectobin(int); // converts a decimal number to binary (represted as a STRING) string dectohex(int); // converts a decimal number to hexadecimal (represted as a STRING) //the addbin and addhex functions work on UNsigned numbers string addbin(string, string); // adds two binary numbers together (represented as STRINGS) string addhex(string, string); // adds two hexadecimal...
Please write code in java and comment . thanksItem classA constructor, with a String...
Please write code in java and comment . thanksItem classA constructor, with a String parameter representing the name of the item.A name() method and a toString() method, both of which are identical and which return the name of the item.BadAmountException ClassIt must be a RuntimeException. A RuntimeException is a subclass of Exception which has the special property that we wouldn't need to declare it if we need to use it.It must have a default constructor.It must have a constructor which...
Please write code in java and comment . thanks Item class A constructor, with a String...
Please write code in java and comment . thanks Item class A constructor, with a String parameter representing the name of the item. A name() method and a toString() method, both of which are identical and which return the name of the item. BadAmountException Class It must be a RuntimeException. A RuntimeException is a subclass of Exception which has the special property that we wouldn't need to declare it if we need to use it. It must have a default...
For Questions 1-3: consider the following code: public class A { private int number; protected String...
For Questions 1-3: consider the following code: public class A { private int number; protected String name; public double price; public A() { System.out.println(“A() called”); } private void foo1() { System.out.println(“A version of foo1() called”); } protected int foo2() { Sysem.out.println(“A version of foo2() called); return number; } public String foo3() { System.out.println(“A version of foo3() called”); Return “Hi”; } }//end class A public class B extends A { private char service; public B() {    super();    System.out.println(“B() called”);...
please give me a long example about " impulse" and a long example about "momentum" PLEASE...
please give me a long example about " impulse" and a long example about "momentum" PLEASE DONT COPY AND PASTE ANYTHING FROM THE INTERNET. give me an example from your own. thank you
Java and please have screenshots with source code and output \item[(1)] A palindrome is a string...
Java and please have screenshots with source code and output \item[(1)] A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the string is read from standard input one character at a time. The algorithm should output true or false as...
(JAVA) InvertArrangement +invert(int[] a) : int [] +print(int[] a) : void Example 1: the invert method...
(JAVA) InvertArrangement +invert(int[] a) : int [] +print(int[] a) : void Example 1: the invert method receives the following arrangement: [1,2,3,4,5] The invert method returns the array [5,4,3,2,1] Example 2: the print method receives the following array: [5,4,3,2,1] The print method prints: 5,4,3,2,1 (data separated by commas). TIP: for the print method use System.out.print () without the "ln".
Write a java method that takes a string and returns an array of int that contains...
Write a java method that takes a string and returns an array of int that contains the corresponding alphabetic order of each letter in the received string: An illustration: the method takes: "Sara" the method returns: {4,1,3,2} another illustration: the method takes: "hey" the method returns: {2,1,3}
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT