Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 1 (10 points): Write a program to prompt the user for a value of x, then calculate the value of the function fx) 2x+3x+10

image text in transcribed
Problem 1 (10 points): Write a program to prompt the user for a value of x, then calculate the value of the function fx) 2x+3x+10 evaluated for that value of x and print the result. Next, prompt the user for another value for x evaluate the function, and print the result To do this you will need to implement the following methods: public static double readDouble(String message) . Displays a message to the user, reads a double and returns it. The message is passed to the method as an input parameter public static double square(double x) . o Calculates the square of a number. For example, if x 2 then, square(x) will return 4 public static double cube(double x) o Calculates the cube of a number. For example, if x 2 then, cube(x) will return 8 . public static double evaluate(double x) o Evaluates the function. For example, if x 2 then, evaluate(x) will return 38. . public static void displayResult String message, double result) o Displays a message to the user as well as the result In the method evaluate use the methods square and cube for calculating the square and cube of x Problem 2 (10 points): Disk capacity is usually measured in bytes, KB, MB, GB, and TB. Your goal is to write a program that asks the user to enter the disk capacity in either of the given units (KB, MB, GB, TB and bytes] and display it in bytes You will need to implement the following methods: public static long readDiskCapacity(String message) . o Asks reads the disk capacity from the user. Input should be in format: "214 KB or "340 MB" or "23 GB or "2 TB" or "234354 Bytes Since the disk capacity can be a very large value use long instead of int Take user input as a parameter to this method and get the metric entered by user Converts the disk capacity to bytes. The first parameter is the disk capacity entered by user and the o public static String getMetric(String input) * o public static double . o second is the metric he/she entered: 1024 for KB -1048576 for MB - 1073741824 for GB 1099511627776 for TB Using conditional statements on the type of metric decide on the conversion technique The method returns disk's capacity in bytes o o public static void displayCapacitylString message, double capacity) . o Displays the capacity of the disk. For this method you w use the method printf to format your output NOTE: 5 points will be given for well-constructed comments in submitted codes

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

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

suggest a range of work sample exercises and design them

Answered: 1 week ago