So I've been working on this sphere class forever and have tried rewriting it a number of times. each time i change something i get a different error...
Instructions: create a sphere class with the following properties:
private attributes: x, y, z coordinates of center, and the radius.
Accessor and mutator methods to: set and get the x,y,z coordinates, set and get the radius, get the volume and surface area of the sphere.
This is the main sphere class:
Java Code:
package spheretester; <pre class="brush:java;"> */ import java.io.*; import java.util.Scanner; public class Sphere { public static void main(String[] argv) throws Exception
So I have to make a cash register class that can be used with a RetailItem class that I did in another assignment. It should simulate the sale of an item. It should have a constructor that accepts a RetailItem object as an argument, and the constructor should also accept an integer that represents the quantity of the items being purchased.
I have no errors but here is the output I am getting:
How many candy bars are you buying? 5 Subtotal : $0.00 Sales tax : $0.06 Total : $0.06 BUILD SUCCESSFUL (total time: 3 seconds)
The code I have so far below:
CashRegister Class package cashregisterdemo; public class CashRegister { private RetailItem retailItem; private int quantityItems; private final double SALES_TAX = .06; private int subTotal;
I have been asked to write a program with 3 classes(an interface, a store and a product class) and I have been going ok until I need to display data on the interface that is held in the product class. At the moment the code will compile fine but when I run the program and try to use the writeOutput() method I get a stack overflow error.
I realise now that it is because of a non-terminating recursive call, however I can not think of a solution on how to fix the problem. And just to clarify, what I am aiming to do is have the MatesTerminal class display the data for name that is stored in the Product class(I have no way of determining which product to display at this time, so I would like to be able to display the data for all three products if possible). Anyway this is what I have so far:
The method from the MatesTerminal Class:
private void writeOutput() { int productChoice; Scanner console = new Scanner(System.in);
Modify class Time2 to include a tick method that increments the time stored in a Time2 object by one second. Provide method incrementMinute to increment the minute and method incrementHour to increment the hour. The Time2 object should always remain
a) incrementing into the next minute,
b) incrementing into the next hour and
c) incrementing into the next day (i.e., 11:59:59 PM to 12:00:00 AM).
how to manage case 4 stuff and what's the problem of this CODE.
import java.util.Scanner; public class Time2Test { public static void main( String args[] ) { Scanner input = new Scanner( System.in ); Time2 time = new Time2(); // input System.out.println( "Enter the time" ); System.out.print( "Hours: " ); time.setHour( input.nextInt() );
So I am doing exercises from my book and I am stuck for nth time. I have problems understanding the exercises from this chapter, this one as well... Add the following method to the Stock class:
public void clear() Resets this Stock’s number of shares purchased and total cost to 0.
So I did this : public void clear(){ this.totalShares = 0; this.totalCost = 0.0;
My problem is I don't know where and how to use it in my code and what result should I look for.Here is a pastebin with the Stock class URL....
the problem I'm having is I want to use a mutator method to set data for an array element. The code I have so far is:
public void addProduct(String productName) //Goes through and sets the name of a product and assigns it to the array { int index; for (index = 0; index < product.length(); index++) { product[index].setName(productName); numberOfProducts++; } }
The array was initialised like this:
Product[] product = new Product[3];
And the setName(String) method is just your typical mutator method.However, in Eclipse, I have an error messages. It is:
"-The method setName(String[]) is undefined for the type String" .....
//******************************************************************** // Demonstrates the existence of separate data space in multiple instantiations of a programmer-defined class. //********************************************************************
[code]....
Basically i'm trying to add one more "coin" to flip. My problem is that my if-else structure isn't working correctly here's what it looks like:
if (count1 < GOAL) if (count2 < GOAL) System.out.println("Coin 3 Wins!");
[Code] .....
It only works correctly when "coin2" wins.How would I modify my if else structure to get the output I am looking for?
I am writing a program for my Java class and I have every function of the program working aside from the modify and delete button. I'm not sure how to make them work. The course material doesn't cover these functions at all.
Here is what I have so far.. which is practically nothing. If I need to post any other code I will, I just don't want to post more than needed because going through unnecessary code can waste time.
public void actionPerformed(ActionEvent e) { inventoryTotalField.setText(String.valueOf(genre[ArrayIndex].getInventoryTotal())); //add button functions if (e.getActionCommand() == "First")//if first button is clicked { ArrayIndex = 0;//set array index to the first element in the array setFieldValues(); // display dvd info on the form
i'm trying to modify and use a GUI to set the variables the setter methods. while the code seems valid to me and should work perfectly, i get ArrayIndexOutOfBounds and StringIndexOutOfBounds and respectively lines 111 and 134. i'm am not the original author of this code, all i want is to get it to work fine.
lst contains list of objects and one of the objects contains the property bDate(Timestamp) which has the value 28-2-1989 00:00:00.0, now I just wants to change the value into 28-2-1989 and store it back into the List as a Timestamp. how can I do that.
I am trying to grab a graphical object from an arraylist, and reposition its coordinates on a Jframe when adding it. My program of course deals with strings, and once it sees specific words in my console, some method is called that adds, removes, or otherwises modifies certain objects on screen.
Here I want to say something like move(object[1],xpos,ypos) which will move a certain object from a specified point in the array, and move it to new x and y positions on the JFrame. I use a different class that extends a graphics program, so when I say add(something,x,y) it draws the object onscreen where I want it. These are some relevant, though incomplete, methods that should move an object already painted on screen:
Console class
Java Code:
public void doMoveCommand(String cmd, String arg, String xpos, String ypos) { int x = Integer.parseInt(xpos); int y = Integer.parseInt(ypos); if (cmd.equals("posMake") && arg.equals("star")) { box.moveStar(box.historyG.get(1), x, y); //historyG is an arraylist of GPolygons freeCommand();
[Code] ....
When I say makepos(whatever) I am getting a arraylist out of bounds exception. How I might be able to accomplish moving objects already on screen?
I would like to create a program that takes some files and modifies them in this way: The files should contain text formatted in this way:
############## #various comments# ############## something{ identifier=1234 anotherIdentifier=1235 anotherOne=12345 //and so on... }//I need only this
#Comments are sometimes made this way
somethingAgain{ #comments that explains what's below them I:dentifier:something, I, do, not, need #see ^that A:notherIdentifier:boolean //and so on.. }
And I have to make so that the numbers contained in something{} in all the files don't match. I could ask to make so that the input file is only one, and it is formatted this way:
identifier=1234 anotherIdentifier=1235 anotherOne=12345 //and so on...
but I don't know how to do the rest of the program... That's what I've done (the names of the classes, package etc. are in Italian and there's some useless code that NetBeans prevents me from deleting):
package confronto; import java.awt.Color; import java.io.*; import javax.swing.*; public class confrontoTesti extends javax.swing.JFrame {
class MultipleReturn { int getInt() { int returnVal = 10; try { String[] students = {"Harry", "Paul"}; //System.out.println(students[5]); //if i remove comment
The goal was to add a few buttons an add delete modify search and save. I feel like I have the entire need satisfied. I'm having a few symbol problems which I'm not quite sure how to fix.
which is directing me towards Prodname on the far right of the if statement. I'm not sure what the problem is. I've double checked my spellings several time for each spot and I cant quite get it.
Everyone has told me but I am aware that I made some bad decisions with the variables being capitalized this was my first go at a program and my instructor didn't let me know that thats the normal way to do it.
I have a design scenario here which is quite interesting and complex. I have a Java class structure as follows,
class A { class B; innerClass B { List<class C> listofC; innerClass C { String attribute1; String attribute2; // Their getter setters } } }
So I have this as an API. Now my challenge is that I need to add one more property to inner class C. i.e attribute3 in innerClass C. I need to do this without disturbing the code in class A by extending these classes or writing a new wrapper, so I can use class C with new properties .
I hope this should be achievable through any design pattern either at runtime or design time.
When I am watching scjp mock test, I am getting error about security.
I am trying to add www.javaranch.com to site exception list in java control panel. I can see security tab in java control panel, there I find field for Site Exception List. When I am add [URL] .... to this site exception list, list is not getting populated.
Why is that ? Why am I unable to add this site to list ?
I am using 64-bit system and have downloaded and installed 64 bit update patch 51.
I need to modify the drawShape method to calculate the distance from the starting point (the diameter) of any shape regardless of how many sides I give it, but I have absolutely no clue where to begin with this. The ultimate goal of the program is to calculate the value of pi using the shape that is drawn.
Java Code:
public class PiTurtle extends Turtle { private double mySize; private int mySides; private double diameter = 0;
I am trying to check the integrity in a Bank Transaction that the message sent to the server has not been modified by any malware in the client system. For this I am trying to read the message sent to the server at the client boundary so as that it enters the network as customer with customer intended values. So, firstly I need to check where to I need intercept the message within client boundary. Secondly, Can I intercept the message and read its contents using Java?
I want to check what my Online Banking Server( Leta Say Bank of America) receives if I ask to transfer amount $100 to Account A . I assume that there is a malware in client system that changes recipient to B,$10000. My aplicaion which I intend to design, shoudl inform the user that the integrity of the message is compromised and should give the option to the user to abort it. plan to track what message is being sent from client to server. This I want to achieve by reading the message from client at the last point before it leaves the client and enter the network.
"What happens if you modify the common object references in these lists, myArrList and urArrList ? We have 2 cases here: In the first one, you reassign the object reference using either of the lists. In this case, the value in the second list will remain unchanged.In the second case, you modify the internals of any of the common list elements - in this case, the change will be reflected in both lists."
I have written the following code, which tests the first case mentioned above, and i get the output as expected: myarrList remains unchanged. How can i test the second case ? My thoughts are ....'second case is untestable the following code, because String is immutable. I need to use StringBuilder or something else to write code for test of second case mentioned'.
ArrayList<String> myarrList = new ArrayList<>(); myarrList.add("one"); myarrList.add("two"); ArrayList<String> urarrList = new ArrayList<>(); urarrList.add("three"); urarrList.add("four"); System.out.println("ArrayLists setup");
This program is basically complete. It compiles and runs. It is a college course assignment that I pretty much completed but for the last part in which I'm suppose to change the values of all fields and display the modified values using a toString method. Modifying the values of the fields is where I am stuck. I don't think I need to create a new text data file to do this. The instructor only asked that all the values of fields be changed and this was the last part of the assignment so I don't think it involves creating additional ObjectOutputStream and ObjectInputStream objects. I'm getting a NullPointerException error on line 161.Here is the code. I'm also including the input data file.
//create program so that objects of class can be serialized, implements interface Serialiable //create constructor with 4 parameters with accompanying get and set methods, Override toString method //create text file with 5 records, create Scanner object,ObjectOutputStream, and ObjectInputStream //create new ItemRecord object, change values of all fields in ItemRecord object using object's set methods //modify ItemRecord object using toString method
[hightlight =Java]import java.io.Serializable; public class ItemRecord implements Serializable
----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete.
Here is the data file: A100 99.99 10 Canon PowerShot-135 A200 149.99 50 Panasonic-Lumix T55 A300 349.99 20 Nikon- D3200 DSRL A400 280.99 30 Sony- DSC-W800 A500 97.99 20 Samsung- WB35F
Here is the data file for the modified field values. B100 98.00 10 ABC1010 B200 97.00 15 DEF1020 B300 96.00 10 GHI1030 B400 95.00 05 JKL1040 B500 94.00 01 MNO1050