Free Essay

Wek 8 Object Oriented Programming

In: Computers and Technology

Submitted By robert22
Words 390
Pages 2
Making Kool-Aid

Public Class Kool-aid
//attributes of kool-aid
Declare Flavors as String
Declare Cherry as String
Declare Lemonade as String
Declare Grape as String
Declare UserInput as string
Declare Two_packs as Bool
Declare One_Pack as Bool
IF UserInput != “Cherry” Set Flavors = Cherry
IF UserInput != “Grape” Set Flavors = Grape
Set Flavors = Lemonade as Deflault
IF One_Pack = True Call Sugar()
IF Two_Pack = True Call Sugar()
End Class

Public Class Sugar
//Attributes of Sugar
Declare Sugar as Float
Declare OnePack as Int
Declare TwoPacks as Int
Declare Input as String
Declare newWater as new Water()
Set OnePack = 2 cups
Set TwoPack = 4 cups
IF Input = “1” Set Sugar = OnePack
IF Input = “2” Set Sugar = TwoPack

Public Class Water
//Attributes of Water
Declare newOnePack as Int
Declare newTwoPack as Int
Set newOnePack = ½ gallon
Set newTwoPack = 1 gallon

Main Module Declare Flavors as new Kool-aid.Flavors() Declare userSugar as new Sugar() Declare userWater as new Water()
Declare yes as String
While yes = “yes” Display “What flavor of Kool-Aid would you like? Cherry, Lemonade, or Grape” Input Flavors IF Flavors != “Cherry” or “Lemonade” or “Grape” Display “You have Chosen” + Flavors Display “Is this correct? Yes = Y or No = N” Else Display “You have not chosen a correct Flavor” End IF Display “How Many Packs of Kool-Aid did you use? 1 or 2” Input userSugar IF userSugar = “1” Set userWater = newOnePack IF userSugar = “2” Set userWater = newTwoPack End IF Display “Would you like to make more Kool-aid? yes or no”
Input yes
End While End Program

I believe I enjoy object oriented programming a lot more then structured because with OOP I can develop classes to store the data rather than using modules to call the functions that I am using I can just use the class file and create a new variable and inherit the attributes of the class file without having to store multiple lines of code to develop the same process and I can also use multiples of the same class with different variable names and label them as different functions and names OOP is used in game programming to store data regarding players and monsters movements, attacks, and items they can carry. Structured programming is good to use when creating smaller programs with little features with the program itself.…...

Similar Documents

Free Essay

Object Oriented Programming Exam

...SAMPLE QUESTION PAPER Object Oriented Programming using Java SEMESTER 1& 2 Question 1 (25 marks) a) Discuss the syntax, purpose and application, with an example for each, of the following: i. if ii. while iii. for iv. switch (4 x 5 marks = 20 marks) b) Write an independent Java method that accepts three sides of a triangle, say a, b and c and returns “Equilateral” if all the three sides are equal, “Isosceles” if any two sides are equal “Scalene” otherwise. (5 marks) Question 2 (25 marks) a) Write an independent Java method that accepts an integer and returns true if it is a prime number, false otherwise. An integer is said to be prime if it is divisible by 1 and itself only. (9 marks) b) Write an independent Java method that accepts an array of integers and returns the smallest of them. (8 marks) c) Write a Java program to accept 10 integers and print the sum of numbers divisible by 5. (8 marks) Question 3 (25 marks) a) Write a Java program to print the sum, average, maximum and minimum of 10 numbers. All numbers must be read from the user. (8 marks) b) What are formal and actual arguments? Explain with a sample program how they work in Java. (8 marks) c) Write a Java program to print first n Fibonacci sequence of numbers. The first two numbers of the sequence are 0 and 1; next number is the sum of the previous numbers. (9 marks) ...

Words: 731 - Pages: 3

Free Essay

It/218 Object Oriented Programming

...Object oriented programming refers to a method of programming in which individual objects, usually called "methods" and "functions", are created and used in junction with each other to perform a function. These objects are organized within the program through use of things called structures or classes. A class is something we use to create a blueprint of sorts for a assortment of variables and components. Similarly, a structure serves the same purpose. The only difference between a structure and a class is that a structure's members are public by default and a classes members are private by default. Another form of "blueprint" used by programmers is the data union. While a union is very primitive in comparison to a structure or class, it is a good tool to use to conserve memory in larger applications. A union uses the same memory block for multiple variables at different points. While two variables in a union cannot be accessed at the same time, a union is a good way to re-use blocks of memory that would normally be left void after a variable is finished with. Now that I have covered the basic points of classes, structures and unions, I will go into more detail of just how powerful a class or structure can be. In basic reference, a class is simply a blueprint to something we create instances of later in the program. This is a very vague statement however, because in object-oriented programming the class is the backbone of the program. It is what makes......

Words: 813 - Pages: 4

Premium Essay

Procedural Programming Compared to Object Oriented

...and Contrast Object Oriented Programming and Procedural Programming Languages Object Oriented Programming 1 Marty Montgomery Compare and Contrast Object Oriented and Procedural Programming Languages: Object Oriented Programming and Procedural Programming are two programming paradigms. A programming paradigm is a fundamental style of computer programming, and they differ in the way different elements of the program are represented and how steps for solving problems are defined. As the name suggests, Object Oriented Programming focuses on representing problems using real-world objects and their behavior while, Procedural Programming deals with representing solutions to problems using procedures, which are collections of code that run in a specific order. (Gaddis, 2010) Procedural Programming is a method of writing software. It is a programming practice centered on the procedures or actions that take place in a program. One of the main concepts of Procedural Programming is the Procedure call. A procedure also known as a subroutine, method or a function contains an ordered list of instructions to be carried out. A procedure can be called at any time during the execution by any other procedure or by itself. Examples of Procedural programming languages are C and Pascal. (Gaddis, 2010) In OOP, the focus is on thinking about the problem to be solved in terms of real-world elements and representing the problem in terms of objects and their behavior. Object is a data......

Words: 924 - Pages: 4

Premium Essay

Object Oriented

...database applying appropriate design and development techniques. Part 1: Using Database Management Systems 1. To access this lab log into CourseMate and open the NP2013 eBook 2. Click the > icon next to “Select Chapter” repeatedly until Chapter 11 appears in the orange heading 3. In the right panel window, Click the word “here” in the “Click here to open the eBook” 4. Click the ARROW icon next to the NEW Perspectives Labs option (2nd from bottom of list) 5. Click the ARROW icon next to the lab title “Working With Database Software” 6. If you see a pop up window asking if you want to set up tracking. Click on Cancel. 7. Click on Click to Continue when Working With Database Software screen appears: 8. The table of contents appears. To begin on Topic 1, click on CLICK TO CONTINUE 9. Read the content boxes that appear on the screen. When you are done, click on the right arrow to go to the next page. Next Page Keep reading each page until you come to page 9. On this page you are given a task to perform. Notice that where you are to click is outlined in red. Be sure to perform all tasks as you go through the lab. Perform this task 10. Take each quick quiz as you go through the topics to help ensure that you are mastering the material. 11. You are not required to turn in any work from this online lab. Part 2 – Designing databases Review and Definitions: * The hierarchy of data begins with a character, a......

Words: 755 - Pages: 4

Premium Essay

Object Oriented Programming

...Object Oriented Programming IT/218 Object-Oriented Programming (OOP) provides computer programmers not only a new way to program, but a new way to think in terms of objects. This type of programming (“Object oriented programming,” 2012) allows programmers to use objects as a way of thought versus using a procedural language and organizing by data structures and algorithms. This is a new way of programming centered on objects to develop programs. C++ gives the programmer a way to incorporate encapsulation, inheritance, and polymorphorism and C++ also provides many ways of support Object-Oriented Programming. Programming was once thought upon as using a series of tasks for the computer to perform but object-oriented programming uses a collection of objects. In this type of programming, each object can receive message and process data, as well as send other messages to fellow objects. By placing information where it is not accessible by the entire computer program, OOP (“Object oriented programming,” 2012) calls the data using methods. The methods then act as intermediaries for working on the data they control. Object-oriented programs center on different types of objects. Each object contains a kind of data that manages the information within the program itself. The method of the object will use a system of checks and safeguards that are defined in the types of data the object contains. Because of this system, adaptations to the program can......

Words: 465 - Pages: 2

Premium Essay

Object-Oriented vs. Procedural Programming

...Object-Oriented vs. Procedural Programming Whether it is Object-Oriented or Procedural Programming, programming in general is dealing with or looking at data and the code that can and will change the data (output) in some way. Object-Oriented vs. Procedural Programming can be said to be ways we handle the coding of the data – how it is written perhaps. We need to apply different thinking and strategies when we write code, and it can be either Object-Oriented or Procedural Programming. In Procedural Programming, we group our code into procedures, hence the name Procedural Programming. These procedures are instructions on how we use and manipulate the data. With Procedural Programming we have code that is read line by line, taking input (instructions) to do something with the goal of an output. The code is read (data taken in) in exchange for an output. With Procedural Programming, you can write code all day long that do not have an existing relationship to the data used. Procedural Programming functions use code (data) provided and can access shared data needed, but a relationship does not exist. Procedural Programming uses traditional programming languages like C, COBOL and Pascal. In short, Procedural Programming is about using and choosing data structures, creating your algorithms, and converting algorithms into code. With Procedural Programming, data and operations of the data or with the data are separate (no relationship exist). You send data to procedures...

Words: 720 - Pages: 3

Free Essay

Object-Oriented Analysis and Design

...Generic Exam: Object-Oriented Analysis and Design Time: 2.5 hours Marking: 100 marks, plus 10 marks for the bonus question. Purpose This purpose of this generic exam is to allow you to see what the real final exam will look like, and the relative weighting in terms of marks. The only significant difference between this generic exam and the final one is that the latter will include a specific case study. Exam Process This examination is composed of multiple sections. Each subsequent section relies upon standard solutions from the previous sections. You are required to submit your section answers—on completion—to the examination coordinator, and trade it for the standard solution. Use the provided standard solution as the basis for your subsequent work. On completion of the examination, hand in the entire set of standard solutions. Do not reveal or discuss the standard solutions, either during or after the examination. Marking ▪ Please note that the use case questions have the least marks, since they are relatively straightforward and not an object-oriented skill. In contrast, the questions on responsibility assignment, patterns, and design of collaborations have the most marks, since these are the most important object-oriented design skills. Evaluation Objectives ▪ Ability to identify primary use cases and record them in expanded, essential form. ▪ Ability to identify outstanding concepts, associations, and attributes......

Words: 688 - Pages: 3

Premium Essay

Object Oriented Programming and Uml

...Object Oriented Programming and UML Implementation modeling is “the development stage for adding fine details to a model that transcend languages. Implementation modeling is the immediate precursor to the actual implementation.”(Blaha & Rambaugh, 2005) Implementation modeling uses the following four steps: fine-tune classes, fine-tune generalizations, realize associations, and preparing for testing. Steps one and two are driven by the theory of transformations. Transformations “is a mapping from the domain of models to the range of models”(Blaha & Rambaugh, 2005) The first step in implementation modeling is fine-tuning classes. It is best to fine-tune classes before writing code because it will help to simplify development or to improve performance. If for some reason you have to alter the design first consider the following possibilities; partition a class, merge classes, partition or merge attributes, or promote an attribute or demote a class. The next step in implementation modeling is fine-tuning generalizations. It is helpful to remove generalization or to add one prior to coding. The third step is realizing associations. This is what holds the class model together by providing paths between objects. The final step is testing. “Testing is a quality assurance mechanism for catching residual errors.” (Blaha & Rambaugh, 2005) It also measures the quality of your software. “Implementation is the final development stage that addresses the...

Words: 319 - Pages: 2

Premium Essay

Introduction to Object-Oriented Programming

