Free Essay

The Switch Statement

In:

Submitted By cybermelvz
Words 341
Pages 2
MIDTERM PROJECT
I – PROGRAM WRITERS * Melecio L. Bernido Jr. * Victor T. Singcol
II – PROBLEM:
11. Write a Java Application that calculates and prints the diameter, the circumference, or the area of the circle, given the radius. The application should input a character corresponding to one of these actions: D for diameter, C for Circumference and A for area. The user should be prompted to enter the radius in floating point form and then the appropriate letter. The output should be labeled appropriately. For example, 6.75 and A, your program should print like this:

The area of the Circle with radius 6.75 is 143.14.

Here some formulas you need:

Diameter=2r
Circumference=2∏r
Area of the circle=∏r2
III – OBJECTIVE * To create a program that will compute the area of the circle.

IV – ALGORITHM
Begin

Declare variables pie, diameter, circumference, radius , area

Prompt the user

Pie = 3.1416

Choice ==’D’
Choice==’d’

Display the Diameter with radius 6.75
Diameter = (radius)*2

Choice==’C’
Choice==’c’

Display the Circumference with the radius 6.75
Circumference = 2*(pie)*(radius)

Display the area with radius 6.75
Choice==’A’
Choice==’a’

Area = ∏ r2

Default:
Invalid

End

V – SOURCE CODE import java.util.Scanner; public class Calculation{ public static void main(String[]args){ Scanner in=new Scanner(System.in); double pie,diameter,circumference,radius,Area; String t; char choice; System.out.println("Enter D for diameter"); System.out.println("Enter C for circumference"); System.out.println("Enter A for Area"); t=in.nextLine(); choice= t.charAt(0); pie=3.1416; radius= 6.75; switch (choice){ case 'D': case 'd': diameter=radius*2; System.out.println("The diameter of the circle with radius 6.75 is " + diameter); break; case 'C': case 'c': circumference=2*pie*radius; System.out.println("The circumference of the circle with radius 6.75 is " + circumference); break; case 'A': case 'a': Area=pie*radius*radius; System.out.println("The area of the circle with radius 6.75 is " + Area); break; default: System.out.println("invalid"); break; } }
}

VI – OUTPUT

Similar Documents

Free Essay

Book Report

...Selection statements Selection is used to select which statements are to be performed next based on a condition being true or false. Relational expressions In the solution of many problems, different actions must be taken depending on the value of the data. The if statement in C I used to implement such s decision structure in its simplest form – that of selecting a statement to be executed only if a condition is satisfied. Syntax: if(condtion) statement executed if condition is true When an executing program encounters the if statement, the condition is evaluated to determine its numerical value, which is then interpreted as either true or false. If the condition evaluates to any non-0 value (positive or negative), the condition is considered as a “true” condition and the statement following the if is executed; otherwise this statement is not executed. Relational Operators In C Relational operator | Meaning | Example | < | Less than | age < 30 | > | Greater than | height > 6.2 | <= | Less than or equal to | taxable <= 200000 | >= | Greater than or equal to | temp >= 98.6 | == | Equal to | grade == 100 | != | Not equal to | number !=250 | In creating relational expressions, the relational operators must be typed exactly as given in the above table. Thus, although the following relational expressions are all valid: age > 40 length <= 50 temp >= 98.6 3 < 4 flag == done day != 5 The following are invalid: length =< 50 ...

Words: 1617 - Pages: 7

Free Essay

Life

...If statement [pic] 1. void main()   2. {   3. int a=5,b=6,c;   4. c = a + b ;   5. if (c==11)   6. printf("Execute me 1");   7. printf("Execute me 2");   8. }   9. Output : 10. Execute me 1 ////////////////////////////////////////////////////////////// Else-if Ladder in C : Decision Making [pic] 11:11 AM [pic] Admin [pic] 1 comment If Else Ladder / Else-If Clause Syntax of Else-If Ladder :  view plainprint? 1. #include   2. if(expression1)   3.  statement1;   4. else if(expression2)   5.  statement2;   6. else if(expression3)   7.  statement3;   8. else   9.  statement4;   [pic] Explanation :  • Conditions are evaluated from Top to Bottom • As soon as TRUE expression is found the statement associated with it is executed and rest of the ladder isBypassed Flowchart :  [pic] Sample Example : To find the Grade of the Student) view plainprint? 1. if (marks >= 67 )   2. printf("Distinction");   3. else if (marks >=60)   4. printf("First Class");   5. else if (marks >=55)   6. printf("Higher Second Class");   7. else if (marks >=50)   8. printf("Second Class");   9. else if (marks >=40)   10. printf("Pass Class");   11. else   12. printf("Fail");   ///////////////////////////////////////////////////////////////// If – else statement [pic] 1. void main()   2. {   3. int marks=50;   ...

Words: 1725 - Pages: 7

Free Essay

Zcen

...$birthdays['David'] = '1983-09-09'; echo('My birthday is: ' . $birthdays['Kevin']); The PHP If Statement if (condition) code to be executed if condition is true; Example1 (true statement) $my_name = "someguy"; if ( $my_name == "someguy" ) { echo "Your name is someguy!<br />"; } echo "Welcome to my homepage!"; Example2 (false statement) $my_name = "anotherguy"; if ( $my_name == "someguy" ) { echo "Your name is someguy!<br />"; } echo "Welcome to my homepage!"; Example calcIFrevised.html <html> <title>A simple math calculator</title> <body> Insert two numbers in the next form and hit submit button <br> <form action="calcal.php" method="post"> Firstnumber: <input name="num1" type="text" /><br> Secondnumber: <input name="num2" type="text" /> <input type="submit" /> </form> </body> </html> Example calcIFrevised2.php <?php $num1 = $_POST['num1']; $num2 = $_POST['num2']; $a = $num1 + $num2; $b = $num1 - $num2; echo ("The sum of the two numbers is ". $a ); echo ("<br>"); echo "The difference of the two numbers is ". $b; echo ("<br>"); if ( $a >= 10 ) { echo "above 10!<br />"; } echo "Welcome to my homepage!"; ?> The if...else Statement if (condition)   {   code to be executed if condition is true;   } else   {   code...

Words: 1002 - Pages: 5

Free Essay

Media

...C – Programming PROGRAM USING PRINTING STATEMENT AND MATHEMATICAL CALCULATION 1. 2. 3. 4. 5. 6. 7. 8. 9. Write a program to print a statement. Write a program to calculate the addition of two numbers. Write a program to multiply two numbers. Write a program to find the Arithematic operation. Write a program to swap the given numbers. Write a program to convert celcius to Fahrenheit. Write a program to find the simple and compound interest. Write a program to find the power of given value. Write a program to calculate the quadratic equation USING FOR LOOP STATEMENT 1. 2. 3. 4. 5. Write a program to print a statement using for loop. Write a program to print a statement up to n terms using for loop. Write a program to find the multiplication table. Write a program to print the start. Write a program to print the number in given format 3 2 1 2 1 1 6. Write a program to find the sum between limits. 7. Write a program to find the sum of N numbers using for loop. 8. Write a program to find the sum of digits. 9. Write a program to find the factorial number. 10. Write a program to generate the factorial number. 11. Write a program to generate fibonacci series. 12. Write a program to print the series as 1+1/2+1/3+... 13. Write a program to print the starts in triangle shape. 14. Write a program to print the number in incrementing order in triangle shape. USING IF ELSE STATEMENT 1. Write a program to find the given number is equal or not. 2. Write a program to find the given number is odd...

Words: 1078 - Pages: 5

Free Essay

Lalalallalala

... DECISION/SELECTION STRUCTURES If-Then Statements A conditional statement used in directing program flow based on multiple decision criteria. It has an equivalent to the English form: “If such-and-such is true, then do so-and-so.” General forms: A. Single Selection 1. Single line If statement 2. If…Then B. Multiple Selection 3. If…Then…Else 4. Nested If…Then.. Else 5. If…Then…ElseIf DECISION/SELECTION STRUCTURES If-Then Statements 1. Single-Line Syntax: 2. If…Then…Syntax: If [Condition] Then [Statement] If [Condition] Then [Statements] End If 3. If...Then...Else Syntax: If [Condition] Then [Statements] Else [Statements] End If DECISION/SELECTION STRUCTURES If-Then Statements 4. Nested If...Then...Else Syntax  Nesting is the process of embedding program statements in other statements  Below is the syntax for Nested If-Then Statements: If [condition1] Then [VB statements] Else If [condition2] Then VB statements If [condition3] Then [VB statements] End If Else [VB Statements] End If End If DECISION/SELECTION STRUCTURES If-Then Statements 5. If-Then-ElseIf Syntax  The ElseIf keyword is used to specify several conditions in one If/Else Statement.  Syntax: If [condition1] Then [VB statements] ElseIf [condition2] Then [VB statements] ElseIf [condition3 Then [VB statements] End If DECISION/SELECTION STRUCTURES Assigning Condition in If-Then Statements Below are condition statements that include conditional operators and results...

Words: 1412 - Pages: 6

Free Essay

Sas Certification Sample Test 50

...1---+----10---+----20---+--son Frank 01/31/89 daughter June 12-25-87 brother Samuel 01/17/51 The following program is submitted using this file as input: data work.family; infile 'file-specification'; run; Which INPUT statement correctly reads the values for the variable Birthdate as SAS date values? a. input b. input c. input d. input relation relation relation relation $ $ $ $ first_name first_name first_name first_name $ $ $ $ birthdate birthdate birthdate birthdate date9.; mmddyy8.; : date9.; : mmddyy8.; Correct answer: d An informat is used to translate the calendar date to a SAS date value. The date values are in the form of two-digit values for month-day-year, so the MMDDYY8. informat must be used. When using an informat with list input, the colon-format modifier is required to correctly associate the informat with the variable name. You can learn about • • informats in Reading Date and Time Values the colon-format modifier in Reading Free-Format Data. 2.A raw data file is listed below. 1---+----10---+----20---+--Jose,47,210 Sue,,108 The following SAS program is submitted using the raw data file above as input: data employeestats; input name $ age weight; run; The following output is desired: name age weight Jose 47 210 Sue . 108 Which of the following INFILE statements completes the program and accesses the data correctly? a. infile 'file-specification' pad; b. infile 'file-specification' dsd; SAS 中文论坛网站 http://www.mysas.net SAS 中文论坛 FTP 站 ftp://mysas.vicp.net ...

Words: 4408 - Pages: 18

Premium Essay

Excel Vba for Dummies Outline

...Excel VBA Programming Dummies Outline and Notes Jason Xu II: How VBA Works with Excel Chapter 3: Working in the Visual Basic Editor * To continue a single line of code from one line to the next, end the first line with a space followed by an underscore (_) * Option Explicit, inserted at the beginning of a VBA Module, forces variables to be defined (Should always use). Chapter 4: Introducing the Excel Object Model * A collection is a group of objects of the same type. * Workbooks: A collection of all currently open Workbook objects * Worksheets: A collection of all Worksheet objects contained in a particular Workbook object * Sheets: A collection of all sheets (regardless of their type) contained in a particular Workbook object. Contains both Worksheets and Charts. * Etc…. (collections are plural) * Referring to Objects * To reference a single object from a collection, you put the object’s name or index number in parentheses after the name of the collection: * Worksheets(“Sheet1”) * Excel won’t be able to identify the object if the quotation marks are omitted. * If Sheet1 if the first (or only) worksheet in the collection, you can also use the following reference: * Worksheets(1) * If referring to an object by its index number, use a plain number without quotation marks. * Navigating through the hierarchy * Application is at top of the hierarchy * Move...

Words: 2094 - Pages: 9

Premium Essay

Programming

...CHAPTER 2: ALGORITHM WORKBENCH (Input, processing, and output) 3. Write assignment statements that perform the following operations with the variables a, b, and c. a. Adds 2 to a and stores the result in b b. Multiplies b times 4 and stores the result in a c. Divides a by 3.14 and stores the result in b d. Subtracts 8 from b and stores the result in a 8. Write a pseudocode statement that assigns the sum of 10 and 14 to the variable total. 9. Write a pseudocode statement that subtracts the variable downPayment from the variable total and assigns the result to the variable due. 11. If the following pseudocode were an actual program, what would it display? Declare Integer a = 5 Declare Integer b = 2 Declare Integer c = 3 Declare Integer result Set result = a + b * c Display result 12. If the following pseudocode were an actual program, what would it display? Declare Integer num = 99 Set num = 5 Display num PROGRAMMING EXERCISES (Input, processing, and output) 2. Sales Prediction A company has determined that its annual profit is typically 23 percent of total sales. Design a program that asks the user to enter the projected amount of total sales, and then displays the profit that will be made from that amount. Hint: Use the value 0.23 to represent 23 percent 3. Land Calculation One acre of land is equivalent to 43,560 square feet. Design a program that asks the user to enter the total square feet in...

Words: 1054 - Pages: 5

Free Essay

Nothing

...Basic If Statement Syntax The structure of an if statement is as follows: ------------------------------------------------- if ( TRUE ) ------------------------------------------------- Execute the next statement ------------------------------------------------- if ( TRUE ) { ------------------------------------------------- Execute all statements inside the braces ------------------------------------------------- } Syntax: The syntax of an if...else statement in C++ is: ------------------------------------------------- if(boolean_expression) ------------------------------------------------- { ------------------------------------------------- // statement(s) will execute if the boolean expression is true ------------------------------------------------- } ------------------------------------------------- else ------------------------------------------------- { ------------------------------------------------- // statement(s) will execute if the boolean expression is false ------------------------------------------------- } ------------------------------------------------- ------------------------------------------------- #include <iostream> ------------------------------------------------- using namespace std; ------------------------------------------------- ------------------------------------------------- int main () ------------------------------------------------- { ------------------------------------------------- ...

Words: 1596 - Pages: 7

Free Essay

Programming

...are the IF selection statement, the IF ELSE selection statement and switch selection statement. This paper will attempt to explain selection structure and its different types and will also give a real life scenario in pseudo code. Selection Control Structure Computer programs utilize selection structures to choose from a variety of actions or processes. These processes typically have an outcome of true or false. When a program reads as true the process will be directed to the output that enables it to be true and vice versa for false processes. With computers having the ability to solve problems, make decisions and follow direction with the aide of a program it eliminates many human errors. The “IF” selection statement structure is used when there is a solitary or a collection of inputs to be executed to decide if the condition is true or false. If a process is submitted as false the “IF else” statement is rendered and the false output is passed over and the computer continues executing to the next selection structure. The IF statement structure also compares two values with relational operators: • greater than • >=greater than or equal to • >=less than or equal to • ==equal to • !=not equal to These are just a few examples of inputs of values to yield a true or false output. The switch selection structure allows users to decide from multiple options. Switch selection structure contains the operator’s case and default. The “switch” statement works by comparing variable...

Words: 505 - Pages: 3

Premium Essay

Pt1420 Unit 6 Assignment

...I’ll keep looking for other students to post their discussion assignment, as I need to assess three student discussion posts. This week, I feel it will be helpful to master the for .. each, while, and do … while control structures. Often, I use the for loop, and select case / switch, but the other loops escape my programming toolbox. This week, I learned how to program with while, do … while, and for … each. These three control structures help complete processing tasks without programming a set number of iterations, or until a boolean condition is met(or not met). Control structures that iterate a set number of times can miss processing the entirety of a data structure. Often, I use the for loop. I am very familiar with the for loop, but I want to use the other control structures more. I enjoyed learning other methods this week. This week, the for … each loop caused me to wonder. I like thinking about putting a data structure into the top of a for … each loop, and letting the computer decide how many processing iterations...

Words: 601 - Pages: 3

Premium Essay

Cmit 350 Final Project

...Technologies VI. xACME WAN - WAN Implementation and Secure Communications VII. Bibliography WAN Implementation with SOHO Skills Configuration I. Springfield Site Device and STP Configurations Problem Statement: The device hostnames on each switch are generic and default. They do not match the network topology device hostnames as delivered with the network architecture. Each switch and router must have the correct hostname configured per device. Switch>en Switch#config t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#Hostname SpringfieldSwitch1 SpringfieldSwitch1(config)# Switch>en Switch#config t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#Hostname SpringfieldSwitch2 SpringfieldSwitch2(config)# Switch>en Switch#config t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#Hostname SpringfieldSwitch3 SpringfieldSwitch3(config)# Switch>en Switch#config t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#Hostname SpringfieldSwitch3 SpringfieldSwitch3(config)# Router>en Router#config t Enter configuration commands, one per line. End with CNTL/Z. Router(config)#hostname SpringfieldRouter SpringfieldRouter(config)# Problem Statement: There is no MOTD banner provided on any switches or login banner to warn users of unauthorized access or terms of use. Without such banners...

Words: 1180 - Pages: 5

Premium Essay

How Managers Are Dealing with the Switch to Ifrs

...dealing with the switch to IFRS Xiaochen Zhang Texas A&M University-Commerce Abstract Recently, there are an increasing number of companies switching from GAAP to IFRS. The subject of this article is mainly about how managers deal with the switch to IFRS. This paper discusses the background of changing standard, and why manager must switch the standard to IFRS. At last, it points out several methods that managers should take in order to switch to IFRS. Keywords: IFRS, GAAP, switch Introduction International Financial Reporting Standards (IFRS) is a standard accounting system easy to International Accounting Standards Board (IASB) issued by the countries in the cross-border economic exchanges. IFRS is a global harmonization of financial rules to regulate the operation of financial management in accordance with international standards guidelines. For specification worldwide accounting operations of enterprises or other economic organizations, and economic, interests can be protected in a standard, and will not lead to the same calculation methods vary in terms of the criteria arising from unnecessary economic loss. However, now GAAP stands for generally accepted accounting principles and refers to business accounting practices that most U.S. companies use. The switch to International Financial Reporting Standards (IFRS) for all U.S. companies means that both accountants and managers have to learn some new practices. This switch is expected to take...

Words: 1193 - Pages: 5

Premium Essay

Codeswitching

...www.sciedu.ca/wjel World Journal of English Language Vol . 1, No. 1; April 2011 On Attitudes to Teachers’ Code-switching in EFL Classes Mingfa Yao School of English Language and Culture, Zhejiang International Studies University 140 Wen San Avenue, Hangzhou 310012, China Tel: +86-571-8157-8296 E-mail: mingfayao@163.com Received: February 27, 2011 Abstract Code-switching is commonly viewed with suspicion in EFL classes. The present article is to investigate and show the teachers and students’ attitudes to code-switching (CS) used by teachers in EFL classes in China. A four-section 20-item questionnaire was developed and distributed to the students and teachers. The data from the questionnaire were tabulated, and frequencies and percentages were conducted by SPSS program. The results display that students have the similar opinions with the teachers in most of question items. This consistency suggests that teachers and students have a similar positive attitude to teachers’ code-switching in EFL classroom. However there are some discrepancies in attitudes between the two samples in some question items. These discrepancies suggest that the use of code-switching in EFL classroom should be adapting to the practical teaching. Keywords: Code-switching, Attitude, Investigation, EFL class 1. Introduction In many cases, code-switching is commonly viewed with suspicion in EFL classes. Teachers and researchers in English as a second or foreign language have, on the whole, been concerned...

Words: 7111 - Pages: 29

Premium Essay

International Accounting

...has been some controversy among accounting professionals regarding the impact that switching to International Financial Reporting Standards (IFRS) from Generally Accepted Accounting Principles (GAAP) will have on United States corporations and investors. On November 14, 2008 there was a proposal that was later made mandatory, issued by the SEC making corporations within the United States switch to International Financial Reporting Standards for fiscal years ending after 2014. There are many disadvantages and advantages that could arise when moving to a global set of standards. International Financial Reporting Standards are a set of international accounting standards, which state how transactions and other events should be reported within financial statements. These standards are becoming the global standard for the preparation of public companies financial statements. “Approximately 120 nations and reporting jurisdictions permit or require IFRS for domestic listed companies, although approximately 90 countries have fully conformed with IFRS as promulgated by the IASB and include a statement acknowledging such conformity in audit reports. Other countries, including Canada and Korea, are expected to transition to IFRS by 2011. Mexico will require IFRS for all listed companies starting in 2012. Japan has introduced a roadmap for adoption that it will decide on in 2012 (with a proposed adoption date of 2015 or 2016) and is permitting certain qualifying domestic...

Words: 1313 - Pages: 6