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

  • Home
  • SEARCH
  • 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 7804727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:00:52+00:00 2026-06-02T02:00:52+00:00

I’m making a class with another separate driver class. The car class is for

  • 0

I’m making a class with another separate driver class. The car class is for a Car Hire Company to store the information about the car like the make, model and registration number, so that using the driver class I can use to input new vehicles, check if a vehicle is on hire and unavailable and name of hirer if it is hired.

My car class with methods:

public class Car {

private String Make;
private String Model;
private int RegistrationNum;

public Car(String Make, String Model, String RegN){
    //Constructor,
    //stores the make, model and registration number of the new car
    //sets its status as available for hire.
    Make = "";
    Model = "";
    RegN = "";

}

public String getMake(){
    return Make;

}

public String getModel(){
    return Model;

}

public boolean hire(String newHirer){

    {
  //Hire this car to the named hirer and return true. 

        return true;
    }
  //Returns false if the car is already out on hire.



}

public boolean returnFromHire(){

    {
 //Receive this car back from a hire and returns true.
        return true;
    }

 //Returns false if the car was not out on hire     


}

public int getRego(){


 //Accessor method to return the car’s registration number      

    RegistrationNum++;
    return RegistrationNum;
    }



public boolean hireable(){
 //Accessor method to return the car’s hire status.     



    {
 //returns true if car available for hire           
    return true;    
    }
}

public String toString(){
 //return car details as formatted string
 //output should be single line containing the make model and reg number
 //followed by either "Available for hire" or "On hire to: <name>"


    return "Vehicle ID number: "+ getRego()+"-"+"Make is: "+ getMake()+"-"+"Model is: "+getModel();


}


}

Following is my Driver class:

  import java.util.*;
  public class CarDriver {
  static Car car1;

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner scan = new Scanner(System.in);


{
    System.out.println("Make?");
    String Make=scan.nextLine();
    System.out.println("Model");
    String Model=scan.nextLine();
    System.out.println("Registration number?");
    String RegNum=scan.nextLine();

    car1 = new Car(Make,Model,RegNum);


    System.out.println("What you input :");

    System.out.println(car1.toString());
}}

 }

my output:

Make?
carmake
Model
carmodel
Registration number?
12345t
What you input :
Vehicle ID number: 1-Make is: null-Model is: null

Problems:

  1. unable to understand how to convert the pseudocode for the
    boolean methods into java codes

  2. unable to connect the driver
    class to store the information that I input, like the model, make
    and registration number

  • 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-02T02:00:54+00:00Added an answer on June 2, 2026 at 2:00 am

    2nd

    Change constructor to this one:

    public Car(String Make, String Model, String RegN){
        this.Make = Make;
        this.Model= Model;
        this.RegN = RegN;
    }
    

    Your previous contructor had a problem, basically all you did was that you get the constructor arguments and set all of them to “” (empty string), you dont want to do that. You want to assign argument values to your instance fields. If you want to access instance fields you have to use keyword this.

    public Car(String Make, String Model, String RegN){
    //Constructor,
    //stores the make, model and registration number of the new car
    //sets its status as available for hire.
    Make = "";
    Model = "";
    RegN = "";
    

    }

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.