Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9173219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:32:18+00:00 2026-06-17T16:32:18+00:00

I’m supposed to make a program that has MotorVehicle abstract class. Car , Truck

  • 0

I’m supposed to make a program that has MotorVehicle abstract class. Car, Truck, Van are kinds of MotorVehicle. The setTerms() and displayInfo() are the only abstract. Car has String transType and void Car(), Van has int numPassenger and void Van(), as Truck has double payLoad and void Truck().

The output should be like this:

Brand is Mazda

Vehicle type is Sedan

Color is Red

Transmission type is Automatic

Price is 840000.0

Terms is 5 years to pay

Brand is Isuzu

Vehicle type is Truck

Color is White

Payload capacity is 3.5

Price is 910000.0

Terms is 3 years to pay

Brand is Mitsubishi

Vehicle type is Family Van

Color is Blue

Number of passenger is 8

Price is 1050000.0

Terms is 7 years to pay

But my program doesn’t still produce this output

Here’s my current codes:

public abstract class MotorVehicle
{
    private String vehicleType;
    private String brand;
    private String color;
    private String terms;

    public MotorVehicle(String vcl, String brn, String clr, String trm)
    {
        vehicleType = vcl;
        brand = brn;
        color = clr;
        terms = trm;
    }

    public String getVehicleType()
    {
        return vehicleType;
    }

    public String getBrand()
    {
        return brand;
    }

    public String getColor()
    {
        return color;
    }

    public abstract void setTerms();

    public abstract void displayInfo();

}

//=========================================

public class Car extends MotorVehicle
{
    String transType="";
    String vehicleType;
        String brand;
    String color;
    String terms;
    int price = 0;

    public Car(String vcl, String brn, String clr, String trm)
    {
        super(vcl, brn, clr, trm);
        vehicleType = vcl;
        brand = brn;
        color = clr;
        terms = trm;
    }

    public void Car()
    {
        brand = "Mazda";
        vehicleType = "Sedan";
        color = "Red";
        transType = "Automatic";
        price = (int) (700000 + (700000*0.2));
        Double.toString(price);
        terms = "5";   
    }

    public void setTerms()
    {
         return;
    }

    public void displayInfo()
    {
        System.out.println("Brand is " + brand);
        System.out.println("Vehicle type is " + vehicleType);
        System.out.println("Color is " + color);
        System.out.println("Transmission type is " + transType);
        System.out.println("Price is " + price);
        System.out.println("Terms is " + terms + " years to pay");
    }

}

//=================================

public class Truck extends MotorVehicle
{
    double payLoad=0.0;
    String vehicleType;
        String brand;
    String color;
    String terms;
    int price = 0;

    public Car(String vcl, String brn, String clr, String trm)
    {
        super(vcl, brn, clr, trm);
        vehicleType = vcl;
        brand = brn;
        color = clr;
        terms = trm;
    }

    public void Truck()
    {
        brand = "Isuzu";
        vehicleType = "Truck";
        color = "White";
        payLoad = 3.5;
        Double.toString(payLoad);
        price = (int) (700000 + (700000*0.3));
        Double.toString(price);
        terms = "3";     
    }

    public void setTerms()
    {
         return;
    }

    public void displayInfo()
    {
        System.out.println("Brand is " + brand);
        System.out.println("Vehicle type is " + vehicleType);
        System.out.println("Color is " + color);
        System.out.println("Payload capacity is " + payLoad);
        System.out.println("Price is " + price);
        System.out.println("Terms is " + terms + " years to pay");
    }   


 }

//==========================

public class Van extends MotorVehicle
{
    int numPassenger=0;
    String vehicleType;
        String brand;
    String color;
    String terms;
    int price=0;

    public Van(String vcl, String brn, String clr, String trm)
    {
            super(vcl, brn, clr, trm);
        vehicleType = vcl;
        brand = brn;
        color = clr;
        terms = trm;
    }

    public void Van()
    {
    brand = "Mitsubishi";
    vehicleType = "Family Van";
    color = "Blue";
    numPassenger = 8;
    String.valueOf(numPassenger);
    price = (int) (700000 + (700000*0.5));
    Double.toString(price);
    terms = "7";   
}

public void setTerms()
{
     return;
}

public void displayInfo()
{
    System.out.println("Brand is " + brand);
    System.out.println("Vehicle type is " + vehicleType);
    System.out.println("Color is " + color);
    System.out.println("Number of passenger is " + numPassenger);
    System.out.println("Price is " + price);
    System.out.println("Terms is " + terms + " years to pay");
}

}

//===================

And this is the main program:

public class MainVehicle 
{
    public static void main(String[] args)
    {
        BBVehicle[] vhl= new BBVehicle[3];

        int ctr=0;
        while(ctr<3)
        {
            if (ctr==0)
                vhl[ctr]=new Car();
            else if(ctr==1)
                vhl[ctr]= new Truck();
            else
                vhl[ctr]= new Van();
            vhl[ctr].displayInfo();
            ctr++;
        }
     }

}

I’m not sure with what’s wrong with my program. help me please thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:32:20+00:00Added an answer on June 17, 2026 at 4:32 pm

    i)

    public void Car()
    public void Truck()
    public void Van()
    

    You are defining return type of Class Contructor

    it should be

    public Car()
    public Truck()
    public Van()
    

    A constructor resembles an instance method, but it differs from a method in that it has no explicit return type, it is not implicitly inherited and it usually has different rules for scope modifiers.

    ii) Define a no-argument constructor in the abstract class (From the comment)

    iii)

        BBVehicle[] vhl= new BBVehicle[3];
    
        int ctr=0;
        while(ctr<3)
        {
            if (ctr==0)
                vhl[ctr]=new Car();
    

    You are casting Car class to BBVehicle class. Although, both class are different. There is no relation between these two class..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.