Write a class called Pen that contains the following information: Private instance variables for the price of...

50.1K

Verified Solution

Question

Programming

Write a class called Pen that contains thefollowing information:

  1. Private instance variables for the price of the pen (float) andcolor of the pen (String).
  2. A two-argument constructor to set each of the instancevariables above. If the price is negative, throw anIllegalArgumentException stating the argument that is notcorrect.
  1. Get and Set methods for each instance variable with the sameerror detection as the constructor.

public class Pen {

Answer & Explanation Solved by verified expert
3.7 Ratings (546 Votes)
Here is the solution your code starts hereimport javautilScannerpublic class Pen instance variables replace the example below with yourownprivate float priceprivate String color constructor with two argumentsparameterspublic Penfloat price String colortry ifprice 0throw new    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students