Question

In: Computer Science

Complete the following code segment that is intended to extract the Dirham and fils values from...

Complete the following code segment that is intended to extract the Dirham and fils values from a price given as a floating-point value; for example, a price 2.95 yields values 2 and 95 for the dirham and fils. as per the following description:

  • Assign the price to an integer variable named dirham to get the dirhmas part of the price

  • Subtract dirham from price then multiply the difference by 100 and add 0.5

  • Assign the result to an integer variable named fils

  • Display both of dirham and fils values each in a separate line

Solutions

Expert Solution

CODE:

class di_fi
{
public static void main(String[] args)
{
    // Initializing the price
    float price = 2.95f;
    // dirham part of the price
    //to do so typecast it to integer and assigning to an integer
    int dirham = (int)price;
    // fils part ,  subtracting dirham from price
    // then multiplying difference by 100 and adding 0.5
    int fils = (int) ((int)((price - dirham) * 100) + 0.5);
    // Displaying the result
    System.out.println(dirham + " dirham");
    System.out.println(fils + " fils");
}

}

output:

IF YOU HAVE ANY DOUBT PLEASE LEAVE A COMMENT.


Related Solutions

1. Write a C++ code segment to read 50 temperature values in Fahrenheit and to convert...
1. Write a C++ code segment to read 50 temperature values in Fahrenheit and to convert them to Celsius. You convert a Fahrenheit temperature to Celsius by using the following formula: Celsius = 5.0 / 9 * (Fahrenheit - 32). 2.A client has purchased 20 products in a store. Write a C++ code segment to read the unit price and the number of items of each product and to compute and print the total price of all these products.
Write assembly code for the following machine code. Assume that the segment is placed starting at...
Write assembly code for the following machine code. Assume that the segment is placed starting at location 80000. Create labels for jump and branch instructions. Indicate the actual memory addresses represented by such labels. 0010 1010 0000 1000 0000 0000 0000 1010 0001 0001 0000 0000 0000 0000 0000 0010 0000 0010 0001 0001 1000 0000 0010 0000 0000 1000 0000 0000 0100 1110 0010 0101 0000 0010 0001 0010 1000 0000 0010 0000
a. Write machine code for the following assembly code. Assume that the segment is placed starting...
a. Write machine code for the following assembly code. Assume that the segment is placed starting at location 80000. Use decimal numbers to represent each instruction. loop:         beq $s3, $s1, endwhile                  add $t0, $s3, $s4                  lw $t1, 0($t0)                  add $s0, $s0, $t1                  addi $s3, $s3, 4                  j loop endwhile: b. Write assembly code for the following machine code. Assume that the segment is placed starting at location 80000. Create labels for jump and branch instructions. Indicate the actual...
Complete the program to read in values from a text file. The values will be the...
Complete the program to read in values from a text file. The values will be the scores on several assignments by the students in a class. Each row of values represents a specific student's scores. Each column represents the scores of all students on a specific assignment. So a specific value is a specific student's score on a specific assignment. The first two values in the text file will give the number of students (number of rows) and the number...
Complete the program to read in values from a text file. The values will be the...
Complete the program to read in values from a text file. The values will be the scores on several assignments by the students in a class. Each row of values represents a specific student's scores. Each column represents the scores of all students on a specific assignment. So a specific value is a specific student's score on a specific assignment. The first two values in the text file will give the number of students (number of rows) and the number...
Question 9 What is produced from the following code segment? val = 0; do { val++;...
Question 9 What is produced from the following code segment? val = 0; do { val++; WriteLine(val); } while (val < 5); Nothing is displayed Outputs 5 thru 9 Outputs 10 Outputs 1 thru 4 Outputs 1 thru 5 Outputs 10 thru 14 Outputs 0 thru 4 Question 10 Assuming val was described as an integer and an initial value of 10, what is produced from the following code segment? do { WriteLine(val); } while (val < 10); Nothing is...
Given int B[4][4]={...}; Write a code segment that exchange the values about the main diagonal of...
Given int B[4][4]={...}; Write a code segment that exchange the values about the main diagonal of the matrix.
21. What is the output of the following segment of code if 7 is input by...
21. What is the output of the following segment of code if 7 is input by the user when asked to enter a number?____________ int num; int total = 0; cout << "Enter a number from 1 to 10: "; cin >> num; switch (num) { case 1: case 2: total = 5; case 3: total = 10; case 7: total = total + 3; case 8: total = total + 6; default: total = total + 4; } cout...
The following extract appeared in the financial statements of Sihle Limited: Sihle Limited Extract from the...
The following extract appeared in the financial statements of Sihle Limited: Sihle Limited Extract from the Statement of Comprehensive Income for the year ended 31 December 2019: R Sales 4 140 000 Cost of sales (3 490 000) Opening inventory 710 000 Purchases 3 630 000 Gross profit 650 000 Operating expenses (429 000) Operating profit 221 000 Interest  expense (35 000) Profit before tax 186 000 Taxation (52 800) Profit after tax 133 200 Additional information: Dividends paid during the...
In Python The following code is intentionally done in poor style but runs as intended. def...
In Python The following code is intentionally done in poor style but runs as intended. def main(): c = 10 print("Welcome to Roderick's Chikkin and Gravy") e = False while not e: x = input("Would you like some chikkin?") if x == "Y" or x == "y": c = f(c) else: e = True if c == 0: e = True print("I hope you enjoyed your chikkin!") def f(c): if c > 0: print("Got you some chikkin! Enjoy") return c-1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT