Create a Motorway class that can be used as extra documentat

Create a Motorway class that can be used as extra documentation with directions. Include data members such as name of the highway, type of street (i.e., Road, Street, Avenue, Blvd., Lane, etc), direction (i.e.; E, W, N, or S), Surface (i.e.; blacktop, gravel, sand, and concrete), number of lanes, toll or not toll, and the party that maintains it. Write instance methods that return the full name of the motorway, full name of the motorway and whether it is toll or not, and full name of the motorway and the numbers of lanes. Also include a Tostring() method that returns all data members with appropriate labels. Include enough constructors to make the class flexible, and experiment with using the class diagram to create the property members. In a second class test the constructors, instance methods, and properties defined in the Motorway class.

Solution


package motorwayapplication;

import java.util.Scanner;

class Motorway
{
String nameOfTheHighway;
String typeOfStreet;//Road, Street, Avenue, Blvd., Lane, etc
String direction;//E, W, N, or S
String surface;// blacktop, gravel, sand, and concrete
int numberOfLanes;
boolean isToll;
String maintainingParty;
public Motorway(String name, String street, String d,String s, int n, boolean tollStatus, String party)
{
this.nameOfTheHighway=name;
this.typeOfStreet=street;
this.direction=d;
this.surface=s;
this.numberOfLanes=n;
this.isToll=tollStatus;
this.maintainingParty=party;
}
public String getFullNameOfMotorway()
{
return nameOfTheHighway+\" \"+typeOfStreet+\" \"+direction;
}
public String getFullNameOfMotorwayWithTollstatus()
{
return getFullNameOfMotorway()+\" \"+isToll;
}
public String getFullNameOfMotorwayWithNumLanes()
{
return getFullNameOfMotorway()+\" \"+numberOfLanes;
}
public String Tostring()
{
String msg=\"Name of the Highway: \"+nameOfTheHighway;
msg+=\" Type of Street: \"+typeOfStreet;
msg+=\" Direction: \"+direction;
msg+=\" Surface: \"+surface;
msg+=\" Number of lanes: \"+numberOfLanes;
msg+=\" Toll availability: \"+isToll;
msg+=\" Maintaining party: \"+maintainingParty;
return msg;
}
}


public class MotorwayApplication {

public static void main(String[] args) {
Scanner input=new Scanner(System.in);
String name, street, d, s, party;
int n;
boolean tollStatus;
System.out.println(\"Enter the highway name: \");
name=input.nextLine();
System.out.println(\"Enter the type of street: \");
street=input.nextLine();
System.out.println(\"Enter the direction: \");
d=input.nextLine();
System.out.println(\"Enter the surface: \");
s=input.nextLine();
System.out.println(\"Enter the number of lanes: \");
n=input.nextInt();
System.out.println(\"Is toll is on the highway? \");
tollStatus=input.nextBoolean();
System.out.println(\"Enter the maintaining party name: \");
party=input.nextLine();
Motorway motorway=new Motorway(name,street,d,s,n,tollStatus,party);
  
System.out.println(\"Motorway fullname:\" +motorway.getFullNameOfMotorway());
System.out.println(\"Motorway fullname and tollstatus:\" +motorway.getFullNameOfMotorwayWithTollstatus());
System.out.println(\"Motorway fullname and number of lanes:\" +motorway.getFullNameOfMotorwayWithNumLanes());
System.out.println(\"Motorway description:\" +motorway.Tostring());
  
}
}

Create a Motorway class that can be used as extra documentation with directions. Include data members such as name of the highway, type of street (i.e., Road, S
Create a Motorway class that can be used as extra documentation with directions. Include data members such as name of the highway, type of street (i.e., Road, S

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site