Java Project - UPC Calculator / Calling ToString Method?

Feb 20, 2014

Our goal is to write a pretty simple program, one that takes the 12 digit UPC code entered by a user and to not only spit it back out in a format with dashes using toString, and also returns the first digit, a 2 more groups of digits numbering 2-6 and 7-11, and finally display the 12th digit. It then performs an equation to check the last digit and make sure the UPC code is correct.

However, being so new to java (I only learned visual basic before), with this I was introduced to two new concepts that for some reason I simply cannot grasp for the life of me: Using and calling the toString method, and calling on methods that are created in a completely different class file.

The first section of code is my UPC class, which is meant to contain all my methods as well as the toString to be called on:

public class UPC
{
// Instance variables
private int itemType; // digit 1
private int manufacturer; // digits 2,3,4,5,6
private int product; // digits 7,8,9,10,11
private int checkDigit; // digit 12

[Code] .....

View Replies


ADVERTISEMENT

Overriding Java ToString Method For Web Browser

Mar 14, 2014

How do i print override the toString for WebBrowser as i would like to print out the object bc. Tested the program and it is fine if i put it in the main method rather than the WebBrowser constructor.

import java.util.*;
class ListNode <E> { /* data attributes */
private E element;
private ListNode <E> next;
/* constructors */
public ListNode(E item)
{ this(item, null);

[code]...

View Replies View Related

PostFix Calculator Project?

Apr 2, 2015

So I am working on a PostFix calculator that is used in command line for a class project, and I am having a little trouble on developing a memory for it. I have been told to create a hashMap and I have researched it and understand the basics of it. I have the calculating method working, but what I am having trouble trying to implement a way for the user to declare variables. For example this what the user should be able to do:

> a = 3 5 + 1 -
7
> bee = a 3 *
21
> a bee +
28

[code]....

I just need to be able to save the answers as a variable the User names, such as the example and let the user be able to use the variables later.

View Replies View Related

JSP :: Calling Java Method Error

Apr 13, 2014

I have a JSP page that calls a Java method .. using GlassFish 4.0 it worked just fine, now I'm trying to run it on a new server with Tomcat 6.0 but it keeps giving me this error: "the function result must be used with a prefix when a default namespace is not specified"

Here's my JSP page:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
......
<jsp:useBean id="diskUtilData" scope="request" class="newpackage.ResultPage" />
.....
<c:forEach var="celldata" items="${diskUtilData.result()}">

[Code].....

View Replies View Related

Calling Method From DLL In Java Code

Mar 6, 2015

I need to access a method from a dll in java as below and is giving an error

"Exception in thread "main" java.lang.UnsatisfiedLinkError: Testdll.Decrypt(Ljava/lang/StringLjava/lang/String;
at Testdll.Decrypt(Native Method)
at Testdll.main(Testdll.java:31)
"
I have included the jna-4.0.0.jar and the HashMatchCryptography.dll to the project in eclipe and the java-library-path has the path for the lib

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.NativeLong;
import com.sun.jna.Platform;
import com.sun.jna.*;
import java.lang.*;

[code]...

View Replies View Related

ToString Method Won't Work

Oct 4, 2014

So I'm working on a project and noticed that my toString() method won't work. This is just an example of the type of code that I have in my real project. THIS IS MY MAIN CLASS

XML Code:

package trialanderror;
import java.util.Scanner;
public class TrialAndError {
public static void main(String[] args) {
Scanner keys = new Scanner(System.in);
String name;
String phonenumber;

[code]....

View Replies View Related

How To Overwrite A ToString Method

Apr 12, 2012

How to overwrite a toString method

View Replies View Related

JAVA Calculator - Equals Method To Return Appropriate Value Using Standard Arithmetic

Apr 18, 2014

I am having trouble using the equals method to return the appropriate value using standard arithmetic.

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

[Code] ....

I know that "inText.setText(Integer.toString(secondOperand));" in the code is wrong, I just don't know the right code...

View Replies View Related

Outputting 2 Classes - ToString Method

Apr 22, 2014

My current assignment involves me outputting these 2 classes. Yet I'm not really sure in what manner I should go about doing this. I have tried creating a separate class and outputting my toString methods there but for some reason I am getting an error. .

The error message is thus;

Exception in thread "main" java.lang.NullPointerException
at Vehicle.toString(Vehicle.java:91)
at Run.main(Run.java:17)
 Process completed.

import java.util.Calendar;
public class HireContract {
String reference;
Calendar startDate = null;
Calendar endDate = null;
Vehicle vehicle = null;;
String customerRef;
double rate;

[Code] .....

View Replies View Related

Each Class Should Override The ToString Method

Nov 10, 2014

Write TestCabAppointment,java class where you will instantiate new CabAppointment objects and read data from RandomAccessFile and create CabAppointment objects and save them in RandomAccessFile You may use FixedLengthStringIO,java class, ICabAppointmentRecord.java interface. Complete the ReadWriteRandomAccessFile.java

CabAppointment.java (this class extends Appointment class)
private int id;
private Address startAddress;
private Address destinationAddress;
private String terminal;
private String description;

[Code].....

View Replies View Related

How To Pass A Loop In Method String ToString

Apr 7, 2014

I am looking to pass a long list of results in a String toString() method,this is my code

public void newlist(){
for(int i = 0 ; i <= nbComposant;i++){
System.out.print(ref+i+" (quantity "+quantity+i+")");
}
}
public String toString(){
return newlist();
}

View Replies View Related

Linked List Queue ToString Method

Oct 21, 2014

So I have to write all the methods for a LinkedListQueue. I've got isEmpty, enqueue and dequeue working correctly (I think) but I'm having trouble with the toString method. I tried to do it recursively and it works if there is only one element in the list, but with multiple elements it throws a StackOverflowerror exception. I've tried it multiple different ways, but I can't seem to figure out how to print it out with out clearing everything. We haven't been taught StringBuilder or .append yet, which I saw a lot of as I was looking for solutions, so I can't use those.

public class LinkedQueue<T>
{
protected LLNode<T> front; // reference to the front of this queue
protected LLNode<T> rear; // reference to the rear of this queue
private T info;
public LinkedQueue()
{
front = null;
rear = null;

[Code] ....

and this is the ITD used with it, for some reason it has the "empty the queue" function as a choice but we weren't assigned that function, so just ignore it.

import java.util.Scanner;
public class ITDLinkedQueue
{
public static void displayMenu()
{
System.out.println("(1) display menu");
System.out.println("(2) check isEmpty");
System.out.println("(3) enqueue");
System.out.println("(4) dequeue");

[Code] ....

View Replies View Related

How To Test And Finish ToString And Equals Method In Code

Jan 19, 2014

Write a class encapsulating 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.

how to test and finish the toString and equals method in this code ?

package labmodule7num57;
import java.util.*;
public class LabModule7Num57 {
// Constructors//
private String name;
private String letterGrade;
public LabModule7Num57 (String name,String letterGrade) {

[code]....

View Replies View Related

ToString Method Return A String Rather Than Display A Message To Screen

Aug 11, 2014

I need making the toString() method return a String rather than display a message to the screen. Also, I'm not supposed to call the toString method in my demo class to test it, so what should I do instead?

public class cupDispenser {
String location;
int noOfCups;
cupDispenser(String location,int cups)
{
this.location=location;
this.noOfCups=cups;
}
public String getlocation()

[Code]...

View Replies View Related

Calling Private Method To Another Method Located In Same Class

Oct 23, 2014

I am trying to call a private method to another method that are located in the same class.

I am trying to call prepareString to the encode method below.

Java Code:

public class ShiftEncoderDecoder
private String prepareString(String plainText)
{
String preparedString = "";
for(int i = 0 ; i < plainText.length();i++)
if(Character.isAlphabetic(plainText.charAt(i)))

[Code] .....

View Replies View Related

Calling A Method From Main

Jan 26, 2014

The idea is to create a program to add plants and retrieve plants from a Nursery. I created a class with the properties of the plants and also there is the class an Array list to keep track of the plants entered ( they will have to be printed later) (I am not too sure if adding a public class there is the best option.

The program will allow the user to pick and action and from there the code will do something. I don't want to have all the code inside 'main' The problem is in line 114.This is what I have so far.

Java Code:

package plant.nursery;
import java.util.ArrayList;
import java.util.Scanner;
/**Class to create a plant for a nursery.
public class PlantNursery

[code]....

View Replies View Related

Calling A String To Another Method

Oct 23, 2014

I need to get the string encodedString from the method encode able to be used in the decode method.

Java Code:

public String encode(String plainText) {
int prepareString;
int shiftChar;
String preparedString2 = prepareString(plainText);
String encodedString = "";
for(int c = 0 ; c < preparedString2.length();c++)

[Code] ....

View Replies View Related

Calling A Method With Timeout

Aug 8, 2014

I have a line code like this one:

String result = someHeavyMethod();

and I need to add this logic: "if the method doesn't finish within 10 seconds, cancel it and let me continue with the rest of the program".

View Replies View Related

Calling Method Into Applet

Apr 8, 2014

I need to create an applet that displays a grid of command buttons which I have done. I then need to create a new class that draws a silly picture of an alien, which I have also done. Where I am completely stuck and confused, is that I do not know how to get the drawing into the applet. My code is below. I really do not fully understand why this is not working or how to get it working.

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MartianGame extends JApplet implements ActionListener {
DrawMartian aMartian = new DrawMartian();
DrawJupiterian aJupiterian = new DrawJupiterian();

[Code] .....

View Replies View Related

Calling Method From Within A Class

Sep 15, 2014

I am calling a method from within a class like so:

xmlWriter.updateFile(environment, doc);

The class is xmlWriter & the method is updateFile

updateFile passes Environment environment (another class) and Document doc (document builder)

but I am unsure about it passing these through the parameters in the method call..is it correct?

Also underneath that method call for the update could I then do another method call for the export method of the file?

View Replies View Related

Calling A Method From Another Class

Mar 24, 2014

I am having problem to call a method from another class using arrays. I already know how to call a method without using arrays but I am not sure how to pass parameters to the main method using arrays. I'd really appreciate any feedback or comments!This is what I have so far.

public class Customer123 {
public static void main(String [] args){
Scanner input = new Scanner(System.in);
int x;
System.out.print("Total number of customers: ");
x = input.nextInt();

[code]....

View Replies View Related

Calling A Method To Main

Nov 17, 2014

I'm trying to call a method to my main method, but I can't seem to get it to work and it keeps resulting in a compile error.

import java.io.*;
import java.awt.Point;
import java.text.DecimalFormat;
import java.util.Random;
public class Chase {
public static void main(String args[]){

[Code] .....

View Replies View Related

Calling A Method To The Main

Sep 10, 2014

I have been reading about methods and I do have a beginner level understanding on how they work. I was trying to mess around and make a dog calculator using methods. I ran into a small snag; I cannot get the method to call to the main or the program to compile correctly. The first code below is the original. To me it looks like (based off of some examples I looked at) there should be no problems, but NetBeans gives me a few errors. 1) line 8- "cannot find symbol, variable dogYearCalc; 2) line 18 illegal start of expression; and 3) line 22 - unreachable statement.

import javax.swing.JOptionPane;
public class KrisExample {
public static void main (String[] args) {
double dogYears = 0;
JOptionPane.showInputDialog (null,"Please enter you dog's age in human years:");

[Code] ....

Someone told me that I was calling dogYearCalc without any arguments in your main method. I take that to mean that I needed to add it to the main, so I did here:

public static void main (String[] args, double dogYearCalc) {

That got rid of my first error, but then when I tried to run the program NetBeans said that I have no main class, so switched back to the original program above.

I thought that when I calling the dogYearCalc method on line 10 was the whole purpose of using a method. It seems to me that putting it somewhere in the main is counter productive.

View Replies View Related

Calling A Method From One Class To Another

Mar 6, 2015

calling a method from one class to another.I have two classes. One called Vacation and another called VacationDriver.I am trying to input an int for addVac and have the value update to the numSold within the updateSales() method in Vacation. From there it should update and display in the v1.toString in the VacationDriver.

Vacation
import java.text.NumberFormat;
public class Vacation {
private String vacationName;
private int numSold;
private double priceEach;

[code]...

View Replies View Related

Calling A Method On Object From Another Class?

Oct 27, 2014

I have a class for employees. This class has basic information for the employee but no real pay information. And 2 subclasses, one for employee's paid for hourly rates and one for those paid a yearly salary. Each subclass has their own pay() method, that calculates and returns their pay and extra fields relative to calculate that.

I'm just curious, if I do this and create an object for an hourly paid employee like so:

Object hourly1 = new HourlyEmployeeWilson("John Doe", "123 Tech Street",361961,"Human Resources", 0,12.50,50);

How can I utilize that classes public method of pay() to gather this instance (or hourly paid employee)'s pay? I've tried doing so via:

System.out.println(hourly1.pay());

But I get

DriverPayWilson.java:9: error: cannot find symbol
System.out.println(hourly1.pay());
^
symbol: method pay()
location: variable hourly1 of type Object
1 error

View Replies View Related

Recall Main Method After Calling Of JVM?

Jul 28, 2014

Can we recall the main method? I'm trying a code to recall main method (after the calling of JVM). I know this doesn't make any sense but I'm trying this just like that.

Code:

class derived {
public static void main(String args[]) {
System.out.println("Main Method class");
show();
}
static void show()

[code]....

View Replies View Related







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