Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program 1. Vehicle Registration Program using netbeans .java This program will b

ID: 3804336 • Letter: P

Question

Program 1. Vehicle Registration Program using netbeans .java
This program will be used to calculate vehicle registration fees. It will include a Vehicle parent class, a Car subclass, and a Calculate interface that is implemented by the Car class. The steps are outlined below.

1. Write an interface called Calculate that includes one method - calcFee - that will calculate the registration fee for a vehicle. calcFee returns a float and doesn't take any parameters.

2. Create a class called Vehicle. This class contains the following attributes:

owner (String)
regNumber (int)

The Vehicle class contains methods to set/get owner and regNumber. Its constructor should initialize all variables to 0 or "" (depending on type). Vehicle will have subclasses.

3. Create a subclass of Vehicle called Car that implements the Calculate interface. Car should have additional attributes of:

make (String)
model (String)
regType (String - values will be either "new" or "renew")
regFee (float)

In addition to the get/set methods for make, model, and regType, include the method calcFee, to calculate the registration fee according to the following conditions:

if regType = renew, then the fee is $36
else if regType = new, then the fee is $58.50

NOTE: To compare two strings in Java, use the "equals" method rather than ==; e.g., if (string1.equals(string2))

When getting input from the user using sc.nextInt() (this assumes that you named your Scanner object "sc"), there will be a newline left in the buffer. Simply put the statement sc.nextLine() after your sc.nextInt() statement to clear the newline from the buffer.

4. In your main class for the program, create a car object called myCar (be sure and include make, model, and registration type [either new or renew] in the constructor call statement). Get the following input from the user:

    owner name
    registration number
    make
    model
    registration type

Calculate the registration fee, then display the owner name, registration number, registration type, and registration fee.

NOTE: The following statement will print the result of the calcFee() method with two decimal places (and go to a new line):

System.out.format("Amount: $ %.2f%n", myCar.calcFee());

Explanation / Answer

// interface
public interface Calculate {
   public float calcFee();
}

// class


public class Vehicle {
  
   private String onwer_name;
   private int reg_number;
  
   Vehicle()
   {
      ;
       reg_number = 0;
   }
  
   public void setOwner(String str)
   {
          
   }
  
   public void setRegNumber(int reg)
   {
       reg_number = reg;
   }

   public String getOwner()
   {
       return onwer_name;
   }

   public int getRegNumber()
   {
       return reg_number;
   }
}

// class


public class Car extends Vehicle implements Calculate{
   private String make;
   private String model;
   private String regType;
   private float regFee;
  
//   public Car(String own, int reg)
   public Car(String pmake, String pmodel, String ptype)
   {
       super();
       make = pmake;
       model = pmodel;
       regType = ptype;              
   }
  
   public void setMake(String s1)
   {
       make = s1;
   }
  
   public void setModel(String s1)
   {
       model = s1;
   }
  
   public void setregType(String s1)
   {
       regType = s1;
   }
  
   public String getMake()
   {
       return make;
   }
  
   public String getModel()
   {
       return model;
   }
  
   public String getregType()
   {
       return regType;
   }
  
   public float calcFee()
   {
       if(regType.equals("renew"))
       {
           regFee = 36;
       }
      
       else if(regType.equals("new"))
       {
           regFee = (float)58.50;
       }
       return regFee;
   }
}

// Main Class

import java.util.Scanner;

public class MainClass {
   public static void main(String args[])
   {
       Car myCar = new Car("Toyota", "Etios","new");
       //System.
       System.out.println("Enter owner name: ");
       Scanner sc = new Scanner(System.in);
       String owner_name = sc.nextLine();
       System.out.println("Enter reg number: ");
       int reg_num = sc.nextInt();
       System.out.println("Enter car make: ");
       String make_n = sc.next();
       System.out.println("Enter car model: ");
       String model_n = sc.next();
       System.out.println("Enter car reg type: ");
       String reg_t = sc.next();
      
       myCar.setOwner(owner_name);
       myCar.setRegNumber(reg_num);
       myCar.setMake(make_n);
       myCar.setModel(model_n);
       myCar.setregType(reg_t);
       myCar.calcFee();
       System.out.println("Owner Name: " +myCar.getOwner());
       System.out.println("Registration Number: " +myCar.getRegNumber());
       System.out.println("Registration Type: " +myCar.getregType());
       System.out.format("Amount: $ %.2f%n", myCar.calcFee());
       sc.close();
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote