Suppose we have a class named as Train it has two constructors, two methods, and a single attribute each of wh?
-
Suppose we have a class named as Train it has two constructors, two methods, and a single attribute each of which described as follows: • One attribute: maxSpeed – an int value representing the maximum speed of the Train object. Note: Train speed of modern Trains may be something like 250 km per hour, so a value you could use for testing purposes is 250. • Two constructors: A default constructor: A constructor that initializes the attribute ms where ms is the maxSpeed. An overloaded constructor: A constructor that takes ms as an argument, where ms is the maxSpeed. • Two methods: getMaxSpeed() – return the maxSpeed value associated with the Train object. setMaxSpeed(ms) – change the maxSpeed value associated with the Train object, where ms is the new value. • Display the value through default constructor and overloaded constructor. • Display setter value through main function.
-
Answer:
doing your homework for you won't help you learn the language. here is my rough thoughts, no compiler. public class Train{ private int maxSpeed = 250; public Train(){ } public Train(int maxSpeed){ this.maxSpeed = maxSpeed; } public int getMaxSpeed(){ return this.maxSpeed; } public void setMaxSpeed(int maxSpeed){ this.maxSpeed = maxSpeed; } } not sure what the two display notes mean
Imran Hameed ([email protected] at Yahoo! Answers Visit the source
Related Q & A:
- Is it correct to extend a bean class and write a class which holds logic to populate the bean we extend?Best solution by stackoverflow.com
- Is it unsafe to call methods from a thread?Best solution by stackoverflow.com
- how to call methods from a dll from c++?Best solution by Stack Overflow
- How to forward e-mail to a group from a single e-mail address?Best solution by Webmasters
- Can a person have more than two alleles for a single gene?Best solution by answers.yahoo.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.