Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Computer Science 111 Introduction to Algorithms and Programming: Java Programming Net Beans Project #4 - Classes and Objects (15 Points) You will create 3 new

Computer Science 111 Introduction to Algorithms and Programming:

Java Programming Net Beans Project #4 - Classes and Objects (15 Points)

You will create 3 new classes for this project, two will be chosen (THE TWO CHOSEN ARE TENNIS SHOE AND TREE) from the list below and one will be an entirely new class you invent. Here is the list:

Cellphone Clothes JuiceDrink Book MusicBand Bike GameConsole Tree Automobile Baseball MusicPlayer Laptop TennisShoe Cartoon EnergyDrink TabletComputer RealityShow HalloweenCostume

Design First

Create three (3) UML diagrams for three classes. Two of the classes are assigned by the instructor from the above list and one you must invent. Choose as the third class, something you know very well or love doing. If soccer is your favorite sport, create a class Soccer. If you sing opera, create a class Opera. Do not overthink. Just come up with the 3 most important data members (i.e. global variables) that describe the class/object you want to build and the design 2 constructors, 3 get methods, 3 set methods and a toString method and you are done.

Please do not use the same 3 data types for any classes global variables. That is, do not make them all ' int ' or all ' String '.

Next to each UML diagram decide on a default value, minimum value and a maximum value for EACH numeric variable. For example, the Shoe class and its size variable may have a default value of 0; the minimum size may be 1 and the maximum size 15. A String variable may set a default value of null, and a minimum and maximum length of the String. For example, the Computer class and its brand variable may have a default value of null, a minimum string length of 3 and the maximum length 20. Please do not use the same 3 data types for any classes global variables. That is, do not make them all ' int ' or all ' String '.

Implement Next

Create a NetBeans project. Create a Java file for EACH of the three classes. For example, add to your project a new file called Book.java and then create the new class from scratch in that file. Use your UML diagrams as the guideline for writing the code. The variables and methods from the diagrams will be part of each of your classes. Make sure ALL your variables are declared to be private.

Protect Your Data!

Objects store data or information! When variables are declared private you can protect or guard that information like a Pit Bull protects a piece of meat. Never allow bad data to be stored in your objects! In each 'set' method, make sure the value passed to the method is in range, greater than or equal to the minimum and less than or equal to the maximum. For strings, you may check the length of the string. Each 'set' method should have some sort of 'if-else' statement, assign the data when it is good and print an informative message when an incorrect value is passed. The Shoe class setSize() method would assign the value '10' to the size global variable when it is passed to the method. But, it would print a 'Shoe size must be between 1 and 15' and NOT change the global variable when a value such as '437' was passed to the method. The private variable declarations build a wall around your data, and the 'set' methods are the gates that allow only 'good' information in. Your constructor that assigns values to global variables should use the 'set' methods so you DO NOT have to repeat the same checks in the constructor. The constructor with NO parameters can go ahead and directly set the default values into the global variables.

Test Next

For each class, create a main method that will declare, build and use an object of that class. So the Book.java main will declare, build and use a Book object, and the other two classes will do the same. Use a command line interface and ask the user to input a value for EACH global variable. Call a constructor or the set methods and insert that information into the object. Once the data is inserted use the object to call the toString method and print the object to the console. You will be writing THREE main methods, one for each class. When you test, make sure your set methods DO NOT allow bad data into the object. Try to make it fail, see if you can sneak bad values into the variables.

To insure you complete each class, use this checklist:

_____ Three global variables (not the same type) _____ Two constructor methods _____ Three 'get' methods _____ Three 'set' methods _____ One 'toString' method _____ One main method that creates an object, assigns values, and prints the object

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Databases On The Web Learn To Create Web Pages That Interface With Database Engines

Authors: Robert Papaj, Donald Burleson

11th Edition

1576100995, 978-1576100998

More Books

Students also viewed these Databases questions

Question

Question How are VEBA assets allocated when a plan terminates?

Answered: 1 week ago

Question

Question May a taxpayer roll over money from an IRA to an HSA?

Answered: 1 week ago

Question

Question What is the doughnut hole in HSA coverage?

Answered: 1 week ago