Java Cannot Be Applied To Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us java lang string cannot be applied to java lang string Learn more about Stack Overflow the company Business Learn more about hiring developers
Object In Object Cannot Be Applied
or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow operator cannot be applied to java lang string Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Java error: method in class cannot be applied
Operator Cannot Be Applied To Java.lang.object Int
to given types up vote 3 down vote favorite I am just trying to call the methods to the main for each switch when it happens, but i just get the error message everytime i try to call any methods, not trying to return anything. ex. if the user enters a or A i want to call the add method to main public static void main(String[] args) cannot be applied to java.lang.string int { char character; Scanner keyboard = new Scanner(System.in); while (character != 'E' || character != 'e') { System.out.println(" A:Addition \n S:Subtraction \n M:Multiplication \n D:Division \n R:Modulus \n E:exit"); switch (character) { case 'a': case 'A': System.out.println("your choice A"); add(); break; case 's': case 'S': System.out.println("your choice S"); subtraction(); break; case 'm': case 'M': System.out.println("your choice M"); multiplication(); break; case 'd': case 'D': System.out.print("your choice D"); division(); break; case 'r': case 'R': System.out.println("your choice R"); modulus(); break; default: System.out.println("Error: please enter a valid letter"); break; } } } public static void add(Scanner keyboard) { int a,b; //get integer 1 System.out.println("enter integer 1"); a = keyboard.nextInt (); //get integer 2 System.out.println("enter integer 2"); b = keyboard.nextInt(); int total = a + b; System.out.println(a + "plus" + b + "is" + total ); } public static void subtraction(Scanner keyboard) { int a,b; //get integer 1 System.out.println("enter integer 1"); a = keyboard.nextInt (); //get integer 2 System.out.println("enter integer 2"); b = keyboard.nextInt(); int total = a-b; System.out.println(a + "minus" + b + "is " + total); } public static void multiplication(Scanner keyboard) { int a,b; //get integer 1 System.out.println("enter integer 1"); a = keyboard.nextInt (); //get integer 2 System.out.println("enter integer 2"); b
Topic/Question Reply 15 Replies - 12001 Views - Last Post: 16 November 2008 - 07:56
Java Cannot Be Applied To Int
PM Rate Topic: #1 Brandon222 D.I.C Head Reputation: 0
Operator Cannot Be Applied Java
Posts: 142 Joined: 16-November 08 Error: cannot be applied to () Posted 16 November 2008 - 03:40 PM Hi...ok well im doing this project where i have to make a program to do online banking...i think im doing it right but http://stackoverflow.com/questions/28445862/java-error-method-in-class-cannot-be-applied-to-given-types i keep getting three errors.. they are: File: C:\Program Files\Java\New Folder\Bank.java [line: 19] Error: getName(java.lang.String) in Customer cannot be applied to () File: C:\Program Files\Java\New Folder\Driver1.java [line: 6] Error: cannot find symbol symbol : constructor Bank(int) location: class Bank File: C:\Program Files\Java\New Folder\Driver1.java [line: 6] Error: internal error; cannot instantiate Bank.
details. Win a copy of Penetration Testing Basics this week in the Security forum! Post Reply Bookmark Topic Watch Topic New Topic programming forums Java Java https://coderanch.com/t/452767/java/java/lot-method-applied-java-lang JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This http://www.java-forums.org/new-java/48853-java-error-cannot-applied-java-lang-string-phone-book-entry-program.html Site Careers Other all forums Forum: Beginning Java Getting a lot of "method cannot be applied to (java.lang.string)" Toshiro Hitsuguya Greenhorn Posts: 19 posted 7 years ago I am trying to write a program that simulates a simple libraray. I am having some trouble applying some of cannot be the methods to the main method. Here is my code so far: public class Library { Book[] books; int numBooks; String address; void addBook(Book b) { //Adds books to the array of this library books[numBooks] = b; numBooks++; } public boolean borrowBook(Book aBook) { //Marks the book as borrowed return aBook.borrowed(); //refers to a method in another class I created cannot be applied } public boolean returnBook(Book aBook) { //Marks the book as returned return aBook.returned(); } public Library(String street) { //creates new street address street = address; } public String printAddress() { //returns the street address when referenced return address; } public Book printAvailableBooks(Book b) { //supposed take a book out of the list if borrowed for(numBooks = 0; numBooks < 10; numBooks++) { if (numBooks>0) { System.out.println("Were sorry there are no books avalible at this library"); } else if(b.borrowed == false) { //references a varible in the Book class System.out.println("We are sorry this book is checked out."); //this line is supposed to be java.lang.string } else if(b.borrowed == true) { System.out.println(b[numBooks]); } } return b;} public String printOpeningHours(String hours) { hours = "We are open from 9-5."; } public static void main(String[] args){ Library firstLibrary = new Library("10 Main St."); // Create two libraries Library secondLibrary = new Library("228 Liberty St."); firstLibrary.addBook(new Book("The Da Vinci Code"));// Add four books to the first library firstLibrary.addBook(new Book("Le Petit Prince")); firstLibrary.addBook(new Book("A Tale of Two Cities")); firstLibrary.addBook(new Book("The Lord of
book entry program. Results 1 to 13 of 13 Thread: Java Error cannot be applied to (java.lang.String), phone book entry program. LinkBack LinkBack URL About LinkBacks Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Search Thread Advanced Search Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 09-23-2011,09:49 AM #1 iceyferrara Member Join Date Sep 2011 Posts 10 Rep Power 0 Java Error cannot be applied to (java.lang.String), phone book entry program. So we have to have two classes so i set it up good and it was almost exactly like my friends who's worked but mine gives me two errors. Here are the two classes. The Errors i recieve are: E:\Lab 2\PhoneBookList.java:20: getName() in PhoneBook cannot be applied to (java.lang.String) entry.getName(keyboard.nextLine()); ^ E:\Lab 2\PhoneBookList.java:22: getNumber() in PhoneBook cannot be applied to (java.lang.String) entry.getNumber(keyboard.nextLine()); ^ Any help? i put it in right but its saying it cant be applied to string which i dont know why. Any help would be greatly appreciated. Last edited by iceyferrara; 09-23-2011 at 10:09 AM. Reply With Quote 09-23-2011,10:07 AM #2 iceyferrara Member Join Date Sep 2011 Posts 10 Rep Power 0 Re: Java Error cannot be applied to (java.lang.String), phone book entry program. Java Code: //Mike Ferrara //Lab 2: 8.13 import java.util.*; public class PhoneBookList { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String[] nameList = new String[5]; String[] numberList = new String[5]; PhoneBook entry = new PhoneBook(); System.out.println("Please enter a name then their corresponding " + "number. (dashes not included): Press enter after each name and number "); for(int i = 0; i < nameList.length; i++) { entry.getName(keyboard.nextLine()); nameList[i