Question

In: Computer Science

in bluej java Writing Classes and Methods, Modulo operator, Integer Division, if-statements, Iteration

in bluej java Writing Classes and Methods, Modulo operator, Integer Division, if-statements, Iteration

Solutions

Expert Solution

I am assuming that you are asking of how to perform these actions in the BlueJ IDE.

  • Classes:

To create a class, click the New Class button and specify the class name which is on the project tool bar. The name has to be a valid java identifier as well. After creating the class, the type (interface, abstract, or applet) is indicated in the class icon.

  • Methods

Writing a method in blueJ is same as in other IDE's which you will be able to understand by the example below

public class Main {
    public static void foo() {
        // Do something here
    }
}
  • Modulo operator

Modulo operator does not differs from IDE to IDE it depends on the language so, it's the same as in other editors.

If you are having trouble understanding what it is then -

There's one important arithmetical operator you may not be familiar with, %, also known as the modulus or remainder operator. The % operator returns the remainder of two numbers. For instance 10 % 3 is 1 because 10 divided by 3 leaves a remainder of 1.

  • Integer Division

Dividing integer a by integer b you get how many times b fits into a. Also a % b will give you a remainder of a division. So (a / b ) * b + a % b = a.

Java does autoconvert types:

It autoconverts ints to doubles. It autoconverts shorts and bytes to ints even when no ints are involved, requiring constant annoying casts when you want to do short or byte arithmetic. It autoconverts primitives to wrappers and vice versa for boxing and autoboxing.

  • If statements

If statements are type of conditional statements used for running some part of code when the condition written in "if" return True. If it's False then the 'if' block won't run and the compiler would skip ahead.

  • Iterations

Iterations means the repetition of a function, method or a process in a computer program which is same for most of the programming languages and it doesn't depends on the IDE as well.

Iterations in Java are performed by

  1. While loop
  2. For loop
  3. Do while loop
  4. For-Each Loop (this one is also recognised as a type of for loop as the only difference is that this one is specially for arrays )

Related Solutions

Explain the difference between the modulo operator and the division operator for C#
Explain the difference between the modulo operator and the division operator for C#
in bluej java Write an application with two classes. Class NumberUtility has one instance variable n...
in bluej java Write an application with two classes. Class NumberUtility has one instance variable n of type int. Constructor initializes instance variable n by using input parameter n. public NumberUtility(int n) Class also has the following methods:   public int getN()                              // Returns instance variable n public boolean isOdd()                  // Returns true if number n is odd and returns false otherwise. public boolean isEven()               // Returns true if number n is even and returns false if it is odd.      // Implement method by...
Writing Classes I Write a Java program containing two classes: Dog and a driver class Kennel....
Writing Classes I Write a Java program containing two classes: Dog and a driver class Kennel. A dog consists of the following information: • An integer age. • A string name. If the given name contains non-alphabetic characters, initialize to Wolfy. • A string bark representing the vocalization the dog makes when they ‘speak’. • A boolean representing hair length; true indicates short hair. • A float weight representing the dog’s weight (in pounds). • An enumeration representing the type...
Write a program in java which is in main and uses no classes, methods, loops or...
Write a program in java which is in main and uses no classes, methods, loops or if statements Ask the user to enter their first name Ask the user to enter their last name Print their initials followed by periods (ie. Clark Kent = C. K.) Print the number of letters in their last name
How do objects enhance Java? How do objects relate to classes and methods?
How do objects enhance Java? How do objects relate to classes and methods?
Writing a Modular Program in Java In this lab, you add the input and output statements...
Writing a Modular Program in Java In this lab, you add the input and output statements to a partially completed Java program. When completed, the user should be able to enter a year, a month, and a day to determine if the date is valid. Valid years are those that are greater than 0, valid months include the values 1 through 12, and valid days include the values 1 through 31. Instructions Notice that variables have been declared for you....
**** All these methods should be implemented using RECURSIVE solutions (no looping statements) // Java //...
**** All these methods should be implemented using RECURSIVE solutions (no looping statements) // Java // This method takes an integer array as well as an integer (the starting // index) and returns the sum of the squares of the elements in the array. // This method uses recursion. public int sumSquaresRec(int[] A, int pos) { // TODO: implement this method        return -1; // replace this statement with your own return }    // This method takes a...
Java GPA calculator. Apply GUI, methods, exception handling, classes, objects, inheritance etc. The program should prompt...
Java GPA calculator. Apply GUI, methods, exception handling, classes, objects, inheritance etc. The program should prompt user for input. When done it should give an option to compute another GPA or exit.
1.What standard methods can you use when handling file-reading and file-writing operations? a. Java b. Fragment-based...
1.What standard methods can you use when handling file-reading and file-writing operations? a. Java b. Fragment-based methods c. onClick d. DDMS 2. What would this query return? SELECT * FROM Items WHERE OrderDate >= Date('Now') a. All items in the database. b. Nothing c. Items that were ordered yesterday d. Items that were ordered today. 3. What can you use to manage files within a desired directory and create subdirectories? a. Subdirectory objects b. Directory class c. File objects d....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT