I am having an issue where the code does something very strange when run. Everything seems to be ok in the code but I don't know what is wrong as no error is given.
Here is the code:
import java.util.Scanner;
public class Pizza {
private static int pizzaSmall = 10;
private static int pizzaMedium = 12;
private static int pizzaLarge = 14;
private static int costPerTopping = 2;
/**@return The total cost of the pizza when given the pizza size and the toppings.*/
[Code] ....
And here is the console output:
Please enter the number of Cheese toppings that you would like: 1
Please enter the number of Pepperoni toppings that you would like: 1
Please enter the number of Ham toppings that you would like: 1
Please enter Small for a Small Pizza, Medium for a Meddium Pizza, and Large for a Large Pizza:
The number of Cheese toppings is 1.
The number of Pepperoni toppings is 1.
The number of Ham toppings is 1.
I want to execute my jsp code to compare two dates after every 10 seconds if user enter date and current sys date are equal it will send the mail to the user automatically. Below is my jsp code
this if condition i want to check the date after every 10 seconds and when two dates are equal it will send the mail using below mail code
if(ExpcReDt.compareTo(dateStr)>0) { out.println("Expected return date is greater than current date"); } else if(ExpcReDt.compareTo(dateStr)==0)
I am unable to run this java mail code, whats the error!!
public class Class1 { final String senderEmailID = "from@gmail.com"; final String senderPassword = "password"; final String emailSMTPserver = "smtp.gmail.com"; final String emailServerPort = "465"; String receiverEmailID = null;
[Code] ...
I get an error as this
javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1 at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1949) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654) at javax.mail.Service.connect(Service.java:317)
I have the program written correctly, but it won't execute.
public class Welcome { public static void main(String[] args){ //Display message Welcome to Java! on the console System.out.println("Welcome to Java"); } }
I compiled the code as written below with "javac Welcome", and use the "Class" name "Welcome"
So when writing my first "Hello World" app everything seemed to work just fine. I wrote the code, compiled it, and then ran the class file and it worked, I got the return Hello World! But when I tried to write another app which is basically the exact same thing just a different sentence, I keep getting a bunch of error codes saying illegal character. I did everything the exact same. I am using Text Edit on a Mac and using Terminal to execute the Java code.
Here is what I wrote....
public class MyFirstApp { public static void main( String[] args ) { System.out.println(“i rule the world!”);
I am running my Java code with SecurityManager enabled. The code must load a DLL and invoke methods written in C using JNI. Is there a documentation available describing the permissions needed for native code?
In fact, I'm not yet past that "Hello World" program.I'm following the steps in "Head First: Java" book, and reached that point where one is ready to write his/her 1st Java code. Here's mine:
public class MyFirstApp { public static void main (String[] args) { System.out.println("I Rule!"); System.out.println("The World!"); }
}
As simple as it should be, and compiles fine producing the correspondent class. But it doesn't run, however, and spits the following execution-time errors:
Exception in thread "main" java.lang.UnsupportedClassVersionError: MyFirstApp : Unsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:643) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
I have two files - I can get the second one to populate with the first ones data and then delete the first one. I cannot get it to then rename itself to the name of the first file. It also only hits the 'rename' section of the code providing I place system.gc in otherwise it completely skips it.
in my ui i will i will select enabled or disabled then it will go in controller , i already debug it and it goes on the right controller based on what i select on ui my problem is when i select disabled it dont display the message but when i select enabled it displays the message, then i check the databases status is change based on what i select but when i change into disabled doesnt display any message.if select enabled will go in controller then change status into true then update the status then will see the message in ui
I want to create a java program to find the applications running in my computer. And then I want to select a particular application called 'Harvest Client.exec'. Bring the application to front. And Then find a textbox in it and paste the things from clipboard.
I am not sure how to do this. I started by using some Runtime methods. But I am not getting anywhere.
I have problems with private static void print section, something is missing? And in case 4, I want it to stop the program(end the loop) but it keeps going.
import java.util.Scanner; import java.util.ArrayList; public class Dogregister16 { public static ArrayList<Dog> dogregister = new ArrayList(); private static Scanner keyboard = new Scanner(System.in); public static void main(String[] args) { initiate();
[Code] ....
case 4: System.exit(0); System.out.println("Exit program"); } } } }
I have a practice exercise here wherein I will add a JOptionPane to a program. When the close button is clicked, the JOptionPane will appear asking the user to exit the program. If the user clicks "Yes," it'll, of course, close the entire program and not just the JOptionPane, but if the user clicks "No," it will return to the program. Please refer to my code below:
try { output = new DataOutputStream(new FileOutputStream("ProjSixExe4.dat")); } catch(IOException ex) { this.dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)) } final JOptionPane optionpane = new JOptionPane("Are you sure you want to quit this program?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
The exercise said it must be placed before the EXIT_ON_CLOSE portion.
I use the right term, release resources because after clicking the close button, the DOS prompts becomes unresponsive. So I have to close the DOS prompt, then reopen it, then type in the path again for the Java folders. Can you check where did I go wrong with my code? Is my placement of the WindowListener and WindowAdapter incorrect? Please refer to my code below:
I have other programs where the placement of the WindowListener and WindowAdapter are as exactly like this (within the class constructor block) where they close correctly and some that behave like this, that renders the DOS prompt unresponsive.
public class testRuntime{ public static void main(String args[]) throws Exception { Runtime.getRuntime().exec("mpstat"); } } mh_sh_highlight_all('java');
I learned that executing mpstat returns information on the CPU.
I just want to know how I can get my program to end when the user inputs "0." By using: System.exit(0);
import java.util.Scanner; public class TestCode { public static void main (String [ ]args ) { Scanner console =new Scanner(System.in); System.out.println("To exit program input 0"); for (int y = 1; y < 11; y++ ){ // Executes output 10 times
I am doing a program that has a weighted average calculation and everything compiles and runs. It is just that my weighted average seems to be calculating incorrectly.This is the type of output I should see:
Homework: Number of assignments? 3 Assignment 1 score and max? 14 15 Assignment 2 score and max? 16 20 Assignment 3 score and max? 19 25 Sections attended? 4 Total points = 65 / 80 Weighted score = 40.63 Exam 1: Score? 81 Curve? 0 Total points = 81 / 100 Weighted score = 16.2 Exam 2: Score? 95 Curve? 10 Total points = 100 / 100 Weighted score = 30.0 Course grade = 86.83
Below is my code and I think even after getting up this morning and looking at it, I have an error in the calculations, but I can;t pinpoint it.This program is supposed to receive input from user, and calculated the grades of a student with a weighted average
import java.util.Scanner; public class Grades{ private double weightExam; private double score; private double curveAmount; private double scoreTotal;
my assignment is to code a program to simulate the rolling of 2 dice. I have most of it set but when I run it and have it print out how many times each number (2-12) was rolled, it displays the numbers 1 off. for instance it will display the number of 4s rolled next to the 5s.
here it is
import java.util.Scanner; //allows info to be inputted// import java.util.Random; //opens random number generator// public class RollTheDiceWithArray13 {
I am still relatively new to java and am working on a lab program. I have already met the requirements and am trying to spice my code up with a loop that prompts the user to say if the program should run again. This is what I have so far:
package lab2; import java.util.Scanner; public class OrderedPairTest{ public static void main(String[] args){ boolean retry = true; while(retry == true){
[code]....
However, it is giving me an error after the user inputs "y" in for the answer to run again. What did I do wrong?
Error code is: Exception in thread "main" java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine(Unknown Source) at lab2.OrderedPairTest.main(OrderedPairTest.java:11)
I'm attempting to make a simple Pythagorean Theorem program (A squared + B squared = C squared) but am running into problems when I write it as object oriented. The darn thing works when written as a simple process, but that isn't Java now is it? Here's the simple:
public class PythagoreanTheorem extends ConsoleProgram { public void run() { println ("Finding C from A and B."); double a1 = readDouble("Input A: "); double b1 = readDouble("Input B: "); double aSq = (a1*a1); double bSq = (b1*b1); double cSq = (aSq + bSq); double c = Math.sqrt(cSq); println ("C = " + c);
I am making a program, where the user answers 3 questions and then I add the number of correct answers in to the (int) numberofcorrect variable, then I want to print the results, and no matter how many correct, the program executes first the correct if statement, then the else statement.
Eg: I have 2 correct it will print:
"Grade B, 2 of 3 "
"You failed the test"
Why does it do that? How can I change my code so the else statement dosent print if one of the if statments is allready printed?I want to know how to not execute the else statement, if one of the if statements have allready been executed.Below is my current code for this problem:
if (numberofcorrect == 3){ System.out.println("Grade A, full score");} if (numberofcorrect == 2){ System.out.println("Grade B, 2 of 3 ");} if (numberofcorrect ==1) { System.out.println("Grade C, 1 of 3");} else { System.out.println("You failed the test"); }
I'm having some trouble with getting this program to read an input of morse code and then produce an output of English. When typing in morse code for the phrase 'the string', the output looks something like this: