Coder Social home page Coder Social logo

bell-kevin / box Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 58 KB

Previously, you wrote a project for rectangles. This one is similar but can create a 3D object (box) as well as a 2D one (paper). Create a class named Box, with instance variables for length, width, and height. Create a constructor with no parameters that sets the instance variables to 1. Create an overloaded constructor that needs 2 integer parameters for a 2D object, which sets the length and width, and stores 0 for the height. Create an overloaded constructor that needs 3 integer parameters for a 3D object, which sets the length, width, and height of the object. You do NOT need to create “set” and “get” methods for the 3 instance variables, you’ll be using the constructors only and direct access to the instance variables. Create 3 different methods to calculate the area of a 2D object, the perimeter of a 2D object, and the volume of a 3D object. You don’t have to test the kind of object, just do the calculations and return the answer. Create a Boolean method that checks if the object is a cube – if all 3 measurements are the same, it is a cube. Create a Boolean method that checks if the object is a box – if all 3 measurements are greater than 0, it is a box. If it is not a box, it is a flat object, only 2D – one of the measurements is 0. Create a Boolean method that checks if the flat object is a square – length and width are the same. Create a display method that prints out information about the object. Use an IF-Else IF structure to determine the kind of object – cube, box, square, rectangle. Check first if it is a cube – if yes, also print out the volume. If it’s not a cube, next check if the object is a box – if yes, print out its measurements and volume. If it’s not a cube or box, check if the object is a flat square – if yes, print out its measurements, perimeter and area. If not a cube, box, or square, check if the object is a rectangle – if yes, print out the measurements, perimeter, and area. Note that each object will only display one of these results. If the object is a cube, print those results and exit the If-Else If structure. That’s why you are using an If-Else If structure, so there is only one block of code executed for each call to this method. Write a driver class that instantiates or creates 4 Box objects – a cube, a box, a flat square, and a flat rectangle. Print out the name you gave to an object, then display its information. Repeat for all of the objects. Notice how short it becomes when you use constructors instead of using a set method for every dimension of the objects.

License: GNU General Public License v3.0

Java 100.00%
class-method object-oriented-programming datc davis-tech

box's Introduction

Hi 👋, I'm Kevin Bell

I'm a student!

  • 🤝 I’m looking to collaborate on almost anything open-source.
  • 🔨 I’m working on my machine learning home cloud server using Ubuntu Server, Nextcloud, Tailscale VPN, & TensorFlow.js

🛠️ My favorite tools

👨‍💻 Programming and markup languages

C++ CSS HTML Java JavaScript Scratch SQL

🧰 Frameworks and libraries

GitHub Actions JUnit TensorFlow Wordpress

🗄️ Databases and cloud hosting

GitHub Pages MySQL

💻 Software and tools

Android Brave Discord Git GitHub Desktop Google Sheets Stack Overflow Visual Studio Code

I love free/libre open-source software! Most JavaScript running on most websites (including GitHub.com) is NOT open-source software.

box's People

Contributors

bell-kevin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.