RetailItem Class Modify With Accessor Mutator

Apr 23, 2014

Here is what i have so far. The retaiItem class and the demo. Basically, my output looks like this:

Description:
Candy bar
Item Number: 17789
Wholesale Cost: $0.75
Retail Price: $1.50
new wholesale cost: 1.0
new retail price: 1.99

[Code] ....

package retailitemdemo;
public class RetailItemDemo {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {

[Code] .....

View Replies


ADVERTISEMENT

Sphere Class Using Accessor / Mutator Methods

Feb 25, 2014

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

[Code] ....

View Replies View Related

Creating Accessor And Mutator For Dual Array?

Apr 19, 2015

I am familiar with creating accessors and mutators, Any example of how to create them for dual arrays? I need the dual arrays to be int

View Replies View Related

Cash Register Class Used With RetailItem Class

Apr 27, 2014

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;

[Code] .....

View Replies View Related

Using Accessor Methods To Access Data From Another Class

May 6, 2014

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);

[Code].....

View Replies View Related

How To Modify Class File Inside JAR

Oct 28, 2014

I have to modify my ContainerImpl.java inside a .jar file. My modification is in here: [URL] but I do not know how can I modify it

View Replies View Related

Modify Class Time2 To Include Tick Method That Increments Time Stored In Object By One Second

Jul 9, 2014

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() );

[code]....

View Replies View Related

How To Use Mutator Method

Jul 31, 2014

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....

View Replies View Related

Using Mutator Method To Set Data To Array Element

Jun 2, 2014

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" .....

View Replies View Related

Modify Hub Code To Switch

May 26, 2014

I have a code for a Hub and I wanted to modify it to a Switch.. See the code below:

--- Update ---

package module.Hub;

import framework.Port;
import module.ModuleUI;
import java.lang.String;
import framework.Packet;

[code]....

View Replies View Related

How To Modify If Else Structure To Get Output

Nov 3, 2014

I'm having trouble with this program:

//********************************************************************
// 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?

View Replies View Related

Modify And Delete Functions

Apr 4, 2014

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

[Code] .....

View Replies View Related

Modify And Use A GUI To Set Variables Setter Methods

Feb 24, 2012

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.

1package de.kugihan.dictionaryformids.dictdconv;
2
3import java.io.FileOutputStream;
4import java.io.IOException;
5import java.io.OutputStreamWriter;
6

[code]....

View Replies View Related

Web Services :: Rest Modify Resource

Jan 20, 2015

"citizen":{"name":"John", "gender":"M","age":32}

Now, I only want to change age to 35, which method should I use and how should the payload/URL look like to be RESTful?

View Replies View Related

How To Modify Property Of Object Stored In List

Jul 31, 2014

I'm facing a problem in below scenario:

List lst = tDAO.executeReport();

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.

View Replies View Related

How To Grab Graphical Object From Arraylist And Modify It

Oct 26, 2014

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?

View Replies View Related

How To Modify Text So That It Doesn't Contain Two Equal Numbers

May 3, 2014

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 {
 
[Code] ....

View Replies View Related

How To Modify And Delete Data From Array List In Netbeans

May 22, 2014

How to modify and delete data from a array list in net-beans?

View Replies View Related

Exception Handling - Block Cannot Modify Primitive Values

Sep 23, 2014

class MultipleReturn {
int getInt() {
int returnVal = 10;
try {
String[] students = {"Harry", "Paul"};
//System.out.println(students[5]); //if i remove comment

[Code] .....

View Replies View Related

Inventory Program - Add / Delete / Modify / Search And Save

Feb 15, 2015

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.

My full code is:

import javax.swing.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.awt.event.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

[Code] ....

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.

View Replies View Related

Modify Internal Object Structure Using Any Design Pattern

Mar 31, 2014

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.

View Replies View Related

How To Modify Site Exception List In Java Control Panel

Apr 2, 2014

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.

View Replies View Related

Modify DrawShape Method To Calculate Distance From Starting Point

Mar 13, 2015

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;

[code]....

View Replies View Related

Modify Or Read Http Message Before Sending To Server Within Client

Feb 25, 2014

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.

View Replies View Related

Modify Common Object References In Lists - MyArrList And UrArrList

Jan 29, 2014

"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");

[code]....

View Replies View Related

Modify Values In Fields In Serializable Object Using Objects Set Methods Java

Dec 10, 2014

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

[Code] .....

This is the error message:

----jGRASP exec: java ItemRecordReport

Item Cost Quantity Description
Number
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
Exception in thread "main" java.lang.NullPointerException
at ItemRecordReport.main(ItemRecordReport.java:161)

----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

View Replies View Related







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