Accessing Toolkit For Assignment

Apr 2, 2014

I'm trying to access the toolkit for an assignment I'm writing and I keep getting the same compiler message. What am I doing wrong?

import java.text.DecimalFormat;
import java.io.*;
import java.util.Scanner;
public class Robert_Gardner_6_07
{
public static void main(String[] args) throws IOException

[code]....

View Replies


ADVERTISEMENT

Applets :: JRE 7 - Reset Default Toolkit

Aug 14, 2014

I want to use my implemented toolkit while loading applets. So, I have set the Runtime Parameters

-Dawt.toolkit=org.sug.MyToolkit in Java Control panel.

But when it is not picking MyToolkit, instead its default toolkit sun.awt.windows.WToolkit.

I am able to set it perfectly in Java 6 but it is not working in java 7.

View Replies View Related

Using MATH Class For Assignment?

Sep 18, 2014

Here is the assignment:

Prompt the user to input two sides (a and b) of a right triangle. Calculate, using the

formulas below, the hypotenuse and the other two angles of the triangle. Calculate the

perimeter and the area.

Here are the formulas:

a^2 + b^2 = h^2

sinθ = a/h

A + B + C = 180 degrees

how to start this program out, i know which math classes i need to use.

View Replies View Related

Compound Assignment Operator

Jan 8, 2014

I just cant seem to understand the order of precedence here.

class Test{    
public static void main(String[] args){       
int k = 1;             
k += (k = 4) * (k + 2);       
System.out.println( k );    
}
}

From what I have read compound operators have the lowest order of precedence... But the above piece of code makes the assignment k = 1 + (k = 4) * (k + 2) before evaluating the rest of the statement first.

It then evaluates (k = 4) and proceeds with the remained of the statement 1 + 4 * (4 + 6)....

I dont understand why the first k is assigned 1 but the remaining ks 4. Should they not all be 1 or 4 (I would have thought 4, since += has the lost order of precedence so is evaluated last)??

View Replies View Related

Two Dimensional Array Assignment

Jun 14, 2014

I am working on the following java assignment..Write a program that randomly fills in 0s and 1s into a 4- by- 4 matrix, prints the matrix, and finds the first row and column with the most 1s. Here is a sample run of the program:

0011
0011
1101
1010

The largest row index: 2
The largest column index: 2

I have code that generates random 0s and 1s for the array, how to get the largest column and row.

import java.util.Random;
public class LargestRowColumn {
public static void main(String[] args){
//create 4x4 array matrix
int arrayMatrix[][] = new int[4][4];

[code]....

finding the row and column with the largest amount of 1s. I keep thinking well if I scan and find a one in the array, maybe I can just save the index of the row and column and then determine which index contains the most 1's after the array has been scanned.

View Replies View Related

Instantiating Object Without Assignment

May 17, 2014

I would like to know what is the significance of instantiating an object without an assignment.

I have created a class TestClass1 with a single constructor that prints a test message.

In TestClass2, if I write "new TestClass1()" rather than "TestClass1 x = new TestClass1()" it still works, and prints the test message.

I would like to know if I do not assign an object at the time of instantiation, it cannot be referenced or reused later, then what is the significance of this type of construct and when it can be useful, and where is the object being held.
 
public class TestClass1 {
   TestClass1() {
     System.out.println("This is a test message");
   }

public class TestClass2 {

[Code] ....

View Replies View Related

Trying To Get Data From Previous Assignment To Be Displayed In New One Using GUI

Apr 26, 2014

I am trying to get items to display that would display in a command prompt now into a GUI. I am freaking lost at the moment, probably because I've been staring at this code for over a week now. I have included all the files that are necessary to run the program as an attachment for your own testing purposes. Should I be using a TextField to display the data from the CSV files? How do I get the data to be displayed? How would I get it to be displayed based on the different files Staples (newSTPL.csv), Apple (newAPPL.csv), and Microsoft (newMSFT.csv)?

Java Code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* DataAnalyzer Class
* This class instantiates the methods from the ReadFiles Class and Calculations Class.

[code]....

View Replies View Related

2 Dimensional Array Assignment With A Loop

May 5, 2015

I have a 2 dimensional array assignment with a loop, i'm supposed find the average score of each student from a grade record and find the average score for each test. I've been trying to do the assignment all day with no progress. This is what i have so far

public class SiuTest {
public static void main(String[] args) {
String [] stu= new String [5];
int [] [] grade= new int [4][2];
String hold;

[code]....

View Replies View Related

Assignment To Create A Sphere Class

May 8, 2015

I have an assignment to create a Sphere class that will allow you to create Sphere objects using the code below. Then create a program called SphereTester that prompts the user for the radii of two spheres in meters. The program should display which sphere is larger and by how many cubic meters and display only four digits after the decimal point. I have the sphere class given to us for the assignment which is this:

public class Sphere {
// instance variable (i.e., a field)
private double radius;
// constructor for the Sphere class
public Sphere(double r) {
radius = r;

[code]....

Here is a sample run of what the final result should look like

Enter the radius of a sphere (in meters): 1
Enter the radius of a 2nd sphere (in meters): 2
Sphere 2 is greater than Sphere 1 by 29.3215 cubic meters

View Replies View Related

Average Score Assignment Using Netbeans

Sep 27, 2014

I've been working on this same assignment using netbeans. I've completed the exercise and when I run it, it works. However, netbeans still had errors listed in the left hand numerical column and it asks me if I still want to run the program with errors when I hit run?

package TestScores;
import java.util.Scanner;
// Name: Joe
// Date: ........
// Desc: Test Score Averages
 
[code].....

I found this thread while doing a google search trying to find out the error in my code.

View Replies View Related

Java Literal And Assignment To Different Primary Types

Jan 20, 2015

I thought numeric literal were by default int or doubles, depending on if have a . and numbers after the But I wrote a quick test program as listed below. I understand the float float floatA = 5.5; failed to compile since 5.5 is a literal of type double and you are trying to assign this to a floag

What I am having problems with is byte byteA = 5; 5 is a literal of type int and this is being assigned to a byte and compiler should complain.The compiler does not allow two byte values to be added and assigned to a byte since the result of the addition is an int

class literalTesting{
public static void main(String[] arg){
byte byteA = 5; // allowed WHY I thought literal is an int and assigning int to byte
byte byteB = 10; // allowed

[code]...

View Replies View Related

Stack Assignment - Give More Than One Option To Input

Sep 10, 2014

I understand the stack part of it, just not the loop, specifically how you give the user more than one option to input.

Implement a printer driver that handles incoming print jobs. The driver will behave in the following manner:

- Loop giving the user the following options: ADD print job, DELETE latest print job, and
QUIT
- Recording the following information from each job: computer name, document name, and
number of pages
- When the user chooses to ADD, add a new print job to the top of the stack
- When the user chooses to DELETE, pop off the latest print job and output to the screen
which job has just been deleted
- When the user chooses to QUIT, output the print jobs still in the stack (in order from top
to bottom)
- Output must include all relevant information for each job.

View Replies View Related

How Curly Braces Follow Assignment Statement

Apr 7, 2015

@Override
@SuppressWarnings("unchecked")
public TableCell<S, T> call(TableColumn<S, T> p) {
TableCell<S, T> cell = new TableCell<S, T>() {
@Override
public void updateItem(Object item, boolean empty) {
if (item == getItem()) {
return;
}

The line in the code above TableCell<S, T> cell = new TableCell<S, T>() {

I don't understand how curly braces follow an assignment statement?What does the line of code mean?

View Replies View Related

How To Write A Client Class To Test Methods For Assignment

Jan 20, 2014

Write a class encapsualting the concept of a course grade, assuming a course grade has the following attributes: a course name and a letter grade. Include a constructor, the accessor and mutator, and methods toString and equals.Write a client class to test all the methods in your class.

package labmodule7num57;
import java.util.*;
public class LabModule7Num57 {
// Constructors//

[code]....

View Replies View Related

Java Assignment To Get User Input And Display ZIP Codes And Populations

Oct 7, 2014

URL....So the problem is that when I type in "PA" it will display about 24 Zips and Populations before it stops. The problem is in the ZIPs file. It goes down the list and then takes the Zip from the Zips file to the Zips in the Population file and displays the Population. It will go to population 513 and stop. Reason being, there is no ZIP code in the Population file to display a population. The loop then stops. How can I get the program to skip over the zip code when there is no corresponding ZIP code in the other file and continue showing the other Pops..Here's what I currently have completed:

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Population {
//Declaring global variables.
Scanner fileScannerZip, fileScannerPop, inputFile;
private String lineZip, linePop;
int invalidZip;

[code]...

View Replies View Related

Difference In Variable Assignment Between Constructor And Variable Section

May 21, 2014

Given the case I have an object which is assigned only once. What is the difference in doing:

public class MyClass {
private MyObj obj = new MyObj("Hello world");

private MyClass(){}
//...
}

and

public class MyClass {
private MyObj obj;
private MyClass(){
obj = new MyObj("Hello world");
}
//...
}

Is there a difference in performance or usability? (Given also the case there are no static calls expected) ....

View Replies View Related

Accessing Objects From Other Packages

Dec 7, 2014

I have GameConsole class with gamePlay(). There are two objects in this class that I want to access from a class in another package.

package blackjackControls;
public class GameConsole {
Player dealer; //both of these objects I am trying to bring over into the blackjackGUI package
Deck playingDeck;
public void gamePlay(){

[code].....

The dealer and playingDeck objects are giving me an error of unresolved. the way it is written I also get a static error on line 37. I know that I have not yet written in the actionEvent statement in the button constructor.

View Replies View Related

Accessing ArrayList Of Another Class

Oct 19, 2014

What I want to do is this, this is my first class:

public class Footballer {
int goals;
String surname= "";
String team="";
private static int counter=0;
private int dres;
}

(this is just the header of the class... And this is my second class, which contains an ArrayList of the first class:

public class FootballTeam{
String teamname="";
String league="";
ArrayList<Footballer> f;
}

And this is my third class which contains an ArrayList of the second class:

public class FootballLeague{
String leaguename="";
ArrayList<FootballTeam> ft;
}

What I want to do is, know how many of footballers are there in the league? Meaning how many of "f"s are in the "ft"... I remember from C++ it was easy, you just did it something like this: ft.f[i]; (where i is a position), then you'd go through each of them, if you wanted to do something with them, or just ask for it's length, if you needed to know how much footballers are there.

I'm trying this method to get the size of the array in the 2nd class, from the 3rd class (containing an ArrayList of classes of 2nd class, but no luck:

int counter=0;
for(int i=0;i<this.ft.size();i++) {
counter+=this.ft[i].f.size();
}

I'm getting this: Array required, but ArrayList<FootballTeam> found ---

View Replies View Related

Accessing Data For Calculations?

Feb 18, 2015

I've created a method to calculate the ratio of one vowel to another, but I was hoping to get some feedback on another way I could approach the problem. The first bit of code is to find the vowels and assign them to an array ( for me, it seemed the easier thing to do in order to easily access the data). In the other bit of code, I have a method with two arguments (the vowels) to calculate the ratio.

public void findVowels(StringBuilder message, String delimiter) {
subString = message.toString().toLowerCase().split(delimiter);
vowelCounter = new int[5][subString.length];
// Remove all whitespace
for (int index = 0; index < subString.length; index++) {
subString[index] = subString[index].replaceAll("s", "");

[code]....

View Replies View Related

Applets :: Accessing HTML Through DOM

May 14, 2014

I do not think this is possible, but I'd like to confirm. If I have an HTML page that has an embedded Java applet, and that applet in turn renders an HTML document (within the applet window), is the HTML *within* the applet part of / accessible through the DOM for the parent page?

View Replies View Related

Accessing Objects Within GCompound?

Sep 19, 2014

Given the class MyExample below:

public class MyExample extends GCompound {
//instance variables
public GRect R1 = new GRect(0, 0, 20, 20);
public GRect R2 = new GRect(0, 0, 5, 5); //R2 is in front of R1, but its coordinates are all "inside" of R1's coordinates
//constructor
public MyExample() {
add(R1);
add(R2);
}
}

1) Suppose I'm in a GraphicsProgram and declare:

MyExample myex = new MyExample();

Suppose I have coordinates (x1, y1), and want to find out whether this is the myex object defined in the previous line. I would use:

obj = getElementAt(x, y);
if (obj == myex) (...and so on)

Now suppose I want to test whether the object is the GRect object R1 within myex. Why doesn't the following work?

if(obj ==myex.R1) (...and so on);

Here is the full code that shows my question; it outputs "myex", none of the other outputs come out...

public void run() {
GObject obj1, obj2;
MyExample myex = new MyExample();
add(myex);
obj1 = getElementAt(1, 1);
obj2 = getElementAt(19, 19);
if (obj1 == myex) System.out.println("myex");
if(obj1 == myex.R1) System.out.println("R1");
if(obj1 == myex.R2) System.out.println("R2");
if(obj2 == myex.R1) System.out.println("R11");
if(obj2 == myex.R2) System.out.println("R22");
}

View Replies View Related

Accessing Values From ArrayList

Nov 27, 2014

I'm a total newbie to Java, and until now all I've done was draw some shapes and flags. I'm struggling to understand the code I've been given. I need to access values stored in an ArrayList within another class. Here are the two classes Seat and Mandate:
 
package wtf2;
import java.util.*;
public class Seat {
public int index;
public String place;
public int electorate;

[Code] ....

The main class contains code that feeds data from 2 text files into Seat and Mandate. From there I managed to access the date in Seat (at the end):

package wtf2; 
import java.io.*;
import java.util.*;
public class CW2 {
public static void main(String[] args)throws Exception {

[Code] ....

Now,instead of getting just the mp for Edinburgh South I need to get the vote values, compare them to each other, take the second biggest and display the associate party value. How to access data from that Array to get started at least.

View Replies View Related

Accessing A Method From Another Class

Apr 1, 2014

I have an admin class that needs to access a method of another class and I'm unsure how to do it.

One of the methods in the admin class (DancerAdmin) accesses a .txt file with information in and each line is to be extracted and is to be created as an object of the Dancer class. The information in each line is to then be used to set the variables in the Dancer class.

To set the values the Dancer class has setter methods which I need to access each time a new object is created while cycling through the .txt file. I'm struggling to access these methods from the DancerAdmin class when I run the relevant method.

The snippet of code I have from the method in DancerAdmin is

while (bufferedScanner.hasNextLine()) {
currentLine = bufferedScanner.nextLine();
lineScanner = new Scanner(currentLine);
lineScanner.useDelimiter(",");
dancer.add(new Dancer());
Dancer.setName(lineScanner.next()); mh_sh_highlight_all('java');

I get an error saying non static method setName cannot be referenced from a static content?

View Replies View Related

Accessing JList Properties

Dec 18, 2014

I currently have some code using a JFrame. I am trying to access the items in a JList to save them in a TXT file. For this, I am using a "for" loop. The problem is, is that when I try to access the list items, I can't access them. The way I am trying to access the items is by using:

Java Code: listRight.getModel().getSize(); mh_sh_highlight_all('java');

BUT, I can't seem to get this to work. I tried to place this for loop everywhere and I can't access it. I tried accessing it under "public class Window", "private JFrame frmPcPartBuilder", "public static void main(String[] args)", "public void Initialize()" and I can't seem to access the JList. I basically have a save button that saves the list to a text file and the code I am trying to write is called by this button.

Java Code: package com.cooksys.assessment;
import java.awt.EventQueue;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JButton;

[code]....

View Replies View Related

Accessing HashMap With JSTL

Aug 18, 2014

I have a HashMap returned from the server. There are two conditions

1. HashMap returned with only one set of key value pair or

2. HashMap with multiple set of data key value pairs.

Now in UI I have to display either text box or drop down box depending upon the size of map for that I am using length method

Java Code:

<c:choose>
<c:when test="${fn:length(myDto.mayMapInDto) eq 1}">
display text box
</c:when>
<c:otherwise>
display drop box
</c:otherwise>
</c:choose> mh_sh_highlight_all('java');

I can display drop box by looping but not sure how I can get only one element for text box. Tricky is I can't use key value to access since UI don't know what key will be returned.

View Replies View Related

Accessing Keylistener From Thread

Mar 23, 2014

I start my thread, it's for a real basic game I'm learning. Everything was working fine, until I got to recognizing keys. It runs, and I can close using the mouse on the close command, but the keys aren't being generated from the keyboard. I copied it to a working sample, and here are the two files.

package testkeys;
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import javax.swing.JFrame;

[Code] ....

The idea was to set the return value to true if any key is pressed, thus quitting, for this short sample program. Problem, it never recognizes any keys pressed on the keyboard. New to java and threading.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved