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

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...
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...
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...
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...
The extract below is taken from a Level Book for levels taken between 2 TBMs. Complete...
The extract below is taken from a Level Book for levels taken between 2 TBMs. Complete the Level Book entries as well as calculate the adjusted RL (reduced levels) for all entries. The misclose error can be assumed acceptable. Note: all staff readings are in meters. BS IS FS Rise Fall RL Correction Corrected RL Notes 1.379 TBM RL 175.5 2.795 PEG 1 3.215 PEG 2 0.595 PEG 3 1.270 PEG 4 1.280 3.215 CP B 1.030 PEG 5 3.045...
Please complete the following code in challenge.c. The code for main.c and challenge.h is below that....
Please complete the following code in challenge.c. The code for main.c and challenge.h is below that. (Don't edit main.c or challenge.h, only edit challenge.c) The instructions are in the comments. Hint: the_person is declared in main, so you need to define it in challenge.c using extern challenge.c #include "challenge.h" //return: struct //param: (struct person p1, struct person p2) //TODO: create a function that returns the person who has a higher GPA. // 1. if GPAs are equal, then return the...
no need to explain 11. What is output by the following code segment? boolean isHighTemp =...
no need to explain 11. What is output by the following code segment? boolean isHighTemp = true; double degree = 100.01; if (isHighTemp) if(degree >= 110) System.out.print(“Extremely Hot”); else System.out.println(“Not Hot”); A) Extremely Hot B) Not Hot C) Hot D) Extremely Hot Not Hot 12. To produce the output 2 4 6 8 10, what is the loop condition for the following loop? int n = 0; Page 3 do { n = n + 2; System.out.print(n + “ ”);...
Rewrite this code of a game of Moropinzee so that it works as intended without the...
Rewrite this code of a game of Moropinzee so that it works as intended without the "break;" in the last few lines of the code. Code: import java.util.*; public class Moropinzee { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(true) { System.out.println("Player 1 enter a number 1-5 for Monkey, Robot, Pirate, Ninja, or Zombie:"); int p1 = sc.nextInt(); while(p1<1 || p1>5) { System.out.println("Invalid choice, Player 1. Enter a number 1-5:"); p1 = sc.nextInt(); } System.out.println("Player 2...
What are the values you get from "data[,1]" and "data[,2]" in r code? Are the values...
What are the values you get from "data[,1]" and "data[,2]" in r code? Are the values from "data[,1]" are the fitted values/ yhat values? When I try "fitted(data)" I get different values from "data[,1]", I am very confused.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT