hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : java - how to ask for a manual input in a mutator method call
Reply

Forum Jump

java - how to ask for a manual input in a mutator method call

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 02-23-2005, 10:13 AM
metronome metronome is offline
Junior Guru
 
Join Date: Aug 2004
Posts: 197

java - how to ask for a manual input in a mutator method call


This is the super class vehicle

Quote:
public class Vehicle
{
private String reg ;
private String type ;
private int maxLoad ;


public Vehicle(String registration)
{
reg = registration ;
}


public String getRegistration()
{
return reg;
}


public String getType()
{
return type;
}


public int getMaxLoad()
{
return maxLoad;
}


public void setType(String vehicleType)
{
if (vehicleType == "van") {maxLoad = 3500;}
if (vehicleType == "small van") {maxLoad = 500;}
if (vehicleType == "lorry") {setLoad(3000);}
type = vehicleType;
}

private void setLoad(int maximumLoad)
{
maxLoad = maximumLoad;
}




}

This is the lorry class that inherits from vehicle

Quote:

public class Lorry extends Vehicle
{
private boolean artic ;


public Lorry(String registration, boolean articulated)

{
super(registration);
setType("lorry");
artic = articulated ;
}


public boolean getArticulated()
{
return artic;
}
}
I'm trying to get it to ask for a manual input when it detects the string "lorry" for vehicle type as lorries can have individual maximum capacities where as vans have known capacities. The problem is that I can get it to setup for the known types but since a lorry has a determined for individual loads, I need to know how to call a method and ask for an input

the method im looking at is the setLoad method which is called from the setType method. Currently it is happy to accpet 3000 as an input but i want it to ask for an input instead.

if i just have it as

if (vehicleType == "lorry") {setLoad();}

then it gives me the following error

setLoad(int) in Vehicle cannot be applied to ()

note: I don't even know if this is the right way of doing it, I thought that you'd have to call a method to ask for an input rather then being able to request in the if statement

anyway many thanks for anyone who is able to help out


Last edited by metronome; 02-23-2005 at 10:20 AM.


Sponsored Links
  #2  
Old 02-25-2005, 12:54 PM
ilyash ilyash is offline
Web Hosting Master
 
Join Date: Dec 2002
Location: NY, NY
Posts: 3,975
you cant do (vehicleType == "lorry")

you must use the equals method

if(vehicleType.equals("lorry")){
// do stuff..
}

  #3  
Old 02-26-2005, 03:13 AM
MilesToGo MilesToGo is offline
Junior Guru Wannabe
 
Join Date: Aug 2004
Posts: 66
The way things work in Java is you need to call an existing method signature, or it won't compile. A method signature is the combination of the method name and the parameters it takes.

Java isn't going to automatically prompt the user for input when a method isn't passed in arguments.

To dynamically read input from the command line, you can use System.in, but it's not so simple as just calling it. Read this article for an example.

Sponsored Links
Reply

Related posts from TheWhir.com
Title Type Date Posted
Jelastic Integrates Java and PHP Cloud Platform with NetBeans IDE Web Hosting News 2013-05-06 13:34:29
Jelastic Expands to Finland via Partnership with Planeetta Internet Web Hosting News 2013-02-11 11:45:35
Web Hosting Jobs - New Hiring Methods for the New Year Blog 2012-12-13 12:08:55
Jelastic Releases Plugin for Java Development Environment IntelliJ IDEA Web Hosting News 2012-12-05 11:15:46
Jelastic Java Cloud App Deployment Gets Easier with Eclipse Partnership Web Hosting News 2012-12-17 13:50:32


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?