Ask Programming Language Expert

Other objectives include:

Use static methods.
Use local variables.
Use arithmetic expressions.
Use Scanner to input values.
Use a class constant.
Use for loops.
Hand-in Requirements

All projects and laboratories will be submitted electronically through Blackboard. Zip up your entire project directory to submit as the source. (Right click on the project folder and follow 7-Zip > Add to "project1.zip".) The project folder should include the following two files:

Tables.java
TablesOutput.txt
Tasks

prepare a program that prints

Project 1 written by YOURNAME
and calls two methods to perform the following two jobs, respectively:
Print a table showing the powers of a number entered by the user. The user should also be asked to enter the maximum exponent.
Print a table showing the results of the remainder operation, varying both numerator and denominator. The user should be asked to enter the maximum denominator and numerator.
Here is an ex of what your output should look like (user input is in bold and underlined):
Enter the base: 2
Enter the maximum exponent: 7
The base is 2 and the maximum exponent is 7.

Powers of 2

x 2^x
0 1
1 2
2 4
3 8
4 16
5 32
6 64
7 128

Enter the maximum numerator: 6
Enter the maximum denominator: 3
The maximum numerator is 6 and the maximum denominator is 3.

Remainders

n n%1 n%2 n%3
1 0 1 1
2 0 0 2
3 0 1 0
4 0 0 1
5 0 1 2
6 0 0 0
Details

The Console

You will need to use Scanner to obtain input from the keyboard. You should declare a class constant of type Scanner named CONSOLE at the beginning of your class; you should store new Scanner(System.in) in CONSOLE. See exs in the Chapter 2 lecture notes and in the Laboratory 2 assignment.

Table for Powers of a Number

Terminology: When computing 210 (2 to the 10th power), 2 is called the base and 10 is called the exponent. For convenience, we will use b to denote the base and x for the exponent.

In the first method, you should allow the user to enter two numbers, b and the maximum value for x. The table should show the results for different values of x, from 0 to the maximum value. For ex, the user might want to print different powers of 2, from x = 0 up to x = 7.

After obtaining values from the user, your method should print a title for the table, a header for each column, and a line for each value of x and bx. Use tab characters (t) to align the columns. See the ex output shown above.

You can use a for loop that counts from 0 to the maximum value for x. Before the loop, you should initialize a result variable to 1. [Note that b0 = 1.] result will be used to store the value of bx. Inside the loop, one line should be printed, and then result should be updated by multiplying it by x. [Note that this update changes result to the next power of b.]

Table for Remainders

Terminology; When computing 5 % 2, 5 is called the numerator and 2 is called the denominator. For convenience, we will use n to denote the numerator and d for the denominator.

For the second method, you should print the result of n % d for different values of n and d.

First, the method should obtain two values from the user: the maximum values for n and d. Next, the method should print a title for the table and a header for each column. The first column will be for the value of n, and the following columns will be for the values of n % d for different values of d.

Then, you should print a line for each value of n, from 1 to its maximum value. The first column should be the value of n. The following columns should be the values of n % d for different values of d.

Let's consider the pseudocode for this method step-by-step.

Pseudocode for Printing the Table for Remainders
Print headers.
Print the values in the table.
The headers for the columns need to printed in the right order with the appropriate spacing.

Task 1: Pseudocode for Printing Headers
Print title on its own line.
Print blank line.
Print a tab and n.
For each value of d from 1 up to its maximum value:
Print a tab and "n%" and d.
Print a newline.
Printing the values in the table requires a double loop.

Task 2: Pseudocode for Printing the Values in the Table
For each value of n from 1 up to its maximum value:
Print a tab and n.
For each value of d from 1 up to its maximum value:
Print a tab and n % d.
Print a newline.
Rubric

[8 Points] If your program has a method that correctly prints a table for the powers of a number.
[1 Point] For printing the table's title and headers.
[2 Points] For prompting the user for two numbers (the base and the maximum exponent).
[2 Points] For a for-loop that prints each row of the table.
[2 Points] For properly calcuating the powers of a number.
[1 Point] For properly formatting the table into columns using tabs.
[8 Points] If your program has a method that correctly prints remainders for different numerators and denominators.
[2 Points] For prompting the user for two numbers (the maximum numerator and the maximum denominator).
[2 Point] For printing the table's title and headers.
[4 Points] For properly nesting the two for loops, including printing the correct numbers, and properly formatting the table into columns using tabs.
[4 points]
If the main method of your program prints "Project 1 written by [...]" and calls the two other methods.
If your submission was a Zip file named project1.zip containing a folder named project1, which contains the other files.
If your Java program was in a file named Tables.java.
If the output of your Java program was in a file named TablesOutput.txt.
If your program contains a comment that describes what the program does and contains a descriptive comment for each method.
If your program is indented properly. 

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M985125

Have any Question?


Related Questions in Programming Language

Assignment - haskell program for regular expression

Assignment - Haskell Program for Regular Expression Matching Your assignment is to modify the slowgrep.hs Haskell program presented in class and the online notes, according to the instructions below. You may carry out th ...

Assignment task -q1 a the fibonacci numbers are the numbers

Assignment Task - Q1. (a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the ...

Question - create a microsoft word macro using vba visual

Question - Create a Microsoft Word macro using VBA (Visual Basic for Applications). Name the macro "highlight." The macro should highlight every third line of text in a document. (Imagine creating highlighting that will ...

Assignmentquestion onegiving the following code snippet

Assignment Question One Giving the following code snippet. What kind of errors you will get and how can you correct it. A. public class HelloJava { public static void main(String args[]) { int x=10; int y=2; System.out.p ...

Assignment - proposal literature review research method1

Assignment - Proposal, Literature Review, Research Method 1. Abstract - Summary of the knowledge gap: problems of the existing research - Aim of the research, summary of what this project is to achieve - Summary of the a ...

1 write a function named check that has three parameters

1. Write a function named check () that has three parameters. The first parameter should accept an integer number, andthe second and third parameters should accept a double-precision number. The function body should just ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Task silly name testeroverviewcontrol flow allows us to

Task: Silly Name Tester Overview Control flow allows us to alter the order in which our programs execute. Building on our knowledge of variables, we can now use control flow to create programs that perform more than just ...

Structs and enumsoverviewin this task you will create a

Structs and Enums Overview In this task you will create a knight database to help Camelot keep track of all of their knights. Instructions Lets get started. 1. What the topic 5 videos, these will guide you through buildi ...

Task working with arraysoverviewin this task you will

Task: Working with Arrays Overview In this task you will create a simple program which will create and work with an array of strings. This array will then be populated with values, printed out to the console, and then, w ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As