Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.*; public class Lines { public static Scanner kbd; public static void main(String[] args) { kbd = new Scanner(System.in); kbd.close(); } /** * Prints

import java.util.*;

public class Lines { public static Scanner kbd;

public static void main(String[] args) { kbd = new Scanner(System.in); kbd.close(); }

/** * Prints a line of asterisks to the screen * @param numAsterisks The number of asterisks to be printed */ public static void printLine(int numAsterisks) {

} }

(Sample Code)

Create a new Java class called: Lines

Write a program that will display a series of asterisks across the screen. The number of asterisks that you should print will be entered by the user.

You should begin the program by asking the user how many asterisks to print. After retrieving this number, your program should print the requested number of asterisks, all on the same line. Make sure that the "line-break" character is printed after the last asterisk.

For example, if the user enters 5, then your program should display this:

*****

If the user enters 2, then your program should display this:

**

If the user enters 10, then your program should display this:

**********

Program Restrictions

The main program should only do two major things:

Get the input from the user.

Use a method named printLine to display the output on the screen.

You must write and use a method called printLine. This method IS NOT ALLOWED to get any values from the user/keyboard that task should be handled by the main program. This method should be given an integer value from the main program. This integer tells the method how many asterisks should be printed to the screen. The method, then, should simply print the requested number of asterisks, followed by a line break character.

The main program is NOT ALLOWED to print any asterisks to the screen. It MUST call on the printLine method, and let the printLine method take care of the printing the asterisks.

The keyboard object is declared as a class (global) variable as discussed in our class example. You are NOT allowed to use any other class (global) variables in this program. All other variables must be declared as local.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

2. What is the impact of information systems on organizations?

Answered: 1 week ago

Question

Evaluate the impact of technology on HR employee services.

Answered: 1 week ago