so I'm learning JAVA by myself and I have only the basic knowledge about programming languages in general. I wrote this simple calculator program to try and apply what I've been learning this far, but the problem is that it doesn't print the age, instead it prints a 0 and I don't know why:
this is the class
public class userinput {
private String name;
private int age;
public tuna (String name, int age){
name = "dina";
age = 3;
}
public void simpleMessage2(){
System.out.println("hello " + name + " ready to use our calculator?");
}
public void setName(String Uname){
name = Uname;
}
public void setAge(int uage){
uage = age;
}
public String getName(){
return name;
}
public int getAge(){
return age;
}
public void printname(){
System.out.printf("your name is %s", getName());
System.out.println();
}
public void printage(){
System.out.println("your age is");
System.out.println(getAge());
System.out.println();
}}
and this is the main class:
import java.util.Scanner;
class calc {
public static void main (String args[]) {
String name1;
int age1;
Scanner bucky = new Scanner(System.in);
int choice, num1, num2, sum;
System.out.println("Hey, enter your name");
name1 = bucky.nextLine();
System.out.println("Hey, enter your age");
age1 = bucky.nextInt();
tuna objc1 = new userinput(name1, age1);
objc1.setName(name1);
objc1.printname();
System.out.println();
objc1.setAge(age1);
objc1.printage();
System.out.println();
System.out.println("this is a basic calculator, select from the menu:");
System.out.println("Enter 1 for summation");
System.out.println("Enter 2 for subtraction");
System.out.println("Enter 3 for multiplication");
System.out.println("Enter 4 for division");
System.out.println("Enter 5 for module");
System.out.println("Enter 0 to exit");
choice = bucky.nextInt();
while (choice != 0) {
switch(choice){
case 1:
System.out.println("enter the 1st num");
num1 = bucky.nextInt();
System.out.println("enter the 2nd num");
num2 = bucky.nextInt();
System.out.println("the sum is equal to: ");
sum = num1 + num2;
System.out.print(sum);
System.out.println("Select another operation from the menu or enter 0 to exit");
choice = bucky.nextInt();
break;
case 2:
System.out.println("enter the 1st num");
num1 = bucky.nextInt();
System.out.println("enter the 2nd num");
num2 = bucky.nextInt();
System.out.println("the sub is equal to: ");
sum = num1 - num2;
System.out.print(sum);
System.out.println("Select another operation from the menu or enter 0 to exit");
choice = bucky.nextInt();
break;
case 3:
System.out.println("enter the 1st num");
num1 = bucky.nextInt();
System.out.println("enter the 2nd num");
num2 = bucky.nextInt();
System.out.println("the mul is equal to: ");
sum = num1 * num2;
System.out.print(sum);
System.out.println("Select another operation from the menu or enter 0 to exit");
choice = bucky.nextInt();
break;
case 4:
System.out.println("enter the 1st num");
num1 = bucky.nextInt();
System.out.println("enter the 2nd num");
num2 = bucky.nextInt();
System.out.println("the div is equal to: ");
sum = num1 / num2;
System.out.print(sum);
System.out.println("Select another operation from the menu or enter 0 to exit");
choice = bucky.nextInt();
break;
case 5:
System.out.println("enter the 1st num");
num1 = bucky.nextInt();
System.out.println("enter the 2nd num");
num2 = bucky.nextInt();
System.out.println("the mod is equal to: ");
sum = num1 % num2;
System.out.print(sum);
System.out.println("Select another operation from the menu or enter 0 to exit");
choice = bucky.nextInt();
break;
default:
System.out.println("Invalid entry, please try again");
choice = bucky.nextInt();
break;
}
System.out.println("Bye!");
}
}
}
Where is the tuna class?
tuna objc1 = new userinput(name1, age1);
the userinput's Constructor:
public userinput(String n, int a){
name = n;
age = a;
}
I was just learning
the first error you don't have tuna class change the error to
tuna objc1 = new userinput(name1,age1);
to
userinput objc1 = new userinput();
then i change your code like that the method you use it in first class
and the second class to make operation
the first class
import java.util.Scanner;
public class userinput {
private String name;
private int age;
public void simpleMessage2(){
System.out.println("hello " + name + " ready to use our calculator?");
}
public void setName(String Uname){
name = Uname;
}
public void setAge(int uage){
age= uage; }
public void printname(){
System.out.printf("your name is %s", getName());
System.out.println();
}
public void printage(){
System.out.printf("your age is %s", getAge());
System.out.println();}
public int getAge(){
return age;
}
public String getName(){
return name;
}
}
the second class
class calc {
public static void main (String args[]) {
String name1;
int age1;
Scanner bucky = new Scanner(System.in);
int choice, num1, num2, sum;
System.out.println("Hey, enter your name");
name1 = bucky.nextLine();
System.out.println("Hey, enter your age");
age1 = bucky.nextInt();
userinput objc1 = new userinput();
objc1.setName(name1);
objc1.printname();
System.out.println();
objc1.setAge(age1);
objc1.printage();
System.out.println();
objc1.simpleMessage2();
System.out.println();
System.out.println("this is a basic calculator, select from the menu:");
System.out.println("Enter 1 for summation");
System.out.println("Enter 2 for subtraction");
System.out.println("Enter 3 for multiplication");
System.out.println("Enter 4 for division");
System.out.println("Enter 5 for module");
System.out.println("Enter 0 to exit");
choice = bucky.nextInt();
while (choice != 0) {
switch(choice){
case 1:
System.out.println("enter the 1st num");
num1 = bucky.nextInt();
System.out.println("enter the 2nd num");
num2 = bucky.nextInt();
System.out.println("the sum is equal to: ");
sum = num1 + num2;
System.out.println(sum);
System.out.println("Select another operation from the menu or enter 0 to exit");
choice = bucky.nextInt();
break;
case 2:
System.out.println("enter the 1st num");
num1 = bucky.nextInt();
System.out.println("enter the 2nd num");
num2 = bucky.nextInt();
System.out.println("the sub is equal to: ");
sum = num1 - num2;
System.out.println(sum);
System.out.println("Select another operation from the menu or enter 0 to exit");
choice = bucky.nextInt();
break;
case 3:
System.out.println("enter the 1st num");
num1 = bucky.nextInt();
System.out.println("enter the 2nd num");
num2 = bucky.nextInt();
System.out.println("the mul is equal to: ");
sum = num1 * num2;
System.out.println(sum);
System.out.println("Select another operation from the menu or enter 0 to exit");
choice = bucky.nextInt();
break;
case 4:
System.out.println("enter the 1st num");
num1 = bucky.nextInt();
System.out.println("enter the 2nd num");
num2 = bucky.nextInt();
System.out.println("the div is equal to: ");
sum = num1 / num2;
System.out.println(sum);
System.out.println("Select another operation from the menu or enter 0 to exit");
choice = bucky.nextInt();
break;
case 5:
System.out.println("enter the 1st num");
num1 = bucky.nextInt();
System.out.println("enter the 2nd num");
num2 = bucky.nextInt();
System.out.println("the mod is equal to: ");
sum = num1 % num2;
System.out.println(sum);
System.out.println("Select another operation from the menu or enter 0 to exit");
choice = bucky.nextInt();
break;
default:
System.out.println("Invalid entry, please try again");
choice = bucky.nextInt();
break;
}
}
System.out.println("Bye!");}
}
I hope i help you
Related
I'm programming a very basic menu calculator that
displays a menu
gets the users choice and performs an action based on that choice
display the results
loop back to the menu until the user enters 10 to exit the loop
What has confused me is using a switch statement in a while loop. Entering 10 is supposed to exit the program and it does, but only at first. The second time it shows the menu and asks for input, 10 does not exit the program.
any other advice is also very welcomed
public class MenuCalculator
{
public static void main(String[] args)
{
showMenu();
}
public static void showMenu()
{
Scanner input = new Scanner(System.in);
//menu display
System.out.println("Calculator Menu");
System.out.println("---------------");
System.out.println("1. Add two integers. ");
System.out.println("2. Add two doubles. ");
System.out.println("3. Subtract two integers. ");
System.out.println("4. Subtract two doubles. ");
System.out.println("5. Multiply two integers. ");
System.out.println("6. Multiply two doubles. ");
System.out.println("7. Divide two integers. ");
System.out.println("8. Divide two douvles. ");
System.out.println("9. Compute a factorial product of a number (n!) ");
System.out.println("10. Exit. ");
System.out.println(" ");
System.out.println("Your choice?");
int userChoice = input.nextInt();
while (userChoice < 10)
{
switch (userChoice)
{
case 1:
System.out.println("Enter the first number * : ");
int addInt1 = input.nextInt();
System.out.println("Enter the 2nd number: ");
int addInt2 = input.nextInt();
System.out.println(add(addInt1, addInt2));
break;
case 2:
System.out.println("Enter the first number !: ");
double plusDub1 = input.nextDouble();
System.out.println("Enter the 2nd number: #");
double plusDub2 = input.nextDouble();
System.out.println(addDbl(plusDub1, plusDub2));
break;
case 3:
System.out.println("Enter the first number: #");
int subInt1 = input.nextInt();
System.out.println("Enter the 2nd number: ");
int subInt2 = input.nextInt();
System.out.println(subtract(subInt1, subInt2));
break;
case 4:
System.out.println("Enter the first number: $");
double subDub1 = input.nextDouble();
System.out.println("Enter the 2nd number: ");
double subDub2 = input.nextDouble();
System.out.println(subtractDbl(subDub1, subDub2));
break;
case 5:
System.out.println("Enter the first number: %");
int multInt1 = input.nextInt();
System.out.println("Enter the 2nd number: ");
int multInt2 = input.nextInt();
System.out.println(multiply(multInt1, multInt2));
break;
case 6:
System.out.println("Enter the first number: ^");
double multDub1 = input.nextDouble();
System.out.println("Enter the 2nd number: ");
double multDub2 = input.nextDouble();
System.out.println(multiplyDbl(multDub1, multDub2));
break;
case 7:
System.out.println("Enter the first number: &");
int divInt1= input.nextInt();
System.out.println("Enter the 2nd number: ");
int divInt2= input.nextInt();
System.out.println(divide(divInt1, divInt2));
break;
case 8:
System.out.println("Enter the first number: -");
double divDub1= input.nextDouble();
System.out.println("Enter the 2nd number: ");
double divDub2= input.nextDouble();
System.out.println(divideDbl(divDub1, divDub2));
break;
case 9:
System.out.println("Enter a number: ");
int factoNum= input.nextInt();
System.out.println(factorialProduct(factoNum));
break;
default:
}//end switch
showMenu();
}//end while
}
public static int add(int n1, int n2)
{
//declare variables
int sum;
// sum and return
sum = n1 + n2;
return sum;
}
public static double addDbl(double n1, double n2)
{
//declaration
double sum;
// sum and return
sum = n1 + n2;
return sum;
}
public static int subtract(int n1, int n2)
{
int total;
total = n1 - n2;
return total;
}
public static double subtractDbl(double n1, double n2)
{
double total;
total = n1 - n2;
return total;
}
public static int multiply(int n1, int n2)
{
int total;
total = n1 * n2;
return total;
}
public static double multiplyDbl(double n1, double n2)
{
double total;
total = n1 * n2;
return total;
}
public static int divide(int n1, int n2)
{
int total;
total = n1 / n2;
return total;
}
public static double divideDbl(double n1, double n2)
{
double total;
total = n1 / n2;
return total;
}
public static int factorialProduct(int n)
{
if (n == 0)
{
return 1;
}
else
{
return n * factorialProduct(n - 1);
}
}
}
You call showMenu from showMenu, which is recursion, and you definitely don't need this here. What you need instead is a while loop around getting the mode and executing the operation. I would shape the code like this (warning - pseudocode):
public static void main() {
while (true) {
// display your menu
userChoice = nextInt()
switch (userChoice) {
case 1:
...
case 2:
...
...
case 10:
return; // exits from main
}
}
}
i have a calculator class and i want the operation input to be specific to these strings "+, -, /, *" if its not, i want to print a message to enter the operator again.
and please if someone would lessen my code please do it. thanks
here is my code
import java.util.Scanner;
public class Calculator1 {
public static void main(String[] args) {
Scanner num = new Scanner(System.in);
String operation;
Double fnum, lnum, answer;
System.out.println("Enter first Number: ");
while (!num.hasNextDouble())
{
num.next();
System.out.print("Enter first Number: ");
}
fnum = num.nextDouble();
System.out.println("Enter Operation: ");
//HERE IM BEING CONFUSED
while (!num.equals("+, -, /, *"))
{
num.next();
System.out.print("Enter Operator: ");
}
operation = num.next();
//End
System.out.println("Enter Second Number: ");
while (!num.hasNextDouble())
{
num.next();
System.out.print("Enter Second Number: ");
}
lnum = num.nextDouble();
switch (operation) {
case "+":
answer = fnum + lnum;
System.out.print("Equals= " + answer);
break;
case "-":
answer = fnum - lnum;
System.out.print("Equals= " + answer);
break;
case "*":
answer = fnum * lnum;
System.out.println("Equals= " + answer);
break;
case "/":
answer = fnum / lnum;
System.out.println("Equals= " + answer);
break;
default:
System.out.println("wrong operator");
break;
}
}
}
This is a way to use operators with SWITCH sentence.
public static void main(String[] args) {
Scanner num = new Scanner(System.in);
double v1,v2;
String v3;
System.out.print("Enter first number: ");
v1 = num.nextDouble();
System.out.print("Enter second number: ");
v2 = num.nextDouble();
System.out.print("Enter operation [+] [-] [*] [/]: ");
v3 = num.next();
System.out.println( ("+".equals(v3) ) ? Operators.ADD.calculate(v1, v2) : "....");
}
public enum Operators {
ADD;
double calculate(double x, double y) {
switch (this) {
case ADD:
return x + y;
default:
throw new AssertionError("Unknown operations " + this);
}
}
}
Can you find the source of error in this?
package calc;
import java.util.Scanner;
public class Calc {
Scanner scan = new Scanner(System.in);
public void add() {
System.out.println("Enter 1st number");
int s1 = scan.nextInt();
scan.nextLine();
System.out.println("Enter 2nd number");
int s2 = scan.nextInt();
scan.nextLine();
int sum = s1 + s2;
System.out.println("The sum is: " + sum);
}
public void diff() {
System.out.println("Enter 1st number");
int d1 = scan.nextInt();
scan.nextLine();
System.out.println("Enter 2nd number");
int d2 = scan.nextInt();
scan.nextLine();
int diff = d1 - d2;
System.out.println("The difference is: " + diff);
}
public void prod() {
System.out.println("Enter 1st number");
int p1 = scan.nextInt();
scan.nextLine();
System.out.println("Enter 2nd number");
int p2 = scan.nextInt();
scan.nextLine();
int prod = p1 + p2;
System.out.println("The product is: " + prod);
}
public void quo() {
System.out.println("Enter 1st number");
int q1 = scan.nextInt();
scan.nextLine();
System.out.println("Enter 2nd number");
int q2 = scan.nextInt();
scan.nextLine();
int quo = q1 + q2;
System.out.println("The quotient is: " + quo);
}
public static void main(String[] args) {
do {
Calc op = new Calc();
Scanner scan = new Scanner(System.in);
char ans = 0;
System.out.println("Calculator");
System.out.println("1.Addition\n" + "2.Subtraction\n" + "3.Multiplication\n" + "4.Division\n" + "Enter operation number:");
int n1 = scan.nextInt();
scan.nextLine();
switch (n1) {
case 1:
op.add();
break;
case 2:
op.diff();
break;
case 3:
op.prod();
break;
case 4:
op.quo();
break;
default:
System.out.println("Invalid input");
break;
}
System.out.println("Try again? [Y/N]");
ans = scan.nextLine().charAt(0);
} while (ans == 'Y' || ans == 'y');
}
}
and then netbeans has this auto correct that resulted into this:
package calc;
import java.util.Scanner;
public class Calc {
private static char ans;
it added a "private static char ans;" and I would like to understand more how did that fix my code. Thanks
ans is defined within the do{ ... } while() loop but it must be defined outside, to make it available for condition in the while.
So do:
char ans = 0;
do {
Calc op = new Calc();
Scanner scan = new Scanner(System.in);
ans = 0;
I'm trying to make a calculator where the person can continue to put in numbers like "2+4*7-1" until they press = and then they will get the answer, and I have no idea how to even start. I know how to make a calculator with just 2 numbers but not how to have the user giving new numbers all the time. If anyone have any tips/code I could look at that would help a lot.
Check this Creating a Calculator using JFrame , and this is a step to step tutorial
yes yes i know that i am replying after 2 years but still maybe it will come in handy to other ppl in the future.
its a simple console code no gui.
So here's how i did it on eclipse
import java.util.Scanner;
public class Adv_calc {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int option;
double num1, num2, result;
result = 0;
do {
System.out.println("Welcome to The Calculator app");
System.out.println("Please Choose an option");
System.out.println("1) Add");
System.out.println("2) Subtract");
System.out.println("3) Multiply");
System.out.println("4) Continue");
System.out.println("5) Exit");
System.out.print("Option :: ");
option = sc.nextInt();
switch (option) {
case 1: {
System.out.println("Addition Calculator");
System.out.print("Kindly Enter the FIRST Number :: ");
num1 = sc.nextDouble();
System.out.print("Kindly Enter the SECOND Number :: ");
num2 = sc.nextDouble();
result = num1 + num2;
System.out.print("The Result is :: ");
System.out.println(result);
break;
}
case 2: {
System.out.println("Subtraction Calculator");
System.out.print("Kindly Enter the FIRST Number :: ");
num1 = sc.nextDouble();
System.out.print("Kindly Enter the SECOND Number :: ");
num2 = sc.nextDouble();
result = num1 - num2;
System.out.print("The Result is :: ");
System.out.println(result);
break;
}
case 3: {
System.out.println("Multiplication Calculator");
System.out.print("Kindly Enter the FIRST Number :: ");
num1 = sc.nextDouble();
System.out.print("Kindly Enter the SECOND Number :: ");
num2 = sc.nextDouble();
result = num1 * num2;
System.out.print("The Result is :: ");
System.out.println(result);
break;
}
case 4: {
System.out.println("Please Choose an option");
System.out.println("1) Add");
System.out.println("2) Subtract");
System.out.println("3) Multiply");
System.out.print("Option :: ");
option = sc.nextInt();
switch (option) {
case 1: {
System.out.println("Addition Calculator");
System.out.print("Kindly Enter the SECOND Number :: ");
num2 = sc.nextDouble();
result = result + num2;
System.out.print("The Result is :: ");
System.out.println(result);
break;
}
case 2: {
System.out.println("Subtraction Calculator");
System.out.print("Kindly Enter the SECOND Number :: ");
num2 = sc.nextDouble();
result = result - num2;
System.out.print("The Result is :: ");
System.out.println(result);
break;
}
case 3: {
System.out.println("Multiplication Calculator");
System.out.print("Kindly Enter the SECOND Number :: ");
num2 = sc.nextDouble();
result = result * num2;
System.out.print("The Result is :: ");
System.out.println(result);
break;
}
}
break;
}
case 5: {
System.out.println("Thank you for using my program :: ");
System.out.println("Program will now exit ");
System.exit(0);
}
}
} while (option != 5);
}
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I know these must be basic errors, but I'm not sure how to fix them.
I changed my class name to Interface & now Java has a problem with it.
Also, in my switch statement, I've tried to call the enterData method, but I'm getting an error on this line as well as on this line... "private static void enterData()" <-- it says a "token" is missing on this line?
I'm trying to call a method from case 0, but it isn't working.
import java.util.Scanner;
public class Interface {
private void run()
{
Scanner console = new Scanner(System.in);
Store store1 = new Store(); // MUST DO THIS
int demandRate, option, end;
double setupCost, unitCost, inventoryCost;
double sellingPrice, optimalOrder;
String name;
do {
System.out.println("Enter product data (0), Show product data (1), Show product strategy (2), Exit program (9).");
option = console.nextInt();
switch(option)
{
case 0: enterData();
break;
case 1:
break;
case 2:
break;
case 9: System.out.println("You chose to exit the program.");
break;
default: System.out.println("Please choose a valid option.");
}
} while (option != 9);
private static void enterData()
{
System.out.println("Product name between 3 & 10 characters long: ");
name = console.nextLine();
while ((name.length() < 3) || (name.length() > 10)) {
System.out.println("Please put in a name between 3 & 10 characters long.");
name = console.nextLine();
}
name = name.toLowerCase();
System.out.println("Demand rate: ");
demandRate = console.nextInt();
while (demandRate <= 0) {
System.out.println("Please put in a positive integer.");
demandRate = console.nextInt();
}
System.out.println("Setup cost: ");
setupCost = console.nextDouble();
while (setupCost <= 0) {
System.out.println("Please put in a positive number.");
setupCost = console.nextInt();
}
System.out.println("Unit cost: ");
unitCost = console.nextDouble();
while (unitCost <= 0) {
System.out.println("Please put in a positive number.");
unitCost = console.nextInt();
}
System.out.println("Inventory cost: ");
inventoryCost = console.nextDouble();
while (inventoryCost <= 0) {
System.out.println("Please put in a positive number.");
inventoryCost = console.nextInt();
}
System.out.println("Selling price: ");
sellingPrice = console.nextDouble();
while (sellingPrice <= 0) {
System.out.println("Please put in a positive integer.");
sellingPrice = console.nextInt();
}
}
}
public static void main(String[] args) {
Interface intFace = new Interface();
intFace.run();
}
}
You can't define method in another method.
Change your code to this:
public class Interface {
private void run()
{
Scanner console = new Scanner(System.in);
Store store1 = new Store(); // MUST DO THIS
int demandRate, option, end;
double setupCost, unitCost, inventoryCost;
double sellingPrice, optimalOrder;
String name;
do {
System.out.println("Enter product data (0), Show product data (1), Show product strategy (2), Exit program (9).");
option = console.nextInt();
switch(option)
{
case 0: enterData();
break;
case 1:
break;
case 2:
break;
case 9: System.out.println("You chose to exit the program.");
break;
default: System.out.println("Please choose a valid option.");
}
} while (option != 9);
}
private static void enterData()
{
int demandRate, option, end;
double setupCost, unitCost, inventoryCost;
double sellingPrice, optimalOrder;
Scanner console = new Scanner(System.in);
System.out.println("Product name between 3 & 10 characters long: ");
String name = console.nextLine();
while ((name.length() < 3) || (name.length() > 10)) {
System.out.println("Please put in a name between 3 & 10 characters long.");
name = console.nextLine();
}
name = name.toLowerCase();
System.out.println("Demand rate: ");
demandRate = console.nextInt();
while (demandRate <= 0) {
System.out.println("Please put in a positive integer.");
demandRate = console.nextInt();
}
System.out.println("Setup cost: ");
setupCost = console.nextDouble();
while (setupCost <= 0) {
System.out.println("Please put in a positive number.");
setupCost = console.nextInt();
}
System.out.println("Unit cost: ");
unitCost = console.nextDouble();
while (unitCost <= 0) {
System.out.println("Please put in a positive number.");
unitCost = console.nextInt();
}
System.out.println("Inventory cost: ");
inventoryCost = console.nextDouble();
while (inventoryCost <= 0) {
System.out.println("Please put in a positive number.");
inventoryCost = console.nextInt();
}
System.out.println("Selling price: ");
sellingPrice = console.nextDouble();
while (sellingPrice <= 0) {
System.out.println("Please put in a positive integer.");
sellingPrice = console.nextInt();
}
}
public static void main(String[] args) {
Interface intFace = new Interface();
intFace.run();
}
}
Try making a separate method and make those fields global. Something like this
import java.util.Scanner;
public class Interface {
int demandRate, option, end;
double setupCost, unitCost, inventoryCost;
double sellingPrice, optimalOrder;
String name;
private void run() {
Scanner console = new Scanner(System.in);
Store store1 = new Store(); // MUST DO THIS
do {
System.out
.println("Enter product data (0), Show product data (1), Show product strategy (2), Exit program (9).");
option = console.nextInt();
switch (option) {
case 0:
enterData(console);
break;
case 1:
break;
case 2:
break;
case 9:
System.out.println("You chose to exit the program.");
break;
default:
System.out.println("Please choose a valid option.");
}
} while (option != 9);
}
private void enterData(Scanner console) {
System.out.println("Product name between 3 & 10 characters long: ");
name = console.nextLine();
while ((name.length() < 3) || (name.length() > 10)) {
System.out
.println("Please put in a name between 3 & 10 characters long.");
name = console.nextLine();
}
name = name.toLowerCase();
System.out.println("Demand rate: ");
demandRate = console.nextInt();
while (demandRate <= 0) {
System.out.println("Please put in a positive integer.");
demandRate = console.nextInt();
}
System.out.println("Setup cost: ");
setupCost = console.nextDouble();
while (setupCost <= 0) {
System.out.println("Please put in a positive number.");
setupCost = console.nextInt();
}
System.out.println("Unit cost: ");
unitCost = console.nextDouble();
while (unitCost <= 0) {
System.out.println("Please put in a positive number.");
unitCost = console.nextInt();
}
System.out.println("Inventory cost: ");
inventoryCost = console.nextDouble();
while (inventoryCost <= 0) {
System.out.println("Please put in a positive number.");
inventoryCost = console.nextInt();
}
System.out.println("Selling price: ");
sellingPrice = console.nextDouble();
while (sellingPrice <= 0) {
System.out.println("Please put in a positive integer.");
sellingPrice = console.nextInt();
}
}
public static void main(String[] args) {
Interface intFace = new Interface();
intFace.run();
}
}
Interface is some kind of an abstract class definition keyword in java.
You can use a keyword to name your class with capitalized letters, but seriously, don't do this.
And you are not calling a method, you are implementing it in another method. You should go over writing and calling a method in java once again ;)