Any of my methods from Triangle with parameters don't work with their calls in TriangleDriver. I get an error:
method validSides cannot be applied to given types;
required: int, int, int found : no arguments; reason: actual and formal argument lists differ in length
Triangle
import java.util.Scanner; public class Triangle { private int a, b, c; public Triangle() { a = 0; b = 0; c = 0; } public String toString(int sideA, int sideB, int sideC) { return sideA + " " + sideB + " " + sideC; } public boolean validSides(int sideA, int sideB, int sideC) { boolean valid = true; if (sideA < 0 || sideB < 0 || sideC < 0) valid = false; return valid; } public void setSides() { Scanner keyboard = new Scanner(System.in); System.out.println("Enter three integers to form a triangle: "); a = keyboard.nextInt(); b = keyboard.nextInt(); c = keyboard.nextInt(); } public boolean displayType(int sideA, int sideB, int sideC) { boolean validTriangle = true; if ( sideA + sideB <= sideC ) { System.out.println("Triangle Type: DOES NOT FORM TRIANGLE"); validTriangle = false; } else if ( sideA == sideB && sideB == sideC) System.out.println("Triangle Type: EQUILATERAL"); else if ( sideA == sideB) System.out.println("Triangle Type: ISOSCELES"); else System.out.println("Triangle Type: SCALENE"); return validTriangle; } public int getPerimeter(int sideA, int sideB, int sideC) { int perimeter = sideA + sideB + sideC; return perimeter; } private void sortSides(int a, int b, int c) { int swap; if ( a > b) { swap = a; a = b; b = swap; } if ( a > c) { swap = a; a = c; c = swap; } if ( b > c ) { swap = b; b = c; c = swap; } } }
TriangleDriver
/** Description: This program will continually get three integers from a user to * represent the three sides of a triangle. They are displayed in * sorted order. It is determined whether the three integers * don't form a triangle and if they do, whether it's equilateral, * isosceles, or scalene. If the triangle is valid, its perimeter * is displayed. * Filename: TriangleDriver.java * Project: Assignment 5 * Author: Joey Benitez * Due Date: 11/06/2013 */ import java.util.Scanner; public class TriangleDriver { public static void main (String[] args) { Triangle theTriangle = new Triangle(); Scanner keyboard = new Scanner(System.in); String playAgain; String sortedSides; boolean validEntries; boolean validTriangle; // Continue as long as the user wants to enter Triangle sides do { theTriangle.setSides(); validEntries = theTriangle.validSides(); if ( validEntries ) { theTriangle.sortSides(); sortedSides = theTriangle.toString(); System.out.println("Sides sorted: " + sortedSides); validTriangle = theTriangle.displayType(); if ( validTriangle ) { System.out.println("Perimeter: " + theTriangle.getPerimeter()); } } else { System.out.println("INVALID ENTRY FOR SIDES"); } System.out.println(); System.out.print("Would you like to enter more triangles? "); playAgain = keyboard.next(); System.out.println(); } while (playAgain.toUpperCase().startsWith("Y")); System.out.println("Program Completed"); } }