I have coded three classes ,1 class containing the Main method. I have declared three private data fields in Staff class and two data fields in Address class. The problem is that I am assigning String type data field from the Staff and Address Class through the public set methods to String type array in a public void method in the Main class.
public static void main(String[] args){ // TODO code application logic here System.out.println("-------------------------------------------------"); System.out.println("Press 1 - 6 To Perform Any One Following Action "); System.out.println("1. Insert New Contact "); System.out.println("2. Delete Contact By Name "); System.out.println("3. Replace Info From Contact "); System.out.println("4. Search Contact By Name "); System.out.println("5. Show All Contacts "); System.out.println("6. Exit Program ");
import javax.swing.JOptionPane; public class Input { public static void main(String[] args) { int user; user = JOptionPane.showMessageDialog(null, "Enter Your Age""); ERROR IS HERE if(user <= 18) { JOptionPane.showMessageDialog(null, "User is legit"); } else { JOptionPane.showMessageDialog(null, "User is not legit"); } } }
I'm getting this error message :
incompatible types: void cannot be converted to int
int a, b, sum; System.out.print("the sum is"); Scanner in = new Scanner(System.in); a = in.nextInt(); b = in.nextInt(); Sum = a + b; System.out.println("the sum us" + sum);
in "sum = a+b" its says "incompatible types: int cannot be converted to boolean" I dont understand why
I am working on a project that just calculates simple interest based upon a principal and a percent interest rate written as .xxxx from user.
I need the Loan amount and the final interest calculation to show up as a currency with commas in appropriate areas, the Rate to be expressed as X.xxx% instead of .xxxx
I keep getting this error when I compile:
C:JavaInterestCalculator.java:46: error: incompatible types: String cannot be converted to double principal = formatter.format(principal); ^ C:JavaInterestCalculator.java:49: error: incompatible types: String cannot be converted to double rate = formatter.format(rate); ^ C:JavaInterestCalculator.java:52: error: incompatible types: String cannot be converted to double totalInterest = formatter.format(totalInterest); ^ 3 errors
Tool completed with exit code 1
And here is my code
import java.util.Scanner; import java.text.NumberFormat; import java.text.DecimalFormat; // class declaration public class InterestCalculator { // main method declaration
What the program must do is to parse the string-declared two-dimensional array for the program to compute the student's scores in their quizzes, but I'm having difficulty in anything with Parsing so I don't know what will be the appropriate codes.
Error: incompatible types: String[][] cannot be converted to int[][]
import java.io.*; public class Quiz3{ public static void main(String[]args)throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String [][]StudQuiz = new String [5][4];
[Code] ....
How am I able to compute the average of the score if the data that is needed to be computed is in the string-declared array?
I am trying to convert the double 4270571936.0000000000d to a hex string using Double.toHexString() and the answer I'm getting is 0x1.fd17834p31, what does p stands for?
The answer I'm expecting to get is 0x41efd17834000000 so not sure why it won't give me the correct answer?
The following floating point Double to hex calculator shows the write answer right Floating Point to Hex Converter
//Students Full Name firstName = JOptionPane.showInputDialog("Enter student " + "first name."); lastName = JOptionPane.showInputDialog("Enter student " + "last name."); // Get test grade (numbers) [b]test1 = JOptionPane.showInputDialog("Enter test1 grade")[/b];
The line in bold is where that error comes up. I know it something simple but I can't remember. I declared both firstName and lastName as Strings and then the test1 I declared as double. I had a similar error in a previous assignment where I had a integer(age) input and then i had an output statement asking for a name all I needed to do was put keyboard.nextLine(); after my age input and I was fine.
I am making a program where the user types in how many students, the student name and the student result. My problem is typing in a dobule name for instance: Tom Tom.
I have tried both:
String name = input.Next(); -> Only works with one name. and String name = input.nextLine(); -> Skips right trough and ask me to type result again.
Here is my code:
Java Code:
import java.util.Scanner; public class c5e8 { public static void main(String[]args){ Scanner input = new Scanner (System.in); int highestResult = 0; String highestName = " ";
I'm having an issue with figuring out how to structure and call a method using a string prompt. My prof has given us specific methods to create, and the one I'm having issues with is blic static double getOperand(String prompt). What I have currently is this:
public static double getOperand(String operand1, String operand2){ Scanner input = new Scanner(System.in); System.out.println("What is the first operand?"); operand1 = input.toString();
System.out.println("What is the second operand?"); operand2 = input.toString(); return operand1, operand2; }
which is obviously not working. When I asked my prof he sent me this, "The String paramater in the getOperand() method is intended to have the prompt value that is passed to it. Within the method, the prompt is then displayed, what the prompt is asking for is input, and then returned to the method call.For example, if the method is public double getOperand(String prompt) within the method you would display the prompt, as in System. out. println(prompt), use the Scanner class to create an object, perhaps called input, and then use the input object to get the value asked for by the prompt. Once you have that value, which in this example would be a double, then return the value to the method that called it.
The call could be something like this: double value = getOperand("What is the first operand?");". But that only works a little. Clearly I'm missing something and no matter what I google, or how many times I read the chapter, I am just not getting this. Everything else up to this point has been easy. and I can create regular methods just fine, the menu method works, but I can't figure out this string method and all the rest build off this method.
I am supposed to write a program on PuTTY using UNIX (I have Windows 8), but I am not comfortable with it yet, so I am using Java through NetBeans (IDE 7.4).
The program has to follow these instructions (ignore the Linux part of the instructions, the rest is in bold):
Write a program on the Linux system using the putty utility. The program should get strings of data from the command line (that is, look for the data in the "args" array of strings). Use a loop to convert each of the strings in the array into a double and add the number to a total. Print the total after all of the strings have been processed.
The program will use try-catch to catch any error that occurs. If an error occurs, the program will print a message saying that the error occurred. The program can end at that point.
You should create the Java program using the nano editor. The input data should be a list of numbers on the line that runs the program.
The problem so far is that I keep getting an error when converting a String value into a new double value. I have yet to code the try-catch method in my program
Java Code:
import java.util.*; public class Program13Strings { public static void main(String[] args) { Scanner scan = new Scanner (System.in); System.out.println("How many lines of data do you wish to enter?"); int size = scan.nextInt();
[Code] ....
*NOTE: right where my code says double newDouble = Double.valueOf(newResponse); is where the error is occurring.
*ERROR: Exception in thread "main" java.lang.NumberFormatException: For input string: "abc"
at sun.misc.FloatingDecimal.readJavaFormatString(Floa tingDecimal.java:1241) at java.lang.Double.valueOf(Double.java:504) at program13strings.Program13Strings.main(Program13St rings.java:21)
This may be a multipart question. Basically I have to write a program that accepts a string, converts it to a double splits it and then performs a calculation.
public static void main(String[] args) { String input = ""; // initalize the string boolean isOn = true; // used for the while loop...when false, the program will exit. String exitCommand = "Exit"; // exit command String[] token = input.split(("(?<=[-+*/])|(?=[-+*/])"));
[Code] ....
This is the error I get:
Enter a math problemException in thread "main" java.lang.NumberFormatException: empty String at sun.misc.FloatingDecimal.readJavaFormatString(Floa tingDecimal.java:1842) at sun.misc.FloatingDecimal.parseDouble(FloatingDecim al.java:110) at java.lang.Double.parseDouble(Double.java:538) at Calculator.main(Calculator.java:22)
[Code] .....
How do I go about actually fixing it. Without that line commented out I get this:
Enter a math problem 2+2 <-What I entered [Ljava.lang.String;@135fbaa4
Also, how would I go about using the submethods to check for valid operands and operators (also part of the problem) I have the actual lists made obviously, but am unsure how to get those to work with the problem.
I have a double primitive and gave it a huge value. I am curious if valueOf could ever potentially cause data loss. I tried a simple test and it seems it never loses any data:
Java Code:
public class DoubleStringTest { public static void main(String[] args) { double val = 1029.129348558634; System.out.println(val); System.out.println(String.valueOf(val)); } } mh_sh_highlight_all('java');
I am working with java project which is kind of charting room..but the problem is when am writing the query for listing the message in the conversation the error prevail in my eclipse...string literal is not properly closed by double quote...this is my java file
I am trying to make a program that calculates the change due in dollars and cents. The user inputs both the amount due and the amount tendered. My program only works with whole numbers?
I am writing a code in which a user inputs data as a string and that data must be verified as a valid number. A valid number is anything from 0-100. Then all valid numbers are converted into double numbers.
I am having trouble in how to write the validation part of the code.
Is it suppose to be an if, else statement? And if so how is it suppose to be validated?