Coder Social home page Coder Social logo

Topic: class-method Goto Github

Some thing interesting about class-method

Related Topics:

👇 Here are 20 public repositories matching this topic...

  • bell-kevin / box

    class-method,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.

    User: bell-kevin

    class-method datc davis-tech object-oriented-programming
  • bell-kevin / drawingshapes

    class-method,This project does not require a class, because we aren’t going to instantiate any objects. It uses class methods, specifically the main method plus a few more. Create a project named “Ch7Draw”. You will add class methods above the main method. Remember that class methods need the keyword “static” in the heading. To draw a bar of asterisks across a line, we will use a method named “drawBar”. It needs to know how many times an asterisk should appear on the line, so it needs an integer parameter. In your project, create a class method named “drawBar”. This method uses a FOR loop to print a single asterisk character repeatedly, the number of times passed in to the method. After the loop completes, the System.out.println() command ends the line and positions the cursor at the left edge of the next line on the screen. The main method tests this drawBar method. Here, there is another FOR loop that calls the drawBar() method with different values for the argument. The first time, the index is 1, so drawBar(1) prints a single asterisk on the line. The second time through the loop, the index is 2, so drawBar(2) prints two asterisks on the line. This continues for 6 lines, because that was hard-coded into the For loop. Run the project to make sure it works so far. Now, modify the program to be able to draw a box. That requires 2 values, length across the line (width) and number of lines (height). Create a class method named “drawBox” that accepts those 2 parameters. We already have a method that can draw a line across the page, to the width specified. We need to repeat that action for the number of lines or height specified, so the drawBox method will need to call the drawBar method multiple times. Now that the basic project exists, you need to modify it to ask the user how big a box to draw, and also to ask if they want the default marker (asterisk or *) or if they want to specify the marker. Create another drawBar method that adds a parameter for the marker, and another drawBox method that adds a parameter for the marker. This overloads both methods. In the main method, after the code already written to test the drawing methods, ask the user for the dimensions of the box, then ask if they want the default marker or if they want to specify the marker. Use Y or N for the answer, but allow the user to type it in upper or lower case. Then call the method that will draw such a box, with the default marker (the code you already have) or one with a new specific marker (the new methods that overloaded the previous methods). Note that if the user said to use the default marker, the code should call the existing method that displays the box with asterisks – no change from the previous version of the code. If the user said to use a specific marker, the code should call the overloaded versions of the methods that have that specified marker passed in as one of the parameters. Run the program -- you may use any width and height values you choose, and any character to draw the box. Take a screenshot of the results. Next, modify the project so that it does not draw the right triangle or the box with the hard-coded measurements. Now, the project should ask the user if it should draw a box, and if the answer is yes, ask for the needed parameters and draw that box. Repeat, so that the project can draw more than one box, until the user says to stop. Run your program and test the Y and N responses to both questions, as you see above, using whatever box measurements you wish. Be sure to request a box with the default marker and another box with a specific marker. Take a screenshot of the results. Submission: the specified screenshots, and the root folder for the project Pay careful attention to the rubric for this assignment. Remember the standards that apply to every project. Note that you must use correct formatting in the code -- appropriate indentation is most important. You can use Shift-Alt-F to have NetBeans automatically format the code correctly. If the formatting is incorrect, it will be returned to you for changes with a grade of zero. Note: You need to submit the whole project for these assignments. In File Explorer, go to the location where you created the project. There will be a folder with the name of your project -- that is the root folder of the project. If you submit the root folder of the project, the instructor can run it on a different machine to grade it. If you don't submit the proper folder, it won't run on another machine, and the assignment will be marked with a zero.

    User: bell-kevin

    class-method object-oriented-programming datc davis-tech
  • bell-kevin / vendingmachineinventory

    class-method,In Competency Exercises, you demonstrate your skill and ability to use the programming principles you've learned in the current and previous modules. You must complete this assignment by yourself, much like a module exam. You can ask instructors for clarification about the project -- you can not ask instructors or other students for help with logic or coding. If you are struggling with the project, you can look at previous assignments where you did similar work, and you can review the pertinent sections in the book. These are the skills you practiced in this module and will now demonstrate: Classes Instantiating objects Constructors Class methods Module 3 Competency Exercise: Vending Machine Inventory In this exercise, you work with the inventory for the beverage vending machine in the Barlow building. Create a class for the inventory in the vending machine. Each inventory item has a name, a price, and a quantity. The class needs a constructor to instantiate each inventory item, a method to display the item with its price and quantity, and a method for receiving new stock which will add to the quantity for that inventory item. Make sure that all money values display correctly, with a dollar sign and 2 decimal places. In the driver class, instantiate 3 inventory items with a price and quantity, then display that starting inventory for all items. For each of those items, ask the user how many are being delivered, and display the value of that quantity of that item, the cost for that delivery. After deliveries for all 3 items, display the inventory for all items. You may choose the items, price, and quantity. If you prefer, you can work with the vending machine for candy and snacks instead of beverages. Run your project and take a screenshot. Remember the style rules that apply to all projects throughout this course. Even if not specifically mentioned in the assignments, you are responsible for the following: Use descriptive names for all variables Add comments describing the use or meaning of variables Do NOT include literal values in any calculations, always use variables Always include a header in the output with a descriptive title and your name If asking for input, make sure the user types on the same line as the question Where sample sessions are provided, output from your project must match it Note that you must use correct formatting in the code -- appropriate indentation is most important. You can use Shift-Alt-F to have NetBeans automatically format the code correctly. If the formatting is incorrect, it will be returned to you for changes with a grade of zero. Submission: specified screenshots and root folder for the project

    User: bell-kevin

    class-method classes constructors instantiation inventory object-oriented-programming vending-machine
  • sarvagya-dubey / pythonoopconcepts

    class-method,This repository contains basic examples illustrating concepts of Object Oriented programming with Python. You get to know how to write a class in python, initialize instances, class variables, inheritance in Python, writing getters and setters and the use of @classmethod, @staticmethod, @property and dunder-methods like __repr__, __str__, __len__ and __add__ and implementing a Singleton class in Python

    User: sarvagya-dubey

    oop-principles python classes-and-objects inheritance-examples dunder-methods class-method static-method staticmethod property getter-and-setter singleton-class
  • xtina-lt / first-national-north-pole

    class-method,Faux banking python project. Shows understanding of python fundamentals (variables, lists, functions, control statements, objects [dictionaries, classes]). Plays with ternary opertors and list comprehension. Shows understanding of OOP. CLASS objectives: define, instantiate, call methods[instance, static, cls], define/use global attributes, and modularization.

    User: xtina-lt

    Home Page: https://github.com/xtina-lt/First-National-North-Pole

    classes-and-objects constructor instantiation class-method static-method ternary-operator import

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.