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
Juli2301 [7.4K]
3 years ago
10

(Language is in Java)

Computers and Technology
1 answer:
Gre4nikov [31]3 years ago
7 0

import java.util.Scanner;

public class InchesToFeetInteractive

{

public static void main(String[] args) {

   Scanner scan = new Scanner(System.in);

   final int INCHES_IN_FOOT = 12;

   int inches = scan.nextInt();

   int feet;

   int inchesLeft;

   feet = inches / INCHES_IN_FOOT;

   inchesLeft = inches % INCHES_IN_FOOT;

   System.out.println(inches + " inches is " +

   feet + " feet and " + inchesLeft + " inches");

   }

}

We import the Scanner class and then initialize a new Scanner named scan. We then get an integer representation of inches from the user and calculate the feet and inches from the value entered by the user.

You might be interested in
Type (dog, cat, budgie, lizard, horse, etc.) Create a class that keeps track of the attributes above for pet records at the anim
Alenkinab [10]

Answer:

If you did the exercise with two Dog objects, it was a bit boring, right? After all, we have nothing to separate the dogs from each other and no way of knowing, without looking at the source code, which dog produced which bark.

In the previous article, I mentioned that when you create objects, you call a special method called a constructor. The constructor looks like the class name written as a method. For example, for a Dog class, the constructor would be called Dog().

The special thing about constructors is that they are the path to any new object, so they are a great place to call code that initializes an object with default values. Further, the return value from a constructor method is always an object of the class itself, which is why we can assign the return value of the constructor to a variable of the type of class we create.

However, so far, we have not actually created a constructor at all, so how come we can still call that method?

In many languages, C# included, the language gives you a free and empty constructor without you having to do anything. It is implied that you want a constructor; otherwise there would be no way of using the class for anything, so the languages just assume that you have written one.

This invisible and free constructor is called the default constructor, and, in our example, it will look like this:

public Dog(){ }

Notice that this syntax is very similar to the Speak() method we created earlier, except that we do not explicitly return a value nor do we even declare the return type of the method. As I mentioned earlier, a constructor always returns an instance of the class to which it belongs.

In this case, that is the class Dog, and that is why when we write Dog myDog = new Dog(), we can assign the new object to a variable named myDog which is of type Dog.

So let’s add the default constructor to our Dog class. You can either copy the line above or, in Visual Studio, you can use a shortcut: type ctor and hit Tab twice. It should generate the default constructor for you.

The default constructor doesn’t actually give us anything new because it is now explicitly doing what was done implicitly before. However, it is a method, so we can now add content inside the brackets that will execute whenever we call this constructor. And because the constructor runs as the very first thing in an object’s construction, it is a perfect place to add initialization code.

For example, we could set the Name property of our objects to something by adding code such as this:

public Dog()

{

   this.Name = "Snoopy";

}

This example will set the Name property of any new objects to “Snoopy”.

Of course, that’s not very useful because not all dogs are called “Snoopy”, so instead, let us change the method signature of the constructor so that it accepts a parameter.

The parentheses of methods aren’t just there to look pretty; they serve to contain parameters that we can use to pass values to a method. This function applies to all methods, not just constructors, but let’s do it for a constructor first.

Change the default constructor signature to this:

public Dog(string dogName)

This addition allows us to send a string parameter into the constructor, and that when we do, we can refer to that parameter by the name dogName.

Then, add the following line to the method block:

this.Name = dogName;

This line sets this object’s property Name to the parameter we sent into the constructor.

Note that when you change the constructor’s signature, you get a case of the red squigglies in your Program.cs file.When we add our own explicit constructors, C# and .NET will not implicitly create a default constructor for us. In our Program.cs file, we are still creating the Dog objects using the default parameter-less constructor, which now no longer exists.

To fix this problem, we need to add a parameter to our constructor call in Program.cs. We can, for example, update our object construction line as such:

Dog myDog = new Dog(“Snoopy”);

Doing so will remove the red squigglies and allow you to run the code again. If you leave or set your breakpoint after the last code line, you can look at the Locals panel and verify that your object’s Name property has indeed been? Got it?

5 0
3 years ago
What is the first step you should take when you want to open a savings account?
pav-90 [236]
 First Go to the bank
Second Present Photo ID
 third Fill out application

I would think review the different savings account options that your bank offers...

Last Make initial deposit.



Hope that helps!!!

.
5 0
3 years ago
Describe, with examples, the way in which a defect in software can cause harm to a person, to the environment, or to a company
Arisa [49]

Answer:

Losing jobs. Fire. Destruction of property.

Explanation:

Having a company shut down due to lack of protection and having people testify products unsafe. If software blows up it could cause desturction of property therefore causing the effect of many people losing their jobs.

4 0
3 years ago
Pls help! 7th grade pythin fyi
larisa [96]

Answer:

There should be a colon at the end of the if statement, ie:

<h2>if x > 100:</h2><h2>  print("...")</h2>

8 0
3 years ago
Write a program to move the Turtle based on the user’s request. Display a menu with options for the user to choose. Use the foll
Strike441 [17]

Answer:

#import turtle

import turtle

 

# set screen

Screen = turtle.Turtle()

 

# decide colors

cir= ['red','green','blue','yellow','purple']

 

# decide pensize

turtle.pensize(4)

 

# Draw star pattern

turtle.penup()

turtle.setpos(-90,30)

turtle.pendown()

for i in range(5):

   turtle.pencolor(cir[i])

   turtle.forward(200)

   turtle.right(144)

 

turtle.penup()

turtle.setpos(80,-140)

turtle.pendown()

 

# choose pen color

turtle.pencolor("Black")

# importing turtle module

import turtle

 

# number of sides

n = 10

 

# creating instance of turtle

pen = turtle.Turtle()

 

# loop to draw a side

for i in range(n):

   # drawing side of  

   # length i*10

   pen.forward(i * 10)

 

   # changing direction of pen  

   # by 144 degree in clockwise

   pen.right(144)

 

# closing the instance

turtle.done()

turtle.done()

Explanation:

7 0
2 years ago
Other questions:
  • You receive an offer for a credit card that can be use to accrue points that
    11·1 answer
  • python (Financial application: compute the future investment value) Write a function that computes a future investment value at
    5·1 answer
  • The picture that graphically represents the items you use in Windows is called a/an
    5·1 answer
  • Amelia has selected the chart in her PowerPoint and needs to change the chart type. Which one of the Chart Tools tabs would she
    15·1 answer
  • _____ is a computing model in which an organization outsources the equipment used to support its business operations, including
    15·1 answer
  • What are the biggest problems facing the criminal justice system in the area of computer crime
    10·2 answers
  • Which of the following players is on offence
    9·1 answer
  • O O O O O O O
    9·1 answer
  • Suppose that we want to enhance the processor used for Web serving. The new processor is 10 times faster on computation in the W
    6·1 answer
  • Python 3.12 LAB: Input and formatted output: Right-facing arrow Given input characters for an arrowhead and arrow body, print a
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!