I am writing a program to store books (Book class) in volumes (Volume class). Within the main class (DemoVolume) I am doing a couple different things. I want to ask the user if they are creating a new array, if yes, I was to create a new array with a variable names assigned by the user. Is this possible? The reason is I want to allow the user to be able to search their library of volumes. If no, then the user will enter the book information and I will assign it to an array unassignedVolume that will contain individual books. I would also like to create book objects that are defined with the book name, if this is possible. I'm just messing around and trying to deepen my understanding of JAVA. My main issue is how to allow the user to title the volume (array variable).
import java.util.Scanner;
public class DemoVolume {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String [] volume, unassignedVolume;
Volume volumeOne = new Volume("JAVA", 3, volume);
I don't understand how i'm supposed to define a variable when the user has to type it into the program so it can be converted. This program i'm working on is supposed to convert from meters to feet (meter = feet * 0.305) but the user has to type in the meters they want converted. how do i solve the problem that keeps coming up that says "variable meter symbol cant be found" ? I keep trying different lines to no avail
public class Lab2 { public static void main(String[] args) { double feet = meter * 0.305; double meter = feet/0.305; System.out.println("Enter in feet for conversion to meters"); meter = meter * 0.305;
Okay, so I know how to get user input and create a variable from the input, create a basic addition sum etc...
So I have this code:
package calc; import java.util.Scanner; class calc{ private static final double add = 0; private static final double subtract = 0; public static void main(String args[]){
[Code] .....
I'm basically trying to make it so that when the user enters tnum, tnum2, tnum3 and tnum4, their answer turns to the variable which has to be either true or false to make the boolean work. I don't know really how to do this. I want to make it so that if they enter yes, then that makes the boolean true and the numbers will multiply and create the answer variable. If they enter no then the boolean is false and it moves onto the next if statement. How can I do this?
I need the user to be able to input a number, and for the program to assign this value to an 'int' variable. I know how to do this with a 'string' variable:
Java Code:
String options = JOptionPane.showInputDialog(null, "In your decision, how many options do you have? " +" (NOTE: The maximum number of options = 5, and you must enter your answer as a numeral.)"); mh_sh_highlight_all('java');
But I need to know how to do this with an 'int' variable.
I'm trying to build a program that will output what will ultimately look like a simple mario level turned on its side. As part of my output I need the user to define what mario looks like. I do this using Scanner and save the input to String mario. When I try to use that variable in another method it gives me troubles.
import java.util.Scanner; public class Mario2 { public static void mario() { //user defines mario String mario = ">->O"; Scanner keys = new Scanner(System.in); System.out.println("What does mario look like?"); mario = keys.next(); System.out.println("Mario now looks like: " + mario);
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 trying to use a JFrame to open up extra windows that will prompt the user the Log In or Out, but I am getting an error with one of my variables that writes to Excel. There is something wrong with the variable "sheet" contained in the "while(i <= 4)"
private void createLabel(WritableSheet sheet) throws WriteException { WritableFont times10pt = new WritableFont(WritableFont.TIMES, 10); times = new WritableCellFormat(times10pt); times.setWrap(true); WritableFont times10ptBoldUnderline = new WritableFont(WritableFont.TIMES, 10, WritableFont.BOLD, false, UnderlineStyle.SINGLE);
so i'm following a java tutorial from the book and it has a few challenge questions. and i'm stucked on one. i think i just don't understand what is it that its asking me. heres the question, Write a statement that reads a user's input integer into the defined variable, and a second statement that prints the integer. assuming scanner is given, and i checked my heading code is ok.
Scanner scnr = new Scanner(System.in); int userNum = 0; System.out.println("What is the product of 8 time 2"); userNum = scnr.nextInt();
this is my program error occured run time,but compile sucessfully
{error msg-Error: Main method not found in class helloworldapp.HelloWorldApp, please define the main method as: public static void main(String[] args)} class HelloWorldApp { private int empno; private float salary; void setHelloWorldApp() { empno=12; salary=1200;
I want to create a JTable which "Analysis","Date" and "Price" the names of columns in header. Here's a piece of my code :
String sql = "Select name, Price from analysis_tab where name ='" + idclicked + "'"; DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); Date date = new Date(); PreparedStatement preparestate = database.con.prepareStatement(sql); ResultSet rs = preparestate.executeQuery();
So, the value of Analysis and Price were stored in my Data Base, and the Date get the value of the current day. How can i create this JTable and how can i set the value into it ?
I am new to Java and i am doing an assignment to identify Class and Attributes from below example. identify 7 classes and its attributes from this scenario:
ABC Maps Maker produces electronic maps for global positioning systems. Every map needs to define the latitude and longitude of the centre of the map, together with the length and breadth of the map. A map also has a name, and a set of geographical features.
A geographical feature is something noticeable in a a map; e.g., a hill, or valley. Among the types of features are the following: trace features, track features and tract features. All features have a name that is displayed on the map next to the feature.
A trace feature has a coordinate point to indicate its location relative to the centre of the map.
Broadcasting stations, mountain peaks, and transmission towers, are examples of trace features. Every trace feature has a description associated with it. Examples of track features include roads, railways and rivers. Each track feature has a list of points that define its course, and a line pattern. The line pattern specifies the colour, and the thickness.
Like a track feature, a tract feature also has set of points, except that when drawn on the map, the last point is linked to the first point to enclose a complete region. Additionally, it has a fill pattern which incorporates essentially a colour. Recall that there is a class, Point, in the java.awt package - this can be used to hold the co-ordinate of a point
I'm trying to make a simple table with JTable class by reading the following tutorial but when try to see my JTable my program doesn't show me nothing! What i'm doing wrong?
[Code] .....
import javax.swing.JScrollPane; import javax.swing.JTable; public class MyFirstTable { public static void main( String[] args ) { String[] columnNames = {"First Name", "Last Name",
I am trying to find the GCD, add, and remove the biggest and smallest fraction, however I am having trouble getting user input into the array and getting the information out of it (Variable f).
Scanner keyb = new Scanner(System.in); Fraction[] frak = new Fraction[7];
Main_Class try { for (Fraction f : frak){ // for each array in frak print f; System.out.println("Enter Numerator"); int num = keyb.nextInt(); System.out.println("Enter Denominator"); int den = keyb.nextInt(); f = new Fraction(num, den);
I'm studying about arrays and I have some questions:
First, is there any difference between these two?
Java Code:
int x[] = new int[3]; int[] x = new int[3]; mh_sh_highlight_all('java');
It seems to me when I try them they do exactly the same, is that correct?
Second, more important question. If I want to make an int variable that refers to the index number of an array, how do I write? For example if we have
Java Code: String[] string = new String[10]; mh_sh_highlight_all('java');
And I want to have a variable "int n" that refers to an index number, so that if I set n = 5 then string[5] is selected. Note that the int n is NOT an array, but just a regular integer variable. How can I do that?
I'm trying to set a variable to point to the last full cell of an array and then create a new larger array and then have the variable be updated to point to the new array's last full cell index value.
a) Should the variable be declared static? b) What would be the best initial value to set this variable to? Shouldn't it correspond to a <for> loop index rather than a solid integer?
private lastfullcell = a[i]; private int [] a;
c) How would you update <lastfullcell> because if you passed the index through a method's loop index isn't the array index value garbage collected after the method completes?
I need to process one component drag to the table. I misunderstand, how I can see to which Cell fall the component. I tried to use Event and Mouse event handlers in my custom Cell, but they do not work. I can copy the drag event to the table and table handles it, but how to get needed Cell I cant understand.