IT1090cLab3
.docx
keyboard_arrow_up
School
University of Cincinnati, Main Campus *
*We aren’t endorsed by this school
Course
1090
Subject
Computer Science
Date
Dec 6, 2023
Type
docx
Pages
8
Uploaded by MegaRainMandrill31
IT 1090C Computer Programming I
Prof. Tom Wulf
Lab 3 Looping
15 pts
/ 6 extra
Mini-lecture:
We will continue to refine our pseudo code.
Now, we will look at looping
We looked at looping in class. Java has a while loop and a for loop.
These are both pre-test
loops.
The for loop is a definite loop and the while loop is an indefinite loop.
(Java also has a
post-test indefinite loop:
do..while.
Here is the flowchart and the pseudo code for an indefinite loop that uses a sentinel to terminate
the repetition of the loop.
In this variation the sentinel is the value “N” which the user enters
when they are prompted if they want to continue or not.
Here is the general format for the while loop in pseudo code:
while BOOLEAN EXPRESSIO
statements here that will be repeated
endWhile
As discussed, Boolean expressions are expressions that evaluate to true or false.
These are
formed by relational operators (<. >,< =,>=, !=) and the logical operators AND && and OR ||.
Copyright © 2019-2020, University of Cincinnati, Ohio. All rights reserved.
For loops:
For loops are definite pre-test loops.
Use these when you want to repeat something some fixed
number of times.
Copyright © 2019-2020, University of Cincinnati, Ohio. All rights reserved.
Pseudo code for the for loop:
for count = 1 to 5 step 1
these statements repeat
endFor
Pseudo code for the do .. while loop
do
these statements repeat
while BOOLEAN EXPRESSION
Which to use?
Use a
while loop
when you don’t know exactly how many times the loop will repeat (indefinite
loop)
Use a
for loop
when you know exactly how many times the loop will repeat (definite loop)
Both these loops are pre-test loops which means that if the first test fails (is false) then the
statements in the loop body are never executed.
The
do while
loop is also indefinite but is post test so that loop runs the code block at least once
before the first test.
Every time you get input you do this. You collect data and plan to loop back
only to correct it!
Lab:
1.
Just submit this document (See directions below.) and insert your work after each task
description.
2.
For each of the following tasks, provide the complete pseudo code including all
elements that we have been using (i.e. class, end class, main return, output prompt).
Be sure to declare your variables and use symbolic constants where appropriate.
Determine if each task requires a definite or indefinite loop and use the correct one.
Use the do while loop for loops that you want to execute at least once, like getting
input.
a.
Task 1 (3 pts): an application program where the user enters the price of
a series of items (assume at least one.)
(Prompt user for additional items
until they are done, so we don’t know ahead how many items there will
be.
This is the looping part!
;) ) The program computes shipping costs.
Copyright © 2019-2020, University of Cincinnati, Ohio. All rights reserved.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
11.
arrow_forward
PROBLEM STATEMENT:
An anagram is a word that has been rearranged from another word, check tosee if the second word is a rearrangement of the first word.
public class AnagramComputation{public static boolean solution(String word1, String word2){// ↓↓↓↓ your code goes here ↓↓↓↓return true;}}
Can you help me with this java question the language is java please use the code I gave
arrow_forward
This needs to be done in Java!
(Sales Commission Calculator) A large company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9% of their gross sales for that week. For example, a salesperson who sells $5,000 worth of merchandise in a week receives $200 plus 9% of $5,000, or a total of $650. You’ve been supplied with a list of the items sold by each salesperson. The values of these items are shown below. Develop a Java application that inputs one salesperson’s items sold for last week and calculates and displays that salesperson’s earnings. There’s no limit to the number of items that can be sold.
Item Value
1 239.99
2 129.75
3 99.95
4 350.89
Example Output:
Enter number sold of product #1: 10Enter number sold of product #2: 20Enter number sold of product #3: 30Enter number sold of product #4: 40Earnings this week: $2182.61
NOTES:
Do not create a separate class for this program. Create the…
arrow_forward
Please answer 6 and 7 as they are associated altogether.
6. The FixProgram.java below has some errors.a. Fix the errors so that the program successfully compiles and runs.
class FixProgram{ public static void main(String[] args) { System.out.println('Hello World!') }}
7. Change the SampleProgram.java program below.a. So that it displays Programming is fun! Instead of Hello World!
class SampleProgram{ public static void main(String[] args) { System.out.println("Hello World!"); }}
arrow_forward
java / eclipse
arrow_forward
Use java language to code this.
arrow_forward
[Python Language]
Using loops of any kind, lists, or Sets is not allowed.
Sloan’s Book Collection
Sloan loves reading books. She recently started reading an AI generated series called “Harry Trotter”.
Sloan is collecting books from the series at her nearest bookstore. Since the series is AI generated, the publishers have produced an infinite collection of the books where each book is identified by a unique integer. The bookstore has exactly one copy of each book.
Sloan wants to buy the books in the range [l,r], where l ≤ r. As an example, the range [−3,3] means that Sloan wants to buy the books − 3, − 2, − 1, 0, 1, 2, and 3.
Pam also loves the series (or maybe annoying Sloan– who knows, really), and he manages to sneak into the bookstore very early to buy all of the books in the range [d,u], where d ≤ u. When Sloan later visits, sadly she will not find those books there anymore.
For example, if Sloan tries to buy books [−2,3] and Pam has bought books [0,2], Sloan would only receive…
arrow_forward
Java program.
arrow_forward
b nvbnvbnbnb
arrow_forward
Computer Science
JAVA: If you wanted to test two variables for equivalency, what operator do you use? Give two circumstances in which that operator does not perform as expected, and why.
arrow_forward
In-Class Exercise 6
A set of linear equations is given:
10 x₁ + 4x₂ - 2x3 = 26
4x₁ - 8x₂ + x3 = 0
2
2x₁ + x₂ - 5x3 = 40
4
1) Solve the equations by using Gauss-Seidel iterative method. Do it
"by hand" (you can use matlab for arithmetic calculations). Start
with guessing answer [X1 X2 X3] = [0 0 0] and try at least three
iterations.
2) Use power method to find the smallest eigenvalue of the
coefficient matrix. (hint: use inverse of coefficient matrix, then
apply power method to find largest eigenvalue. Take inverse of
that eigenvalue)
3) Find all eigenvalues and their corresponding eigen vectors of the
coefficient matrix.
arrow_forward
java-matlab
arrow_forward
Write Java code please
arrow_forward
Welcome to the era of Aladdin and the great magic lamp. This is 1st of January and Aladdin will be in jail for one year. He was recently caught for helping forty thieves. Now he has nothing to do. But he knows that Jasmine is waiting for him. At some point he got an idea to give Jasmine a magical program that can find intervals of months from a year. This allows her to easily determine how long it will take for Aladdin to get out. Then Aladdin rubs the magic lamp and The Genie appears. Then he asked The Genie to make such a magical program.
Unfortunately the Genie doesn't know programming and he wants your help to create that magical program. Genie will give you N as the day of the year and you have to print in which month that day is.
Input Format
Input will contain one line with a single integer N, day of the year.
Constraints
1 <= N <= 365
Output Format
Print a single line containing the name of month. Be careful about the newline ('\n') at the end.
Sample Input 0
1
Sample…
arrow_forward
write a code in java (using recursion)
arrow_forward
*** Complete in Java Program**
Use Gambler's Ruin Example
Gambler's ruin. Suppose a gambler makes a series of fair $1 bets, starting with $50, and continue to play until she either goes broke or has $250. What are the chances that she will go home with $250, and how many bets might she expect to make before winning or losing? Gambler.java is a simulation that can help answer these questions. It takes three command-line arguments, the initial stake ($50), the goal amount ($250), and the number of times we want to simulate the game.
Implement and modify Gambler's ruin simulation from the textbook or textbook website. Modify, to show the results from several simulations not only one, in a formatted table. Compute the average over all simulations.
arrow_forward
Can u solve this ?
arrow_forward
I am trying to complete this assignment in Java.
arrow_forward
Problem specification:
There is a grid of NXN squares. We can easily determines how many different rectangles (squares are excluded) there are in the grid. For example, in a 3X3 grid, you can find 22 different rectangles, marked as the green rectangles. You can see that we did not count the red ones as they are squares. In this assignment, you will write a Java program that takes the value
of N as input and determines the total area of all the rectangles in the grid. Assume that the smallest squares in the grid have length 1. So a 3X2 rectangle will have an area of 6. For example, the total area of all the rectangles in the 3X3 grid is 66.…
arrow_forward
Answer just a & b in Java please
arrow_forward
Four of Java's looping control structures are while loops, do-while loops, while-do and for loops.
True or False
arrow_forward
write by java language
Write a program that will display the prime numbers in a given range. The program should allow users toenter the lower and upper limits. The program should adopt looping and method techniques as follows:o A method to control user inputs (lower and upper limits)o (A) loop(s) to identify prime numberso A method to display the prime number
arrow_forward
Solve all three by java Programming
arrow_forward
For the code in java below it shows a deck of 52 cards and asks the name of the two players and makes both players draw five cards from the deck. The code also makes Player A pick a card and Player B has to pick two cards that equal the same value as Player A's card.
What I want to be added to the code if for the cards that have been used to be removed and replaced with the other cards in the deck and for the next round to begin with Player B picking a card and Player A picking two cards that equal the same value as Player B's card.
I also want the game to keep going between Player A and B until the cards in the deck run out.
Main class code:
import java.util.ArrayList;
import java.util.Scanner;
import java.util.List;
import java.util.Random;
class Main {
publicstaticvoid main(String[] args) {
String[] suits = {"Hearts", "Clubs", "Spades", "Diamonds"};
String[] numbers = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
for(String oneSuit : suits){
for(String num :…
arrow_forward
Mailings
Review
View
ell me what you want t
Help
Design
Layout
References
imes New Romar -
12
A A
Aa v
ab
、三
B
IU abs X, x A
Paragraph
Font
Objective(s):
You are required to write a program in JAVA based on the problem description given. Read the
problem description and examine the sample of output; then study the program design given.
Using the problem-solving tips as a guide, write a complete program with necessary useful
comment for good documentation. Compile and execute the program.
Learning Outcome(s):
1. To introduce business problem specification/requirement and translates into JAVA codes.
2. To practice writing simple application of deploying object-oriented programming concept using
JAVA.
DESCRIPTION OF PROBLEM:
Write a program contained a class Student which has firstName, lastName, mark, grade. The
class allows object instance to assign firstName, lastName and mark from input user and
perform and assign grade based on mark's criteria displayed below.
SAMPLE OF OUTPUT:
Enter…
arrow_forward
DTA STRUCTURE AND ALGORITHM .
You have given a n pair of brackets. Your task is to find the number of ways that you can put those brackets in such a way that they will be always balanced.( A balanced pair is that if there are opening brackets there will always a closing brackets for them). Your code must be optimised. Programing language: Java..
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Related Questions
- 11.arrow_forwardPROBLEM STATEMENT: An anagram is a word that has been rearranged from another word, check tosee if the second word is a rearrangement of the first word. public class AnagramComputation{public static boolean solution(String word1, String word2){// ↓↓↓↓ your code goes here ↓↓↓↓return true;}} Can you help me with this java question the language is java please use the code I gavearrow_forwardThis needs to be done in Java! (Sales Commission Calculator) A large company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9% of their gross sales for that week. For example, a salesperson who sells $5,000 worth of merchandise in a week receives $200 plus 9% of $5,000, or a total of $650. You’ve been supplied with a list of the items sold by each salesperson. The values of these items are shown below. Develop a Java application that inputs one salesperson’s items sold for last week and calculates and displays that salesperson’s earnings. There’s no limit to the number of items that can be sold. Item Value 1 239.99 2 129.75 3 99.95 4 350.89 Example Output: Enter number sold of product #1: 10Enter number sold of product #2: 20Enter number sold of product #3: 30Enter number sold of product #4: 40Earnings this week: $2182.61 NOTES: Do not create a separate class for this program. Create the…arrow_forward
- Please answer 6 and 7 as they are associated altogether. 6. The FixProgram.java below has some errors.a. Fix the errors so that the program successfully compiles and runs. class FixProgram{ public static void main(String[] args) { System.out.println('Hello World!') }} 7. Change the SampleProgram.java program below.a. So that it displays Programming is fun! Instead of Hello World! class SampleProgram{ public static void main(String[] args) { System.out.println("Hello World!"); }}arrow_forwardjava / eclipsearrow_forwardUse java language to code this.arrow_forward
- [Python Language] Using loops of any kind, lists, or Sets is not allowed. Sloan’s Book Collection Sloan loves reading books. She recently started reading an AI generated series called “Harry Trotter”. Sloan is collecting books from the series at her nearest bookstore. Since the series is AI generated, the publishers have produced an infinite collection of the books where each book is identified by a unique integer. The bookstore has exactly one copy of each book. Sloan wants to buy the books in the range [l,r], where l ≤ r. As an example, the range [−3,3] means that Sloan wants to buy the books − 3, − 2, − 1, 0, 1, 2, and 3. Pam also loves the series (or maybe annoying Sloan– who knows, really), and he manages to sneak into the bookstore very early to buy all of the books in the range [d,u], where d ≤ u. When Sloan later visits, sadly she will not find those books there anymore. For example, if Sloan tries to buy books [−2,3] and Pam has bought books [0,2], Sloan would only receive…arrow_forwardJava program.arrow_forwardb nvbnvbnbnbarrow_forward
- Computer Science JAVA: If you wanted to test two variables for equivalency, what operator do you use? Give two circumstances in which that operator does not perform as expected, and why.arrow_forwardIn-Class Exercise 6 A set of linear equations is given: 10 x₁ + 4x₂ - 2x3 = 26 4x₁ - 8x₂ + x3 = 0 2 2x₁ + x₂ - 5x3 = 40 4 1) Solve the equations by using Gauss-Seidel iterative method. Do it "by hand" (you can use matlab for arithmetic calculations). Start with guessing answer [X1 X2 X3] = [0 0 0] and try at least three iterations. 2) Use power method to find the smallest eigenvalue of the coefficient matrix. (hint: use inverse of coefficient matrix, then apply power method to find largest eigenvalue. Take inverse of that eigenvalue) 3) Find all eigenvalues and their corresponding eigen vectors of the coefficient matrix.arrow_forwardjava-matlabarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT