Question

Computer Science 111 Introduction to Algorithms and Programming: Java Programming Net Beans Project #4 - Classes...

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
0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER -

public class Shoe {
  
private static final int MIN_SIZE = 1;
private static final int MAX_SIZE = 15;
  
private long productID;
private String brand;
private double price;
private int size;

public Shoe(long productID, int size, double price) {
this.productID = productID;
this.size = size;
this.price = price;
}

  
public Shoe(long productID, String brand, double price, int size) {
super();
this.productID = productID;
this.brand = brand;
this.price = price;
this.size = size;
}
  
public long getProductID() {
return productID;
}

public void setProductID(long productID) {
this.productID = productID;
}

public String getBrand() {
return brand;
}

public void setBrand(String brand) {
this.brand = brand;
}

public double getPrice() {
return price;
}

public void setPrice(double price) {
if (price < 0) {
System.out.println("Price Must be greater than zero!\n");
return;
}
this.price = price;
}

public int getSize() {
return size;
}

public void setSize(int size) {
if (size > MAX_SIZE && size < MIN_SIZE) {
System.out.println("Invalid Size!\n");
return;
}
this.size = size;
}

@Override
public String toString() {
return "Shoe [productID=" + productID + ", brand=" + brand + ", price=" + price + ", size=" + size + "]";
}
}


public class Car {
  
private static final int MIN_SPEED = 0;
private static final int MAX_SPEED = 300;
  
private int modelNumber;
private String color;
private double speed;
  
  
public Car(int modelNumber) {
this.modelNumber = modelNumber;
this.speed = 0;
}

public Car(int modelNumber, String color, double speed) {
this.modelNumber = modelNumber;
this.color = color;
this.speed = speed;
}

public int getModelNumber() {
return modelNumber;
}

public void setModelNumber(int modelNumber) {
this.modelNumber = modelNumber;
}

public String getColor() {
return color;
}

public void setColor(String color) {
this.color = color;
}

public double getSpeed() {
return speed;
}

public void setSpeed(double speed) {
if (speed < MIN_SPEED && speed >MAX_SPEED) {
System.out.println("Speed out of range!\n");
}
this.speed = speed;
}
  
/**
* Accelerates the car
*/
public void accelerate() {
this.speed += 5;
}

/**
* Applies break on the car, and sets speed to zero
*/
public void brake() {
this.speed = 0;
}
  
@Override
public String toString() {
return "Car [modelNumber=" + modelNumber + ", color=" + color + ", speed=" + speed + "]";
}
}

--------------------------------------------END THANK YOU---------------------------------------------

Add a comment
Know the answer?
Add Answer to:
Computer Science 111 Introduction to Algorithms and Programming: Java Programming Net Beans Project #4 - Classes...
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
  • I need help writing my main method**** Computer Science 111 Introduction to Algorithms and Programming: Java...

    I need help writing my main method**** Computer Science 111 Introduction to Algorithms and Programming: Java Programming Project #4 – Classes and Objects (20 Points) You will create 3 new classes for this project, two will be chosen from the list below and one will be an entirely new class you invent.Here is the list: Shirt Shoe Wine Book Song Bicycle VideoGame Plant Car FootBall Boat Computer WebSite Movie Beer Pants TVShow MotorCycle Design First Create three (3) UML diagrams...

  • Java Program Please help me with this. It should be pretty basic and easy but I...

    Java Program Please help me with this. It should be pretty basic and easy but I am struggling with it. Thank you Create a superclass called VacationInstance Variables destination - String budget - double Constructors - default and parameterized to set all instance variables Access and mutator methods budgetBalance method - returns the amount the vacation is under or over budget. Under budget is a positive number and over budget is a negative number. This method will be overwritten in...

  • JAVA :The following are descriptions of classes that you will create. Think of these as service...

    JAVA :The following are descriptions of classes that you will create. Think of these as service providers. They provide a service to who ever want to use them. You will also write a TestClass with a main() method that fully exercises the classes that you create. To exercise a class, make some instances of the class, and call the methods of the class using these objects. Paste in the output from the test program that demonstrates your classes’ functionality. Testing...

  • Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters...

    Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...

  • Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and...

    Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and name variables (do not include topTrick). Note: The type refers to what the breed typically does; for example, a corgi would be a “cattle herding dog.” A Shiba Inu would be a “hunting dog.” Create the setTopTrick() mutator method Dog is parent class Corgi and Driver are subclasses Complete the Corgi class: Using the UML Class diagram, declare the instance variables. Create the two...

  • Java - Object Oriented Programming Declare a class named Customer that has two private fields? Write...

    Java - Object Oriented Programming Declare a class named Customer that has two private fields? Write a set method to make sure that if age > 125 years or less than 0 then it is set to 0 (default value) What does it indicate when declaring a class's instance variables with private access modifier? What is the role of a constructor? The data part of by an object's instance variables is known as? Do all methods have to always return...

  • Deliverable A zipped NetBeans project with 2 classes app ZipCode Address Classes Suggestion: Use Netbeans to...

    Deliverable A zipped NetBeans project with 2 classes app ZipCode Address Classes Suggestion: Use Netbeans to copy your last lab (Lab 03) to a new project called Lab04. Close Lab03. Work on the new Lab04 project then. The Address Class Attributes int number String name String type ZipCode zip String state Constructors one constructor with no input parameters since it doesn't receive any input values, you need to use the default values below: number - 0 name - "N/A" type...

  • Additional info is this will use a total of four classes Book, BookApp, TextBook, and TextBookApp....

    Additional info is this will use a total of four classes Book, BookApp, TextBook, and TextBookApp. Also uses Super in the TextBook Class section. Problem 1 (10 points) Вook The left side diagram is a UML diagram for Book class. - title: String The class has two attributes, title and price, and get/set methods for the two attributes. - price: double Вook) Book(String, double) getTitle(): String setTitle(String): void + getPrice() double setPrice(double): void toString() String + The first constructor doesn't...

  • Hello, In need of help with this Java pa homework. Thank you! 2. Create a normal...

    Hello, In need of help with this Java pa homework. Thank you! 2. Create a normal (POJo, JavaBean) class to represent, i. e. model, varieties of green beans (also known as string beans or snap beans). Following the steps shown in "Assignment: Tutorial on Creating Classes in IntelliJ", create the class in a file of its own in the same package as class Main. Name the class an appropriate name. The class must have (a) private field variables of appropriate...

  • Create a UML diagram to help design the class described in exercise 3 below. Do this...

    Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two constructors:...

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