1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

Computer Programming w/ Eng. Applications
Mathematical Operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming in.
CS 201 Functions Debzani Deb.
AlgoTutor Tutorial (3) Program Pad J. Yoo, S. Yoo, C. Pettey, S. Seo, and Z. Dong MTSU Computer Science Department Making the transition from the algorithm.
1 Project 6: Cats in Tree. 2 Project 3: Cats in Tree In this project you will Create a class definition for a Cat class. Populate a BST with Cat information.
1 Project 7: Huffman Code. 2 Extend the most recent version of the Huffman Code program to include decode information in the binary output file and use.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
Putting Applets into Web Pages.  Two things are involved in the process of putting applets onto web pages ◦ The.class files of the applet ◦ The html.
1 Project 4: Vehicle Inventory. 2 Write a program to read a text file containing information about vehicles and output the information First in the order.
VARIABLES & CONSTANTS. Objective By the end of the lesson students should be able to:  Define a constant  Define a variable  Understand the rules for.
1 C++ Programming Basics Chapter 2 Lecture CSIS 10A.
How to start Visual Studio 2008 or 2010 (command-line program)
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
C OMPUTER P ROGRAMMING 1 Assignment. A SSIGNMENT We have used gets to input a value into variable The second way to give a variable a value is known as.
1 FUNCTIONS - I Chapter 5 Functions help us write more complex programs.
11 Project 2 Towers of Hanoi. 22 Towers of Hanoi is a well known puzzle that can be very difficult to solve manually but can be programmed very easily.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
VARIABLES Programmes work by manipulating data placed in memory. The data can be numbers, text, objects, pointers to other memory areas, and more besides.
1 Project 5: Printing Address Labels. 2 Assignment Write a Windows forms program to display and print a set of address labels. Input from a csv file.
Overview of c++ Objectives 1. Understanding the use of the following elements in a c++ program variables constants assignment input output 2. Writing a.
1 Project 3 The Kumquat Society Conference. 2 Conference Registration In this project you will write a program to handle a conference registration. The.
Project 3: Ticket Printer
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Computer Science I Variables. Methods. Classwork/Homework: Re-do or do new drawing using variables & function(s). Zip folder and upload to Moodle dropbox.
Chapter 3 Numerical Data. Objectives After you have read and studied this chapter, you should be able to Select proper types for numerical data. Write.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
Introduction to Programming Python Lab 3: Arithmetic 22 January PythonLab3 lecture slides.ppt Ping Brennan
Exercise 1 #include int main() { printf(“Hello C Programming!\n”); return 0; } 1.Run your Visual Studio 2008 or Create a new “project” and add.
1 Project 3 String Methods. Project 3: String Methods Write a program to do the following string manipulations: Prompt the user to enter a phrase and.
Introduction Chapter 1 1/22/16. Check zyBooks Completion Click on the boxes for each section.
Calculator Program Explained by Arafa Hamed. First Designing The Interface Ask yourself how many places are there that will be used to input numbers?
Introduction to Programming
1 Project 2: Sorting Cats. Write a C++ console application to read a text file containing information about cats and output the information to the screen.
Homework 1 (due:April 8th) Deadline : April 8th 11:59pm Where to submit? eClass “ 과제방 ” ( How to submit? Create a folder. The name.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
1 Project 7: Looping. Project 7 For this project you will produce two Java programs. The requirements for each program will be described separately on.
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
1 Project 5: Leap Years. 222 Leap Years Write a program that reads an integer value from the user representing a year and determines if the year is a.
1 Project 4: Computing Distance. 222 Computing Distance Write a program to compute the distance between two points. Recall that the distance between the.
1 Project 4: Venue Sort. 2 This project is an exercise in Using C++ strings. Operator overloading. Text File Input.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
1 Project 15: Animals Using Derived Classes and Inheritance.
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
1 Project 6: New Venue. 2 New Venue Based on the posted New Venue scenario
1 Project 8: Tic Tac Toe. 2 Assignment Write an HTML and JavaScript page that pemits users to play Tic Tac Toe. Both players use a single browser. Alternating.
1 Project 12: Cars from File. This is an extension of Project 11, Car Class You may use the posted solution for Project 11 as a starting point for this.
Introduction to Programming
Computer Science I Variables. Methods.
Introduction to Programming
Variables, Expressions, and IO
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
One-Dimensional Array Introduction Lesson xx
Programming in JavaScript
CSCI N207 Data Analysis Using Spreadsheet
Programming in JavaScript
Programming in JavaScript
Unit 3: Variables in Java
Running a Java Program using Blue Jay.
Variables in C Topics Naming Variables Declaring Variables
MIS 3200 – Unit 6.1 Moving between pages by redirecting
GCSE Computing Mini Assignment.
The values to be assigned to the structure members are surrounded by braces and separated by commas. The first value in the list is assigned to the first.
Presentation transcript:

1 Project 2: Using Variables and Expressions

222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What you need to do for each program is described on the following slides.

333 Circle.java An initial version of Circle.java is available for download. Create a folder named Circle in a convenient location. Download the file Circle.java from the Downloads area of the class web site to your Circle folder. Study Circle.java and try to understand how it works. See next slide

444 Circle.java Some things to notice: The first three lines inside main are declarations for PI, radius, and area. Note that the type for each is given in these lines: final double for PI, since it is a floating point constant; int for radius, since it is an integer variable, and double for area, since it will hold the product of the radius and PI, resulting in a floating point value. These first three lines also hold initializations for PI, radius, and area. These could have been done separately, but it is often convenient to assign an initial value when a variable is declared. The next line is simply a print statement that shows the area for a circle of a given radius. The next line is an assignment statement, giving variable radius the value 20. Note that this is not a declaration, so the int that was in the previous radius line does not appear here. The same memory location that used to hold the value 10 now holds the value 20—we are not setting up a new memory location. Similar for the next line—no double because area was already declared. The final print statement prints the newly computed area of the circle with the new radius.

555 Add Circumference to Circles Program The circumference of a circle is two times the product of pi and the radius. Add statements to this program to compute the circumference in addition to the area for both circles. You will need to do the following: Declare a new variable to store the circumference. Compute the circumference for each value of the radius and store it in that variable. Add two println statements to show your results. Be sure your results are clearly labeled. Compile and test the modified program.

666 Compute Change When the radius of a circle doubles, what happens to area and circumference? Do they double as well? You can determine this by dividing the second area by the first area. Unfortunately, as it is now the program overwrites the first area and circumference with the second area and circumference. You need to save the first area and circumference you compute instead of overwriting them with the second set of computations. So you'll need two area variables and two circumference variables, which means they'll have to have different names (e.g., area1 and area2). Remember that each variable will have to be declared.

777 Compute Change Modify the program as follows: Add declarations for the area and circumference of the second circle. Use the new variables when calculating area and circumference of the second circle. Change the println statements for the second circle to use the new variables. At the end of the program, compute the area change by dividing the second area by the first area. This gives you the factor by which the area grew. Store this value in an appropriately named variable (which you will have to declare). Add a println statement to print the change in area that you just computed. Now repeat the last two steps for the circumference. Save the file, compile, and run it. Correct mistakes if necessary.

888 Painting a Room File Paint.java, available in the Downloads area of the class web site, contains a partial program, which when complete will calculate the amount of paint needed to paint the walls of a room of the given length and width. It assumes that the paint covers 350 square feet per gallon.

999 Paint.java Create a folder named Paint in a convenient location. Download the file Paint.java from the Downloads area of the class web site to your Paint folder. Fill in the missing statements so that the program does what it is supposed to. (Comments tell you what to fill in where.) Compile and run the program and correct any errors. Suppose the room has doors and windows that don't need painting. Ask the user to enter the number of doors and number of windows in the room, and adjust the total square feet to be painted accordingly. Assume that each door is 20 square feet and each window is 15 square feet. Again compile and test the program.

10 Ideal Weight Write a program to compute the ideal weight for both males and females who are over 5 feet tall. According to one study, the ideal weight for a female who is over 5 feet tall is 100 pounds plus 5 pounds for each inch in height over 5 feet. For example, the ideal weight for a female who is 5'3" would be = 115 pounds. For a male who is over 5 feet tall, the ideal weight is 106 pounds plus 6 pounds for each inch in height over 5 feet. For example, the ideal weight for a male who is 6'2" would be *6 = 190 pounds. Your program should ask the user to enter his/her height in feet and inches (both as integers—so a person 5'3" would enter the 5 and then the 3). It should then compute and print both the ideal weight for a female and the ideal weight for a male.

11 Ideal Weight The general outline of your main function would be as follows: Declare your variables. Think about what variables you need—you need to input two pieces of information, then you need some variables for your calculations. (See the following steps.) Get the input (height in feet and inches) from the user. Compute the total number of inches of height. (Convert feet and inches to total inches). Compute the ideal weight for a female and the ideal weight for a male. (Here you basically convert the "word" description above to assignment statements). Print the answers. Plan your program, then type it in, compile and run it. Be sure it gives correct answers.

12 Submission Put your three Java source files into a folder and zip the folder. In Windows, right click on the folder, select "Send to" then select "Compressed (zipped) folder".

13 Submission Submit your zipped Java source files via Canvas Assignments. Project is due by 11:59 PM Monday, January 25 All Sections

14 Ground Rules Do not share your code with other students Before or after submitting the project. OK to discuss the project. Do not copy any other student’s code. Or even look at it. Do not let anyone copy or examine your code.