1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
anzhelika [568]
3 years ago
7

Write convert() method to cast double to int

Computers and Technology
1 answer:
Oksanka [162]3 years ago
3 0

Answer:

Explanation:

The code provided is written in Java. The statement is provided right under the /*Type your code here*/. In Java, in order to case one primitive to another you simply need to type the primitive type that you are trying to cast too before the variable and within parenthesis. The output of the new code can be seen in the attached image below.

class LabProgram {

   public static int convert(double d){

   /* Type your code here */

      return (int) d;

}

public static void main(String[] args) {

System.out.println(convert(19.9));

System.out.println(convert(3.1));

}

}

You might be interested in
Jim wants to buy a car, but he’ll probably only need it for a couple of years. He has a short commute to work, so he won’t be pu
GalinKa [24]
A Motorcycle would be a good option or get a bike.
7 0
3 years ago
I am having trouble with this python question. I am in a beginner level class also so any solution that isn't too complex would
Delicious77 [7]

The code:

filename = input("> ")

with open(filename, "r") as file:

   items = file.read()

   items = items.split("\n")

   for index, item in enumerate(items):

       items[index] = item.split("\t")

   for item in items:

       if item[3] == "Available":

           print(f"{item[1]} ({item[0]}) -- {item[2]}")

Explenation:

1. We make the user enter the file's path, in our case "food.txt". This does only work if the .txt file is in the <u>same</u> directory as our code.

2. We get the content of our .txt file with the "open" function. If we use the "open" function inside of a "with" statement we don't have to deal with closing the file after we opened it. The file will close as soon as we exit the statement. The argument "r" indicates that we only want to read the file, not do anything else with it.

3. However the variable "file" doesn't contain the <u>contents</u> of "food.txt", only the class object of our file (if you try "print(file)" you'll only get nonsense). We can simply get the content of the file by calling ".read()" after.

4. We can separate this long str using the ".split()" function. The split function seperates a string by another sertain string (in our case "\n", since the different items are seperated by a newline). Now "items" is a list of strings.

5. Next we go through all items in "items" and separate them by "\t", again using the ".split()" function. Enumerate makes a list of indexes and values from another list (in our case, "items").

6. Now we have a list of lists of strings. The only thing left to do is go through every item and print it if the item's third item is equal to "Available" (notice that this is case-sensative). And print out the result in the desired format.

The code works for me, please ask me if there is anything you don't understand (or if the code is incorrect). Happy to help :D

5 0
2 years ago
window operating system popularly known as. 1) character user interface. 2) computer user interface. 3) graphic user interface.
fredd [130]

Answer:

The window operating system is popularly known as a graphical user interface(GUI)

Explanation:

older operating systems were command line based but window uses a gui

5 0
2 years ago
Write an if/else statement that compares the value of the variables soldYesterday and soldToday, and based upon that comparison
jenyasd209 [6]

Answer:

if(soldYesterday > soldToday){

salesTrend = -1;

} else if(soldToday > soldYesterday){

salesTrend = 1;

}

Explanation:

The if/else statement is more explicit. The first if condition check if soldYesterday is greater than soldToday, if true, then -1 is assigned to salesTrend.

Else if soldToday is greater than soldYesterday, if true, then 1 is assigned to salesTrend.

7 0
3 years ago
You work for the Contoso Corporation. You have a server that acts as a file server for clients. You must make sure that the serv
Anika [276]
Get a dedicated server with 6-10gb RAM, which might be able to run a lot, while staying up with no lag.
6 0
3 years ago
Other questions:
  • Which string method counts the number of characters in a string?
    5·1 answer
  • What is a block cipher algorithm that operates on 64-bit blocks and can have a key length from 32 to 448 bits?
    8·1 answer
  • A program called the ______ combines the object program with other programs in the library and is used in the program to create
    5·1 answer
  • )a___ is a complete binary tree such that each node in the tree contains a comparable object that us greater than or equal to th
    9·1 answer
  • If you implement a Wireless LAN (WLAN) to support connectivity for laptops in the Workstation Domain, which domain does WLAN fal
    5·1 answer
  • Which data type or collection of data types can SOQL statements populate or evaluate to?
    9·1 answer
  • Which of the following is true about radio waves? They have short wavelengths. They have high energies. They reveal hot gases. T
    10·2 answers
  • Drag each tile to the correct box.
    11·1 answer
  • What is the HCF of smallest prime number and the smallest composite number?​
    12·1 answer
  • 2ND LAST QUESTION
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!