...INTRODUCTION Structured programming (known as modular programming) is a subset of procedural programming that enforces a logical structure in the programming being written, to make it more efficient and easier to understand and modify. Structured programming frequently employs a top-down design model, in which developers map out the overall program structure into separate subsections. A defined function or a set of similar functions coded in separate modules can be reused in other programs. After a module has been tested individually, it is then integrated with other modules into the overall program structure. Program flow follows a simple hierarchical model that employs looping constructs such as 'for,' 'repeat' and 'while.' Use of the 'Go To' statement is discouraged in structured programming. Structured programming was first suggested by the mathematicians Corrado Bohm and Guiseppe Jacopini. They demonstrated that any computer program can be written with just three structures: decision, sequences and loops. In structured programming coders break larger pieces of code into shorter subroutines (functions, procedures, methods, blocks or otherwise) that are small enough to be understood easily. In general, programs should use local variables and take arguments by either value or reference. These techniques help to make isolated small pieces of code easier to understand the whole program at once. PASCAL, Ada and C are some of the examples of structured programming......

Words: 2729 - Pages: 11

Premium Essay

Object Oriented

...sites have Construction activities  8 sites have D&D activities  4 Chemical Inventory Management Benchmarking Survey Results Site Information, continued  Size of facilities and magnitude of the inventory ranged from small to very large  700 to 12,000 employees  600 to 30,000 unique chemicals  1780 to 130,000 MSDS  3 to 267 Chemical Storage Tanks  130 to 2300 storage locations  5 Chemical Inventory Management Benchmarking Survey Results  Chemical Inventory Management System  All sites utilize electronic chemical inventory systems  9 sites use an in-house application  3 sites use commercial-off-the-shelf applications  All sites use barcodes. 3 sites use container tracking methodologies in addition to bar codes  RFID is not being used for container tracking at any site 6 Chemical Inventory Management Benchmarking Survey Results  What are the primary purposes for the Chemical Management System? 7 Chemical Inventory Management Benchmarking Survey Results  Barcoding Processes  Every site barcodes individual containers, but not every site barcodes all their individual containers  Bulk tanks—7 of the 9 sites use a barcode for their tanks  3 of the 8 sites barcode process tanks  10 of 11 sites barcode gas cylinders  5 of 8 sites barcode case lots (one barcode on the case)  Static Inventory-where one barcode may be used for a predetermined inventory quantity. 3 of the 8 sites have this. 8 Chemical Inventory Management......

Words: 1410 - Pages: 6

Free Essay

Object Oriented Programming in Java ‐ Exercises

...OBJECT ORIENTED PROGRAMMING IN JAVA ‐ EXERCISES    CHAPTER 1    1. Write Text‐Based Application using Object‐Oriented Approach to display your name.    // filename: // Class containing display() method, notice the class doesnt have a main() method public class Name { public void display() { System.out.println("Mohamed Faisal"); } } // filename: // place in same folder as the file // Class containing the main() method public class DisplayName { public static void main(String[] args) { Name myname = new Name(); // creating a new object of Name class myname.display(); // executing the display() method in the Name class } }   2. Write a java Applet to display your age.  // filename: import java.applet.Applet; // import necessary libraries for an applet import java.awt.Graphics; public class DisplayNameApplet extends Applet { public void paint(Graphics g) { g.drawString("Mohamed Faisal", 50, 25); } } // filename: DisplayNameApplet.htm // place in same folder as the compiled DisplayNameApplet.class file Displaying my Name CHAPTER 2    3.  Write a program that calculates and prints the product of three integers.    // filename: import java.util.Scanner; // import Scanner libraries for input public class Q1 { public static void main(String[] args) { Scanner input = new Scanner (; int number1; int number2; int number3; System.out.println("Enter the First......

Words: 3130 - Pages: 13

Free Essay

Object-Oriented Programming Mini Projects

...MANAGEMENT DEVELOPMENT INSTITUTE OF SINGAPORE Advanced Diploma in Information technology AITD2 1422A_AITD2 1421A_AITD2 1420A_AITD2 1419A Objected-oriented Programming Mini Project Question (100 marks) In this project, you will be creating new classes that are derived from a class called BankAccount. A checking account is a bank account and a savings account is a bank account as well. This sets up a relationship called inheritance, where BankAccount is the superclass and CheckingAccount and SavingsAccount are subclasses. This relationship allows CheckingAccount to inherit attributes from BankAccount (like owner, balance, and accountNumber), but it can have new attributes that are specific to a checking account, like a fee for clearing a check. It also allows CheckingAccount to inherit methods from BankAccount, like deposit, that are universal for all bank accounts. You will write a withdraw method in CheckingAccount that overrides the withdraw method in BankAccount, in order to do something slightly different than the original withdraw method. You will use an instance variable called accountNumber in SavingsAccount to hide the accountNumber variable inherited from BankAccount. The UML diagram for the inheritance relationship is as follows: [pic] Task #1 Extending BankAccount 1. Copy the files and from the Blackboard. is complete and will not need to be......

Words: 1078 - Pages: 5

Free Essay

Object Oriented Programming -Java

........................................................................................ 4 Provide the UML diagrams for the given problem with clear explanations on the design decisions. Derive detailed Use Case diagram, Class diagram & a sequence diagram. Whenever necessary document the relevant assumptions you made. ...................................................................................... 4 TASK B ....................................................................................................................................................... 7 Provide an alternative OO design for the same problem ......................................................................... 7 Object Oriented Known as Methodology or paradigm to design a program using classes and objects. It simplifies the software development and maintenance. ......................................................................... 7 TASK C ....................................................................................................................................................... 9 There are many system design patterns available in system development. Critically evaluate singleton, factory and abstract factory design patterns and apply the most suitable design pattern for your system development................................................................................................................................. 9 TASK D .................................................

Words: 4819 - Pages: 20

Premium Essay

Object Oriented Analysis and Design

...SOF535 Object oriented analysis and design ABSTRACT This is pages are for downloading of Visual studio and setting up IDE environment.First I have gone to the link and download the IDE from that link so process starts from here.It is the first page of Downloading process visual studioMicrosoft Visual Studio is an integrated development environment (IDE) from Microsoft. It is used to develop computer programs for Microsoft Windows, as well as web sites, web applications and web services. Visual Studio uses Microsoft software development platforms such as Windows API, Windows Forms, Windows Presentation Foundation, Windows Store and Microsoft Silverlight. It can produce both native code and managed code. Visual Studio includes a code editor supporting IntelliSense (the code completion component) as well as code refactoring. The integrated debugger works both as a source-level debugger and a machine-level debugger. Other built-in tools include a forms designer for building GUI applications, web designer, class designer, and database schema designer. It accepts plug-ins that enhance the functionality at almost every level—including adding support for source-control systems (like Subversion) and adding new toolsets like editors and visual designers for domain-specific languages or toolsets for other aspects of the software development lifecycle (like the Team Foundation Server client: Team Explorer). Visual Studio......

Words: 1330 - Pages: 6

Free Essay

Object Oriented Programming Definitions

...Polymorphism Polymorphism is the ability of an object to take on many forms. This can be where a child class is created and extends a parent class to inherit their common variables and add new variables to match the requirements Public interface Food {} Public class Burger {} Public class Bigmac extends Burger implements Food {} Class A class is a blue print from which individual objects are created and modified. There are three type of variables Local variables: Variables that are defined inside method Instance variables: Instance variables are variables within a class but outside any method Class variables: Class variables are variables declared with in a class Interface An interface is a reference type in Java and is made up of a collection of abstract methods. A class implements an interface and inherits the abstract methods of the interface. It can never be declared only implemented Public human { Public void eat (); Public void drink (); } Object This is a representation of a real world entity Objects have states and behaviours. For example a human has states - name, race as well as behaviours –talking, eating etc. An object is also an instance of a class. Public Shivam ( String name, String age){ System.out.print(“My name is” + name + “And my age is” + age); } Constructor Generally used in classes, if the programmer does not create a constructor for the class there is a default one. Objects use this in their creation and needs to......

Words: 601 - Pages: 3