Question

3.a.Imagine you have a box of asterisks (*). Write a psuedocode that will instruct a person...

3.a.Imagine you have a box of asterisks (*). Write a psuedocode that will instruct a person to stack fifteen *s into the arrangement below. Write the solution in a way that can be generalized easily to larger arrangements.

*
**
***
****
*****

3.b Imagine you have a box of asterisks (*). Write a psuedocode that will instruct a person to stack nine *s into the arrangement below. Write the solution in a way that can be generalized easily to larger arrangements.

*
***
*****

3.c. It’s ok to make errors. In fact, the more errors you make, the quicker you will become an expert Java programmer. Each error can teach you an important lesson. So, let’s make a few errors by experimenting with the HelloWorldClasswork1 program.

a) Try deleting the only semicolon. What happens when you compile? Fix the error.

b) Try deleting the left brace under the main method and compiling your program. What happens? Fix the error.

c) Delete the first left brace in the program. What happens when you compile? Fix the program.

d) Change main to Main. Does the program compile? What is the problem

3.d. Assume you are a bank manager and you want to teach the tellers in the bank how to count the paper currency in their teller drawers. Write pseudocode for a method of counting the money.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

3.a)

Java code:

import java.util.*;
import java.lang.*;
import java.io.*;


class star
{
   public static void main (String[] args)
   {
       int k,j,n;
       System.out.println("Please enter how many stars do you have?");
       Scanner sc = new Scanner(System.in);
       n= sc.nextInt();
j=1;
  
while(j<=n)
{
for(k=1;k<=j;k++)
{
System.out.print("*");
}
System.out.println("\n");
n=n-j;
j++;
  
}
   }
}
Output:

Please enter how many stars do you have?

15
*

**

***

****

*****

b)

import java.util.*;
import java.lang.*;
import java.io.*;


class star
{
   public static void main (String[] args)
   {
       int k,j,n;
       System.out.println("Please enter how many stars do you have?");
       Scanner sc = new Scanner(System.in);
       n= sc.nextInt();
j=1;
  
while(j<=n)
{
for(k=1;k<=j;k++)
{
System.out.print("*");
  
}
System.out.println("\n");
n=n-j;
j=j+2;
  
}
   }
}
Output:

Please enter how many stars do you have?

9
*

***

*****

Add a comment
Know the answer?
Add Answer to:
3.a.Imagine you have a box of asterisks (*). Write a psuedocode that will instruct a person...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Prelab Exercises Your task is to write a Java program that will print out the following...

    Prelab Exercises Your task is to write a Java program that will print out the following message (including the row of equal marks): Computer Science, Yes!!!! ========================= An outline of the program is below. Complete it as follows: a. In the documentation at the top, fill in the name of the file the program would be saved in and a brief description of what the program does. b. Add the code for the main method to do the printing. //...

  • Lab 3 Step One First, create an empty directory for lab3. There is no starter code for this lab. You will be throwing an...

    Lab 3 Step One First, create an empty directory for lab3. There is no starter code for this lab. You will be throwing and catching exceptions in this exercise. Create a file called RuntimeException.h and put the following code in it. #include <string> class RuntimeException { private: string errorMsg; public: RuntimeException(const string& err) { errorMsg = err; } string getMessage() const { return errorMsg; } } Step Two In a new .cpp file in your directory, write a main function...

  • Project 1, Program Design 1. Write a C program replace.c that asks the user to enter...

    Project 1, Program Design 1. Write a C program replace.c that asks the user to enter a three-digit integer and then replace each digit by the sum of that digit plus 6 modulus 10. If the integer entered is less than 100 or greater than 999, output an error message and abort the program. A sample input/output: Enter a three-digit number: 928 Output: 584 2. Write a C program convert.c that displays menus for converting length and calculates the result....

  • Lab 3 – Array-Based Stack and Queue Overview In this assignment, you will be implementing your...

    Lab 3 – Array-Based Stack and Queue Overview In this assignment, you will be implementing your own Array-Based Stack (ABS) and Array-Based Queue (ABQ). A stack is a linear data structure which follows the Last-In, First-Out (LIFO) property. LIFO means that the data most recently added is the first data to be removed. (Imagine a stack of books, or a stack of papers on a desk—the first one to be removed is the last one placed on top.) A queue...

  • Introduction In this lab we will look at the information given by thrown exceptions. In particular,...

    Introduction In this lab we will look at the information given by thrown exceptions. In particular, we will see that a given design does not give the most useful information that it could. We will explore how to fix it. The Program We have three classes in the project. StringArray is similar to the class in the homework, with much functionality removed. Names is meant to be a collection of names that has a StringArray used to store them. It...

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

  • Reverse Polish (HP) Style Calculator - Part 3 The purpose of this assignment is to build...

    Reverse Polish (HP) Style Calculator - Part 3 The purpose of this assignment is to build the business calculator using supporting files built in Topics 4 and 5. Create a Java application file named RPN.java containing a main method by using the ForthStack.java and associated files from Topic 5. The application should have one text box for numeric data entry, one text box for numeric display, one text box for error display, and buttons labeled "+", "-", "*", "/", "dup",...

  • I have updated my previously posted C++ question to ensure that I have included all of...

    I have updated my previously posted C++ question to ensure that I have included all of the necessary documentation in order to complete Part 2 - Bank Account of the assigned lab in its entirety. Please note that the lab below is somewhat lengthy, and I do not expect you to answer each question! If coding the full lab is too much to ask, please focus soley on Part 2 of the lab, titled Bank Account and the subsections that...

  • Use C++ For this week’s lab you will write a program to read a data file...

    Use C++ For this week’s lab you will write a program to read a data file containing numerical values, one per line. The program should compute average of the numbers and also find the smallest and the largest value in the file. You may assume that the data file will have EXACTLY 100 integer values in it. Process all the values out of the data file. Show the average, smallest, largest, and the name of the data file in the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT