Question

JAVA question: Please see the code posted below and improve it so it allows for: 1.new...

JAVA question:

Please see the code posted below and improve it so it allows for:

1.new aircraft are entered [new objects]

2.these objects are automatically be assigned their unique IDs [unique ID linked to a static class variable?]

3.will not be automatically given airport codes [initialise airportCode as null in the constructor]

4.assign an airport code to each new aircraft [an object method?]

The code:

class Aeroplane
{
static int planeCount = 0;
static int codeGenerator = 0;
int uniqueID = 0;
String location = "null";

//assuming all the aeroplane entered into the system are flying.
Aeroplane (){
planeCount = planeCount + 1;
uniqueID = planeCount + 1;
}
String assign_code (){
codeGenerator = codeGenerator + 1;
String Aeroplanecode = "A" + codeGenerator;
return Aeroplanecode;
}
}

public class markedEx6{
public static void main (String[]args){
Aeroplane a1 = new Aeroplane ();
Aeroplane a2 = new Aeroplane ();
Aeroplane a3 = new Aeroplane ();

System.out.println (" Aeroplane 1 ID: " + a1.assign_code () +
" and location is: " + a1.location +
"\n Aeroplane 2 ID: " + a2.assign_code () +
" and location is: " + a2.location +
"\n Aeroplane 3 ID: " + a3.assign_code () +
" and location is: " + a3.location);
System.out.println (a1.planeCount);
}
}

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

code:

class Aeroplane
{
static int planeCount = 0;
static int codeGenerator = 0;
int uniqueID = 0;
String location = "null";

//assuming all the aeroplane entered into the system are flying.
Aeroplane (){
planeCount = planeCount + 1;
uniqueID = planeCount + 1;
}
String assign_code (){
codeGenerator = codeGenerator + 1;
String Aeroplanecode = "A" + codeGenerator;
return Aeroplanecode;
}
}
class newAeroplane{
    static int count=0;
    int uniqueID=0;
    String airportcode;
    newAeroplane(){     //making airportcode null
        airportcode="null";
    }
    public String assignAirportcode(){   //assigning airportcode
        count=count+1;
        uniqueID=count+1;
        airportcode="2"+uniqueID;
        return airportcode;    //return airportcode
    }
}
public class markedEx6{
public static void main (String[]args){
Aeroplane a1 = new Aeroplane ();
Aeroplane a2 = new Aeroplane ();
Aeroplane a3 = new Aeroplane ();
newAeroplane a4=new newAeroplane();
System.out.println (" Aeroplane 1 ID: " + a1.assign_code () +
" and location is: " + a1.location +
"\n Aeroplane 2 ID: " + a2.assign_code () +
" and location is: " + a2.location +
"\n Aeroplane 3 ID: " + a3.assign_code () +
" and location is: " + a3.location);
System.out.println (a1.planeCount);
System.out.println("newAeroplane ID:"+ a4.uniqueID +"and airportcode is:"+a4.assignAirportcode() );
}
}

output:

Add a comment
Know the answer?
Add Answer to:
JAVA question: Please see the code posted below and improve it so it allows for: 1.new...
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
  • FOR JAVA: Summary: Create a program that adds students to the class list (see below). The...

    FOR JAVA: Summary: Create a program that adds students to the class list (see below). The solution should be named Roster402_v2.java. Allow the user to control the number of students added to the roster. Ask if the user would like to see their new roster to confirm additions. If yes, then display contents of the file, if no, end the program. ------------------------------------------------------------------------------------- List of student names and IDs for class (this will be your separate text file): Jones, Jim,45 Hicks,...

  • JAVA- Complete the code by following guidelines in comments. class CircularList { private Link current; private...

    JAVA- Complete the code by following guidelines in comments. class CircularList { private Link current; private Link prev; public CircularList() { // implement: set both current and prev to null } public boolean isEmpty() { // implement return true; } public void insert(int id) { // implement: insert the new node behind the current node } public Link delete() { // implement: delete the node referred by current return null; } public Link delete(int id) { // implement: delete the...

  • Problem 1 Given a linked list of integers, write a function getUnique that removes all duplicates elements in the linked list and returns the new linked list of unique elements (The order does not ma...

    Problem 1 Given a linked list of integers, write a function getUnique that removes all duplicates elements in the linked list and returns the new linked list of unique elements (The order does not matter). Example: Input: 1-»2->3->1-2 Output: 1->2->3 public class Node f int iterm Node next; Node(int d) t item = d; next-null; ) import java.util.ArrayList; public class ExtraLab public static void main (String[] args)t PROBLEM 1 System.out.println("PROBLEM 1"); Node head new Node(1); head.next-new Node (2); head.next.next-new Node(3);...

  • What is wrong with the following Java Code. public class TestEdible { abstract class Animal {...

    What is wrong with the following Java Code. public class TestEdible { abstract class Animal { /** Return animal sound */ public abstract String sound(); } class Chicken extends Animal implements Edible { @Override public String howToEat() { return "Chicken: Fry it"; } @Override public String sound() { return "Chicken: cock-a-doodle-doo"; } } class Tiger extends Animal { @Override public String sound() { return "Tiger: RROOAARR"; } } abstract class Fruit implements Edible { // Data fields, constructors, and methods...

  • Below, you can find the description of your labwork for today. You can also find the...

    Below, you can find the description of your labwork for today. You can also find the expected output of this code in the Application Walkthrough section. You are going to improve your existing Money & Stock Trading Platform on previous week’s labwork by incorporating Collections. In previous labworks, you have used arrays for holding Customer and Item objects. For this labwork you need to use ArrayList for holding these objects. So, rather than defining Customer[] array, you need to define...

  • the answer must be in java. thank you Question 2 [8 points] Consider the class Class...

    the answer must be in java. thank you Question 2 [8 points] Consider the class Class A below: class Class A implements Serializable{ int a; static int b; transient int c; String s; // Constructor public Class A (int a, int b, int c, Strings){ this.a = a; this.b = b; this.c = c; this.s = s; Complete the class Test to test the serialization and deserialization of the objects of class Class A. State the possible variable values following...

  • 1. What is output by the following code: ArrayList< Integer > a = new ArrayList< Integer...

    1. What is output by the following code: ArrayList< Integer > a = new ArrayList< Integer >(); ArrayList b = a; a.add(new Integer(4)); b.add(new Integer(5)); a.add(new Integer(6)); a.add(new Integer(7)); System.out.println(b.size()); A)1 B)2 C)3 D)4 E)5 2. Assume the Student and Employee classes each extend the Person class. The Student class overrides the getMoney method in the Person class. Consider the following code:     Person p1, p2, p3;     int m1, m2, m3;     p1 = new Person();     m1 = p1.getMoney();     // assignment 1...

  • Write an application that displays a series of at least five student ID numbers (that you...

    Write an application that displays a series of at least five student ID numbers (that you have stored in an array) and asks the user to enter a numeric test score for the student. Create a ScoreException class, and throw a ScoreException for the class if the user does not enter a valid score (less than or equal to 100). Catch the ScoreException, display the message Score over 100, and then store a 0 for the student’s score. At the...

  • Java - Car Dealership Hey, so i am having a little trouble with my code, so...

    Java - Car Dealership Hey, so i am having a little trouble with my code, so in my dealer class each of the setName for the salesman have errors and im not sure why. Any and all help is greatly appreciated. package app5; import java.util.Scanner; class Salesman { private int ID; private String name; private double commRate; private double totalComm; private int numberOfSales; } class Car { static int count = 0; public String year; public String model; public String...

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