Question

Write the Widget class. a. A widget has a name and price. b. Thedefaultfornameshouldbe“widget” c. Write...

Write the Widget class.

a. A widget has a name and price.

b. Thedefaultfornameshouldbe“widget”

c. Write a constructor (not the no-args), all getters and setters.

d. Add a to String method.

e. Create an object of type Widget.

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

Following is the java Program:

widget.java

public class widget {

    private String name = "widget";
    private double price;

    widget(){

    }


    public void tostring(){
        System.out.println("Name: " + this.getName() );
        System.out.println("Price: " + this.getPrice() );
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
}

Object is in main class:

widgetmain.java

public class widgetmain {
    public static void main(String[] args) {

        widget w = new widget();
        System.out.println(w.getName());

    }
}
Add a comment
Know the answer?
Add Answer to:
Write the Widget class. a. A widget has a name and price. b. Thedefaultfornameshouldbe“widget” c. Write...
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
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