You will get email Reply within few hours

Wednesday, 24 April 2013

BIS346 WS1 Java Programming Guide

Q: State the order of evaluation of the operators in each of the following Java statements, and show the value of x after each statement is performed:

x = 7 + 3 * 6 / 2 - 1 ;

x = 2 % 2 +2 * 2 - 2 / 2 ;

x = ( 3 * 9 * ( 3 + ( 9 * 3 / ( 3 ) ) ) ) ;
BIS346 WS1 Java Programming Guide
Declaration:
  1. 1.     The logic in this document/example are pseudo code or partial Java source code and may be used for your reference only in order to help your development on your Java Programming Assignments.
  2. 2.     Because there may be multiple correct Java programming solutions for one programming assignment, it is very possible your own logic is correct and different from examples. Therefore, you are NOT required to 100% follow the logic below in this document if you believe that your solution is correct and better.
  3. 3.     Input and output screen shots are also your reference only. The main purpose of have them in this document is to show you what the inputs and outputs are.
Ex 2.15 (To calculate sub, difference, product, quotient (division) from two inputs(integers))
This is your first Java program in this class. You may copy an existing Java program example like Fig 2.7 below:

// Fig. 2.7: Addition.java
// Addition program that displays the sum of two numbers.
import java.util.Scanner; // program uses class Scanner

public class Addition
{
   // main method begins execution of Java application
   public static void main( String[] args )
   {
      // create a Scanner to obtain input from the command window
      Scanner input = new Scanner( System.in );

      int number1; // first number to add
      int number2; // second number to add
      int sum; // sum of number1 and number2

      System.out.print( "Enter first integer: " ); // prompt
      number1 = input.nextInt(); // read first number from user

      System.out.print( "Enter second integer: " ); // prompt
      number2 = input.nextInt(); // read second number from user

      sum = number1 + number2; // add numbers, then store total in sum
      //other calculations are sinmilar

      System.out.printf( "Sum is %d\n", sum ); // display sum
      //other printf’s are sinmilar

   } // end method main
} // end class Addition

This example is similar to the solution of your individual Ex 2.15, but is a little different. Here you must change it to not only calculate a sum of number1 and number2, but also their difference, product and quotient:

Difference = number1 - number2;
Product =  number1 * number2;
Quotient = number1 / number2;

Note:

  1. In this class my tip is only so called pseudo code. Sounds familiar?  You learned it in a previous class BIS220. So you need to convert it to a Java language. Your extra efforts are expected in order to make your program
a)             To pass compile
b)            To function as expected or required.
  1. You also need first rename your .java file by “Save As” a new meaningful file name. For example, this program may be called as “MathCalculations”. Do not forget to change the class name from “Addition” to MathCalculations”.
  2. Remember that in Java it is case sensitive. A class name “MathCalculations” is different from another class name “mathcalculations” or Mathcalculations” or mathCalculations”.
  3. Every Java program or .java file must has a method called “main”, not “Main” or “MAIN”. Again, Java is case sensitive.
  4. Make sure your program include a comment at the beginning of your Java code. This applies to all the individual and group programming assignments:
EMAIL ME For Solution:
topsolutions8@gmail.com