anyone can help me..
i have a task to coplete
below is the question :

create class called Arithmetic for performing arithmetic process.
use two integer variables to represent the private data of the class. provide a constructor function that enables an object of this class to be initialized when it is declared. the constructor should contain default values in case no initializers are provided.

provide public member functions for each of the following :

a) accepting values for Arithmetic variables
b) menu for Arithmetic process option.
c) addition of two numbers. this function should return a value
d) substraction of two numbers. this function should return a value
e) multiplication of two numbers. this function should return a value
f) division of two numbers. this function should return a value
g) printing Arithmetic numbers. this function should return a value

anyone can help me..
i have a task to coplete
below is the question :

create class called Arithmetic for performing arithmetic process.
use two integer variables to represent the private data of the class. provide a constructor function that enables an object of this class to be initialized when it is declared. the constructor should contain default values in case no initializers are provided.

provide public member functions for each of the following :

a) accepting values for Arithmetic variables
b) menu for Arithmetic process option.
c) addition of two numbers. this function should return a value
d) substraction of two numbers. this function should return a value
e) multiplication of two numbers. this function should return a value
f) division of two numbers. this function should return a value
g) printing Arithmetic numbers. this function should return a value

And what part of this do you not understand, or are you having a specific problem with?

We are not just simply going to do your assignment for you.

public class arithmetic
{
private int x;
private int y;
public arithmetic(int i,int w) // default constructor
{
x = i;
y = w;
}
public int addition() // method
{
return x + y;
}
public int substraction() // method
{
return x - y;
}
public int multiplication() // method
{
return x * y;
}
public int division() // method
{
return x / y;
}
public static void main(String[] args)
{

System.out.println("Please choose ");
{
int arithmetic=4;
switch (arithmetic)
{
case 1: arithmetic add=new arithmetic(5,2);
System.out.println("Addition of two number is :"+add.addition());break;
case 2: arithmetic sub=new arithmetic(5,2);
System.out.println("Substraction of two number is:"+sub.substraction());
case 3:arithmetic multiply=new arithmetic(5,2);
System.out.println("Multiplication of two number is:"+multiply.multiplication());
case 4: arithmetic divide=new arithmetic(5,2);
System.out.println("Division of two number is:"+divide.division());
}
}
}
}

this is code that i write..but i don't know how to display a menu in question a.that'a all

public class arithmetic
{
    private int x;
    private int y;
    public arithmetic(int i,int w) // default constructor
    {
        x = i;
        y = w;
    }
    public int addition() // method
    {
        return x + y;
    }
    public int substraction() // method
    {
        return x - y;
    }
    public int multiplication() // method
    {
        return x * y;
    }
    public int division() // method
    {
        return x / y;
    }
    public static void main(String[] args)
    {

        System.out.println("Please choose ");
        {
            int arithmetic=4;
            switch (arithmetic)
            {
            case 1: arithmetic add=new arithmetic(5,2);
                System.out.println("Addition of two number is :"+add.addition());break;
            case 2: arithmetic sub=new arithmetic(5,2);
                System.out.println("Substraction of two number is:"+sub.substraction());
            case 3:arithmetic multiply=new arithmetic(5,2);
                System.out.println("Multiplication of two number is:"+multiply.multiplication());
            case 4: arithmetic divide=new arithmetic(5,2);
                System.out.println("Division of two number is:"+divide.division());
            }
        }
    }
}

Now we're talking. You can use code tags to make your code more readable in a post.
Although you've not tried to to solve the problem you're actually stuck at (getting the user input).
Simple answer would be STFW. Top 2 matches have code that you can copy.
Here is what I found

import java.io.*;  
public class ReadString {  
   public static void main (String[] args) {  
      //  prompt the user to enter their name 
      System.out.print("Enter your name: ");  
      //  open up standard input 
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  
      String userName = null;  
      //  read the username from the command-line; need to use try/catch with the 
      //  readLine() method 
      try { 
         userName = br.readLine(); 
      } catch (IOException ioe) { 
         System.out.println("IO error trying to read your name!"); 
         System.exit(1); 
      }  
      System.out.println("Thanks for the name, " + userName);  
   }  
}  // end of ReadString class

Just one addition, you want user to give you int and example is for String. So you need to convert String to int. For this you can use Integer.parseInt(String xxx) ;

thanks ..i will try to modify the coding ..to get my answer..

This article has been dead for over six months. Start a new discussion instead.