Can you guys help me fix my assignment
this is the program that i need to do
You are required to write a command line program in Java that declares three numbers.
Write a method called calc() that takes in the three numbers as parameters. Inside this
method, you must add the first two numbers together and divide the answer by the
third. The value of the sum must be returned. Write another method called display()
that prints the following to the screen:
******************************************
* *
* This is a simple program *
* that performs a mathematical *
* calculation. The answer is: *
* [answer] *
******************************************
so far i made this.
import java.util.Scanner;
public class assignmentB
{
public int calc(){
int number1;
int number2;
int number3;
int sum;
Scanner scan=new Scanner(System.in);
System.out.println("Please enter 1st number: ");
number1 = scan.nextInt();
System.out.println("Please enter 2nd number: ");
number2 = scan.nextInt();
System.out.println("Divide the sum of the two numbers by: ");
number3 = scan.nextInt();
sum = (number1 + number2)/ number3;
return sum;
}
public String display(){
System.out.println("****************************** ***");
System.out.println("* *");
System.out.println("* This is a simple program *");
System.out.println("* that performs a mathematical *");
System.out.println("* calculation. The answer is: *");
System.out.println("* "+ sum +" *");
System.out.println("* *");
System.out.println("****************************** ***");
}
}
can anyone fix this for me? so it will work as state above.
Re: Can you guys help me fix my assignment
Can you explain what the code does now, post its output and add comments showing what is wrong with the output and show what you want the output to look like?
Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting
Re: Can you guys help me fix my assignment
Code java:
import java.util.Scanner;
public class assignmentB
{
public int calc(){
int number1;
int number2;
int number3;
int sum;
Scanner scan=new Scanner(System.in);
System.out.println("Please enter 1st number: ");
number1 = scan.nextInt();
System.out.println("Please enter 2nd number: ");
number2 = scan.nextInt();
System.out.println("Divide the sum of the two numbers by: ");
number3 = scan.nextInt();
sum = (number1 + number2)/ number3;
return sum;
}
public String display(){
System.out.println("****************************** ***");
System.out.println("* *");
System.out.println("* This is a simple program *");
System.out.println("* that performs a mathematical *");
System.out.println("* calculation. The answer is: *");
System.out.println("* "+ sum +" *");
System.out.println("* *");
System.out.println("****************************** ***");
}
}
basically my instructor wants me to make a program. his guidelines is this.
Quote:
You are required to write a command line program in Java that declares three numbers.
Write a method called calc() that takes in the three numbers as parameters. Inside this
method, you must add the first two numbers together and divide the answer by the
third. The value of the sum must be returned. Write another method called display()
that prints the following to the screen:
******************************************
* *
* This is a simple program *
* that performs a mathematical *
* calculation. The answer is: *
* [answer] *
******************************************
Re: Can you guys help me fix my assignment
You missed responding to this:
Can you explain what the code does now, post its output and add comments showing what is wrong with the output and show what you want the output to look like?
If you are getting errors, copy and paste them here.
Your code is not properly formatted making it hard to read and understand. The statements should not all start in the first column.
They should be indented to show the nesting logic.
Re: Can you guys help me fix my assignment
For starters, your calc method is supposed to allow three parameters into it, which it doesn't how it is written. Your instructor wants you to pass the three numbers into your calc method, not have your calc method do everything. It should look something like this.
Code java:
public int calc(int num1, int num2, int num3) {
//Do your calculations and return the result
}
You will also have to provide a main method to actually be able to call these methods and have it run in the console. Hope this helps.