New York City temperature ranges for 12 months are given below:
Jan Feb Mar Apr May JunJul Aug Sep Oct Nov Dec
25-38 26-40 34-4843-58 52-68 62-7768-83 60-75 49-65 41-54 31-4347-61
1.Create an int array of size 366 to save the daily temperatures for a leap year.
2.Fill the array with randomly generated numbers between the ranges for that month. For example, for the first 31 days of the year (that is the month of January) randomly generate numbers between 25 and 38. For the next 29 days (the Month of February) randomly generate numbers between 26 and 40, and so on for every month.
The formula for generating random numbers between two numbers m and n is, (int)Math.floor(m + Math.random() * (n-m+1)); Or you may choose to use the Random Class from the util package.
3.Print the average temperature for each month.
4.Print the hottest day for the entire year, in the following format: Example: The hottest day was Thursday, July 4. Also, mention what the temperature Was on this day. You may assume that January 1 was a Monday.
5.Print the coldest day for the entire year, in the following format: Example: The coldest day was Tuesday, February 12. Also, mention what the temperature was on this day. Again, assume that January 1 was a Monday.
6.How many days in the year was it below 330 F and how many more than 750F.
So far i Have this
import java.util.Random;
public class NYCTemp
{
String [] days = {"Sunday","Monday","Tuesday","Wednesday","Thursday ","Friday","Saturday"};
String [] months = {"January","February","March","April","May","June" ,"July","August","September","October","November", "December"};
int [] daysInMonth = {31,29,31,30,31,31,30,31,30,31,30,31};
- The user runs CarDealer JFrame in which appears a JTexField in which he types in some characters (pretending he types some data about selling licence). - The user clicks on the JButton "Save" that stores the characters typed in inside a String variable called strLicence. - The user clicks on the JButton "Open 'Vehicle Form'" that opens the Vehicle JFrame. - Finally, in the Vehicle JFrame I want to write a code that can see/use the value of the String variable called strLicence.
In other words, for example, I want to store the value of strLicence in a new variable declared in the Vehicle class.
(Actually I'm working with a long and elaborate project for the dissertation of my bachelor's degree, so, for cutting to the chase, I simplified it by creating an essential JFrame project.)
how access levels work from subclasses and other packages, and I have discovered that a class cannot see it's own protected variable from another package which I thought it would be. I know that it says in the java docs "The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package." but I thought that would also include it's own class.
Java Code:
package food; import food.fruit.*; public class Food { protected int protecte = 5; private int privat = 5; protected void method(){
My working directory is e:ajava. in package p1 i create two classes c1 and c2. net beans creates three files e:ajavap1srcp1, e:ajavap1srcc1, e:ajavap1srcc2. package runs without a hitch. i create another package p2 under e:ajava. i want to use class c1 in p2. pray what on earth should be my import statement in the p2 source code after the first statement 'package p2'. another related querry what should i include in my class path so as to gain access to c1 and c2 in source code of p2.
I am puzzled by a note in the book I am reading (by Mala Gupta). Page 55 says "All java components you've heard of can be defined within a java class: import and package statements, variables.....". But the online oracle doc (tutorial) clearly says the following 2 statments:
"If present, package statement must be the very first line in a file"
"To import a specific member into the current file, put an import statement at the beginning of the file before any type definitions but after the package statement, if there is one. " (Here).
So, how can import and package be present inside a class ? (This seems to go against the 2 statements from oracle online tutorial).
I'm trying to access class file which is inside the package and package is inside the jar file but I can't access that class file inside my source file . All files are on desktop .
I don't want a tutorial that shows me how to do a util timer with a button, or that prints a message, or that does anything. I want the simplest possible snippet that makes the timer, lets me have it do something, and can be stopped. No bells and whistles, no strings, no sparkles and explosions. Just a timer.
Let's say hypothetically you're making a huge program and use a lot of imports (ex import java.util). If you only need a few specific things from java.util, will it use more memory importing java.util.* compared to only importing lets say java.util.Scanner, java.util.ArrayList, etc. Basically does importing a whole package use more (if any at all) memory than only importing specific package parts?
in my progrm there are three diff array of objects...namely garments..gadgets and home app...now one who buys from each of these sections will have to make a bill at last...when he choses to make the bill he will be shown the list of products he bought and their details (like price...brand...etc)...so i thought that while he orders each product(which is done in a previous method called purchase()...)....(each product is stored as an object in there diif arrays namely garments...gadgets ...appliances)....each of those object will be copied in a new array in a diif class...then that array print will give me the desired result...
is this approach correct...?and if its correct then how can i pull out a specific obj frm a stored array of object and then save it in a new array....?
The program I'm supposed to create generates a random number between one to ten. Then the program is to ask me if I wish to cross the road. If you choose to cross, the outcomes for 0-2 are "You crossed safely." For 3-5, 75% of the time it should say "RIP you got run over", and 35% of the time it should say "You crossed the street." For 6-8, 60% of the time it should say you made it.", and 40% of the time it should say "You died". For 9-10, it should say "RIP".
So far I have gotten the random number generation part working. I have up to here:
import java.util.Random; public class test4 { public static void main(String[] args) { Random random = new Random(); for(int i =0; i < 1; i++){ int num = random.nextInt(10) + 1; System.out.println("The number of cars on the street are: " + num + "Do you wish to cross the road?"); } } }
my new class had me download eclipse and for some reason it won't let me type anything until I create a document. creating a document creates a package and that lets me create a class which then it will let me start typing code...so wtf is wrong with eclipse and why is it bulling me into having this "package" line in my code when I never had anything like that in other ide's?
I have a folder of classes that I am packaging together. Some classes are being packaged and compiling just fine. My other classes in the same package, however, are saying that they cannot find these classes.
Though have been playing around with my ebook but finding it difficult to get along with the topic PACKAGE&INTERFACES, I find it challenging to write a package file despite the book I currently studying and online tutorial.. so I want a more explanatory format to comprehend the piece cos without knowing it.
I am trying to make a jar file in intelliJ. My directory that holds all the java classes is C:rafficProjectsrccege. In cege there is a package ui where there is a class GuiMain. And I have imported the GuiMain() in my Main() class.
I have this code lines:
package cege; import cege.ui.GuiMain;
and when I use the terminal in the intelliJ and write the command:
C: rafficProjectsrccege>javac *.java
I get this message:
Main.java:3: error: package cege.ui does not exist
import cege.ui.GuiMain;
but actually, I have already put this line in my code. what could be the problem?
Public Class{ Objects Constructor(){} ActionListener Method(){} Main Function()}
[Code]....
but I cannot declare variables in this method, how can I do this what can be the simplest method?
In addition: I've a marksheet class, a calculator class, & in main class I've 2 buttons one for marksheet & one for calculator, how can I make it so that if user clicks on marksheet button that class should be called & so?
This code doesn't recognise the package ( and therefore class ) timetest3, when I try to import it. The package I try to reference/call, follows, and works fine.
import javax.swing.JOptionPane; import timetest3.TimeTest3; public class timetest4 { public static void main(String args[]) { TimeTest3 time = new TimeTest3(); time.setTime(13,45,52);
i have a program in UNIX directory /home/me/java/src
package bin; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } }
I have manage to compile it successfully(class file will be in bin directory) using command below: javac -d /home/t_bmf/java/bin HelloWorld.java
My problem now is how would I execute the class in bin directory in UNIX? I already tried different ways on how to execute it as suggested in my internet research The one I tried is this:
java $CLASSPATH:.:bin/HelloWorld but I got this error message: Exception in thread "main" java.lang.NoClassDefFoundError: :/:bin/HelloWorld Caused by: java.lang.ClassNotFoundException: :.:bin.HelloWorld
Iam getting this error at run time while using this command "java mypack.Accountbalance". I have compiled this source code and got its class file that I have put in mypack package but now its showing this error ..
Here's the code : package mypack; class Balance { String name; double bal; Balance(String n ,double b)
[Code] .....
Error: exception in thread "main" java.lang.NoClassDefFoundError: mypack/Ba at mypack.Accountbalance.main(Accountbalance.java:25) used by: java.lang.ClassNotFoundException: mypack.Balance
I am using javac -d WEB-INFclasses WEB-INFclassesdemoServlet4ListenerTest.java and javac -d WEB-INFclasses WEB-INFclassesdemoServlet4MyServletContextListener.java to compile the classes.
I have a class that works only when in the default package. If I move the class to a package I receive UnsatisfiedLinkError.
This is the class in the default package(this works fine):
[code] public class CsharpConsumer { private native int reigsterAssemblyHandler(String str); public CsharpConsumer() { String dir = System.getProperty("user.dir"); System.load(dir+"dllscardJNICsharpBridge.dll"); int reigsterAssemblyHandler = reigsterAssemblyHandler(dir+"dllscard"); } } [/code]
If at the top of this class I add "package DLLUtils;"
the error is "Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError:
I'm trying to setup a function that takes input from a user and prints it onto a label and updates it per entry. The updating would occur through removing the old label and then adding a label with the updated value. The text would be center-aligned. While I'm able to get the label to print the current value of "entry", it does so without removing the label with the old value.
I tried reversing the add(label) and remove(label) to see if there is a syntax error with remove, and I determined from the label not being there at all that remove was called correctly. I have kept the loop infinite for debugging purposes to work with various test cases as they come to me.
Java Code:
import acm.graphics.*; import acm.program.*; public class testCanvas extends ConsoleProgram { public void run() { GCanvas canvas = new GCanvas(); add(canvas); String entry ="";