Question

2 (4 marks): Complete the missing code in the following classes ublic class Hero private int pos; /*4.1 write the constructor*/ pos 11; blic class Fish private doubel wight; m. /*4.2 write setter for pos*/ setWight ( w ){ wight = w; blic class Pen /*4.3 write 2 perperties of Pen:- color: could be red, green, pink .etc ink: amount of left ink in percent, like 88, 10, 99, ..etc private private Th lic class Account private doubel Balance; /*4.4 Write deposite method*/ public void Deposite( amountt Balance =


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

public class Hero
{
private int pos;
// Constructor
public Hero()
{
pos=11;
}
}



-------------------------------------------
public Fish
{
private double wight;
//Setter Method for Fish Class
public void setweight(double w)
{
wight=w;
}
}

--------------------------------------------

public class Pen
{
//Properties of Pen class
private String color;
private int ink;
}
---------------------------------------------
public class Account
{
private double balance;
//Deposit Method
public void deposit(double amount)
{
balance=balance+amount;
}
}

Add a comment
Know the answer?
Add Answer to:
Complete the missing code in the following classes class Hero private int pos: /*4.1 write the...
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
  • The Account class Create a class named Account, which has the following private properties: number: long...

    The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement these methods: void deposit(double amount) and void withdraw(double amount). For both these methods,...

  • Question: Write the Main class code for the following application. The first three classes are given...

    Question: Write the Main class code for the following application. The first three classes are given below. Lottery This lottery app allows users to sign up for an account, choose a random number or two, and then win a certain amount of money if their chosen number matches the number that the game draws. The house keeps the cash proceeds if nobody wins. The app must repeatedly do the following: Allow the user to (1) Add Player Account (2) Play...

  • please write in c++. 4 Derived class JPG 4.1 Class declaration • The class JPG inherits...

    please write in c++. 4 Derived class JPG 4.1 Class declaration • The class JPG inherits from File and is a non-abstract class. 1. Hence objects of the class JPG can be instantiated. 2. To do so, we must override the pure virtual function clone() in the base class. • The class declaration is given below. class JPG : public File { public: JPG(const std::string& n, int n, int w, const double rgb()) : File(...) { // ... } *JPG()...

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