Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Homework 2 CMP 167: Programming Methods I Lehman College, City University of New York Problem definitions for this homework assignment are found on the pages

Homework 2

CMP 167: Programming Methods I

Lehman College, City University of New York

Problem definitions for this homework assignment are found on the pages that follow below.

A note on formatting in the problem definitions:

Text that is in boldface represents values input by the user.

Text that is underlined represents values that are calculated by the program.

Homework 2-1

Write a program named IntegerExpressions that asks the user for three integers.

The program must then output results based on the following calculations:

firstResult = The sum of firstInt and secondInt divided by thirdInt

secondResult = The product of secondInt and thirdInt divided by the sum of secondInt and firstInt

thirdResult = The product of firstInt and thirdInt mod by the secondInt

Note:

firstInt, secondInt, and thirdInt represent the three integers entered by the user.

firstResult, secondResult, and thirdResult represent the results of the calculations.

n mod m means the remainder obtained when n is divided by m.

The prompt to the user to enter the integers must be:

Enter firstInt: Enter secondInt: Enter thirdInt:

The output must be in the format:

First Result = firstResult Second Result = secondResult Third Result = thirdResult

Please make sure to end each line of output with a newline.

Please note that your class should be named IntegerExpressions.

Homework 2-2

Write a program named YardsFeetInches that asks the user to enter a distance measured in inches.

The program must then determine and output the equivalent number of yards, feet, and inches.

Note:

3 feet = 1 yard

12 inches = 1 foot

Use plurals "yards" , feet, and "inches" for all outputs (even where it is grammatically incorrect).

The prompt to the user to enter the number of inches must be:

Enter number of inches:

The output must be in the format:

numYards yards, numFeet feet, and numInches inches.

For a sample run where the user enters 367 the console screen must look as follows:

Enter number of inches: 367

10 yards, 0 feet, and 7 inches.

Please make sure to end each line of output with a newline.

Please note that your java class should be named YardsFeetInches.

Homework 2-3

Write a program named CircleSphere that prompts the user for a double value representing a radius.

The program must then use the radius to determine and output the following:

circleCircumference = 2r

circleArea = r2

sphereArea = 4r2

sphereVolume = (4/3)r3

Note:

You must use as defined in the java.lang.Math class.

Recall that int, float,and double divisions produce different results.

Recall that there are multiple ways to calculate r2 and r3.

Recall that floating point arithmetic rounds differently for different formulations of a calculation.

The prompt to the user to enter the radius must be:

Enter radius:

The output must be in the format:

Circle Circumference = circleCircumference Circle Area = circleArea Sphere Area = sphereArea Sphere Volume = sphereVolume

Please make sure to end each line of output with a newline.

Please note that your class should be named CircleSphere.

Homework 2-4

Write a program named DistanceFormula that prompts the user for the coordinates of two points in a Cartesian Plane.

The program must then compute and output the distance between those points.

Note:

All coordinates need to be double values.

In a cartesian plane the distance between two points, P1 = (x1, y1) and P2 = (x2, y2), is given by the formula

The prompt to the user must be:

Coordinates for P1 Enter x1: Enter y1: Coordinates for P2 Enter x2: Enter y2: The output must be in the format:

Distance between P1 and P2 = dist

Please make sure to end each line of output with a newline.

Please note that your class should be named DistanceFormula.

Homework 2-5

Write a Java program named Words that asks the user to enter four words.

The program should then analyze each of the four words so that it can report the length of each word as well as the positions of the five vowels within each word.

For a sample run where the user enters the words: she smiles third frisbee

the console screen must look as follows:

Enter 4 words: she smiles third frisbee Word 1 = "she" Length = 3 position of vowels: 'a' = -1, 'e' = 2, 'i' = -1, 'o' = -1, 'u' = -1

Word 2 = "smiles" Length = 6 position of vowels: 'a' = -1, 'e' = 4, 'i' = 2, 'o' = -1, 'u' = -1

Word 3 = "third" Length = 5 position of vowels: 'a' = -1, 'e' = -1, 'i' = 2, 'o' = -1, 'u' = -1

Word 4 = "frisbee" Length = 7 position of vowels: 'a' = -1, 'e' = 5, 'i' = 2, 'o' = -1, 'u' = -1

For a sample run where the user enters the words: shoe shoe chime wallabees

the console screen must look as follows:

Enter 4 words: shoe shoe chime wallabees Word 1 = "shoe" Length = 4 position of vowels: 'a' = -1, 'e' = 3, 'i' = -1, 'o' = 2, 'u' = -1

Word 2 = "shoe" Length = 4 position of vowels: 'a' = -1, 'e' = 3, 'i' = -1, 'o' = 2, 'u' = -1

Word 3 = "chime" Length = 5 position of vowels: 'a' = -1, 'e' = 4, 'i' = 2, 'o' = -1, 'u' = -1

Word 4 = "wallabees" Length = 9 position of vowels: 'a' = 1, 'e' = 6, 'i' = -1, 'o' = -1, 'u' = -1

Note:

For multiple instances of a vowel, only the index of the first occurrence will be indicated.

An index of -1 indicates that the vowel does not occur in the word.

Please make sure to end each line of output with a newline.

Please note that your class should be named Words.

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

Apply your own composing style to personalize your messages.

Answered: 1 week ago

Question

Format memos and e-mail properly.

Answered: 1 week ago