hiya can anyone help me on this coding i need to creates this in netbeans: Write
ID: 3637833 • Letter: H
Question
hiya can anyone help me on this coding i need to creates this in netbeans:Write a method that calculates and stores the result of the following equations
Result1 = (Val1 x Val2) / Val3
Result2 = (Val1+Val2) – Val3
Write a separate method to print the result of the above calculation
Write a main app class to create an operator object set it up with some test values run the calculate method and final print the result
so far i have done this:
public class Logic1 {
int Val1;
int Val2;
int Val3;
int Result1;
int Result2;
// creating val 1,2,3 integers
Result1 = (Val1*Val2)/Val3;
public void setVal1(int newVal1Value)
{
Val1 = newVal1Value;
}
public int getVal1()
{
return Val1;
}
// Created get and set for val1
public void setVal2(int newVal2Value)
{
Val2 = newVal2Value;
}
public int getVal2()
{
return Val2;
}
// Created get and set for Val2
public void setVal3(int newVal3Value)
{
Val3 = newVal3Value;
}
public int getVal3()
{
return Val3;
}
// Created Get and Set for Val3
}
Explanation / Answer
class test { int Val1; int Val2; int Val3; int Result1; int Result2; // creating val 1,2,3 integers //Result1 = (Val1*Val2)/Val3; public void setVal1(int newVal1Value) { Val1 = newVal1Value; } public int getVal1() { return Val1; } // Created get and set for val1 public void setVal2(int newVal2Value) { Val2 = newVal2Value; } public int getVal2() { return Val2; } // Created get and set for Val2 public void setVal3(int newVal3Value) { Val3 = newVal3Value; } public int getVal3() { return Val3; } // Created Get and Set for Val3 public void result() { Result1= (Val1 * Val2) / Val3; Result2 = (Val1+Val2)- Val3; System.out.println("Result1 is:-"+Result1); System.out.println("Result2 is:-"+Result2); } } public class Logic1 { public static void main(String args[]) { test t = new test(); t.setVal1(2); t.setVal2(3); t.setVal3(3); t.result(); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.