Question

create a class in Java for a Plane the class will include String Data Fields for...

create a class in Java for a Plane

the class will include

String Data Fields for the make, model, and year. (as well as mutators and accessors)

Defined constructor and copy constructor.

there must be a toString method as well as a copy method.

runner program

the program will create an array for Plane class. The size of the array will be set to user input. then the user will input the information into each plane object in the array. Asking the user to enter the make, model, and year. then it will output all the planes using the tostring method

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.Plane Class

public class Plane {
   String make, model,year;

   public String getMake() {
       return make;
   }

   public void setMake(String make) {
       this.make = make;
   }

   public String getModel() {
       return model;
   }

   public void setModel(String model) {
       this.model = model;
   }

   public String getYear() {
       return year;
   }

   public void setYear(String year) {
       this.year = year;
   }

   // Constructor
   public Plane(String make, String model,
   String year)
   {
   this.make = make;
   this.model = model;
   this.year = year;
   }

   // Used to print Plane details in main()
     
   public String toString()
   {
   return "Make of Plane:"+ this.make + "Model:" + this.model + " Year:" + this.year;
   }


}

2.Main Plane Class

import java.util.Scanner;
public class PlaneMain {

   public static void main(String[] args)
   {
      
   // asking the user how many they would like to add
       int choice;
       Plane[] StArray;
       Plane p = new Plane(null, null, null);
   System.out.print("How many new Planes are you going to add: ");
   Scanner in = new Scanner(System.in);
   choice = Integer.parseInt(in.nextLine());
      
       //creating Plane array of chosen amount
   StArray = new Plane[choice];
  
       //asking user for the variables and trying to display them?
       for (int x = 1; x < StArray.length; x++)
       {
   System.out.print("Enter the Make of plane " + ": ");
   p.make = in.next();
   System.out.print("Enter the Model of plane " +": ");
   p.model = in.next();
   System.out.print("Enter the Year of plane " +": ");
   p.year = in.next();
   System.out.println(p.toString());

       }
}


Add a comment
Know the answer?
Add Answer to:
create a class in Java for a Plane the class will include String Data Fields for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Programming Language is Java 1. Create a class to describe a car. Include fields like: make,...

    Programming Language is Java 1. Create a class to describe a car. Include fields like: make, model, year and color. Add all the accessors and mutators for these fields. Add a constructor that can initialize the fields. 2. Create a class that will enable you to handle standard mail communication with a customer. Add all accessors and mutators, as well as a constructor. Add a method named fullAddress that will return the address formatted for a standard mail. Add a...

  • Create a class House with the private fields: numberOfUnits of the type int, yearBuilt of the...

    Create a class House with the private fields: numberOfUnits of the type int, yearBuilt of the type int, assessedPrice of the type double. A constructor for this class should have three arguments for initializing these fields. Add accessors and mutators for all fields except a mutator for yearBuilt, and the method toString. Create a class StreetHouse which extends House and has additional fields: streetNumber of the type int, homeowner of the type String, and two neighbors: leftNeighbor and rightNeighbor, both...

  • [JAVA] Program: Design a Ship class that the following members: A field for the name of...

    [JAVA] Program: Design a Ship class that the following members: A field for the name of the ship (a string) o A field for the year the the ship was built (a string) o A constructor and appropriate accessors and mutators A toString method that displays the ship's name and the year it was built Design a CruiseShip class that extends the Ship class. The CruiseShip class should have the following members: A field for the maximum number of passengers...

  • Write a java program that creates a class Car. Class Car contains the following private member...

    Write a java program that creates a class Car. Class Car contains the following private member fields: make, model, year, and miles. The class Car has a constructor that takes as arguments the car make, model, and year. In addition, the constructor sets miles to 100 as default. Class Car has accessors and mutators to get and set the make, model, year and miles on the car. The program should complete the following tasks: Ask the user to enter make,...

  • create a Person class with two fields (name(String), age(int)) create all the required methods such as...

    create a Person class with two fields (name(String), age(int)) create all the required methods such as the accessors, mutators, toString(),constructors etc. Use the comparable interface and implement the compareTo method such that the person objects can be compared and sorted according to their age.

  • I need this in java please Create an automobile class that will be used by a...

    I need this in java please Create an automobile class that will be used by a dealership as a vehicle inventory program. The following attributes should be present in your automobile class: private string make private string model private string color private int year private int mileage. Your program should have appropriate methods such as: default constructor parameterized constructor add a new vehicle method list vehicle information (return string array) remove a vehicle method update vehicle attributes method. All methods...

  • Design a JAVA class called Course. The class should contain: ○ The data fields courseName (String),...

    Design a JAVA class called Course. The class should contain: ○ The data fields courseName (String), numberOfStudents (int) and courseLecturer (String). ○ A constructor that constructs a Course object with the specified courseName, numberOfStudents and courseLecturer. ○ The relevant get and set methods for the data fields. ○ A toString() method that formats that returns a string that represents a course object in the following format: (courseName, courseLecturer, numberOfStudents) ● Create a new ArrayList called courses1, add 5 courses to...

  • Design a Payroll class with the following fields:

    IN JAVADesign a Payroll class with the following fields:• name: a String containing the employee's name• idNumber: an int representing the employee's ID number• rate: a double containing the employee's hourly pay rate• hours: an int representing the number of hours this employee has workedThe class should also have the following methods:• Constructor: takes the employee's name and ID number as arguments• Accessors: allow access to all of the fields of the Payroll class• Mutators: let the user assign values...

  • Equals and Copy method activity Implement a Dog class with the following features: + Attributes: ...

    Java Equals and Copy method activity Implement a Dog class with the following features: + Attributes: age, gender, weight + Method: constructor, copy constructor, equals (if same weight and gender), toString + A main method/driver that create an array of 5 Dog objects (obtain input from user), and then display the objects that are "equal" Equals and Copy method activity Implement a Dog class with the following features: + Attributes: age, gender, weight + Method: constructor, copy constructor, equals (if...

  • IN JAVA Write a class Store which includes the attributes: store name, city. Write another class...

    IN JAVA Write a class Store which includes the attributes: store name, city. Write another class encapsulating an Art Gallery, which inherits from Store. An Art Gallery has the following additional attributes: how many paintings are sold every year and the number of artists submitting artwork. Code the constructor, accessors, mutators, toString and equals method of the super class Store. Code the constructor, accessors and mutators for the subclass Art Gallery. In the Art Gallery class, also code a method...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT