Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a Java Car class
    primarykey
    data
    text
    <p>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.</p> <p>My car class with methods:</p> <pre><code>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: &lt;name&gt;" return "Vehicle ID number: "+ getRego()+"-"+"Make is: "+ getMake()+"-"+"Model is: "+getModel(); } } </code></pre> <p>Following is my Driver class:</p> <pre><code> 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()); }} } </code></pre> <p>my output:</p> <pre><code>Make? carmake Model carmodel Registration number? 12345t What you input : Vehicle ID number: 1-Make is: null-Model is: null </code></pre> <p>Problems:</p> <ol> <li><p>unable to understand how to convert the pseudocode for the boolean methods into java codes </p></li> <li><p>unable to connect the driver class to store the information that I input, like the model, make and registration number</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload