How to use get im different class?
Hello, I am new to this java. I need your help, please
I have Rental class that I use for my RentalApplication to run my Number of items rented & Total of Sale.
However it gives me 0 instead of the number. Where did I write wrong code?
public class Rental {
//Declare variables
public static final double COST_OF_NEW_RELEASES = 2.25;
public static final double COST_OF_REGULAR_VIDEO = 1.00;
public static final double COST_OF_DVDS = 2.98;
public static final double COST_OF_GAMES = 4.50;
private int NewReleases;
private int RegularVideo;
private int Dvds;
private int Games;
private Date timeOfSale;
private int customerNumber;
private String customerRental;
//Constructor method
public Rental(int theCustomerNumber) {
timeOfSale = new Date();
customerNumber = theCustomerNumber;
NewReleases = 0;
RegularVideo = 0;
Dvds = 0;
Games = 0;
System.out.println(customerRental = "\nCustomer Number " + customerNumber);
public Rental(
int theNumberOfNewReleases,
int theNumberOfRegularVideo,
int theNumberOfDvds,
int theNumberOfGames) {
this.NewReleases = theNumberOfNewReleases;
this.RegularVideo = theNumberOfRegularVideo;
this.Dvds = theNumberOfDvds;
this.Games = theNumberOfGames;
this.timeOfSale = new Date();
//Getters
public int getNumberOfNewReleases() {
return NewReleases;
public int getNumberOfRegularVideo() {
return RegularVideo;
public int getNumberOfDvds() {
return Dvds;
public int getNumberOfGames() {
return Games;
//Other Methods
public double rentalCost() {
* Rental Cost()
* creation date ("2/5/03" 1:30PM)
return NewReleases * COST_OF_NEW_RELEASES
+ RegularVideo * COST_OF_REGULAR_VIDEO
+ Dvds * COST_OF_DVDS
+ Games * COST_OF_GAMES;
public String getCustomerRental() {
return customerRental;
public int totalAmountRented() {
return NewReleases + RegularVideo + Dvds + Games;
public Date getTimeOfSale() {
return timeOfSale;
public String getFormatteddatetimeOfSale() {
DateFormat dateFormat = DateFormat.getDateInstance();
return dateFormat.format(timeOfSale);
public String getFormattedRentalCost() {
* rentalCost()
* creation date ("1/30/03" 1:30PM)
NumberFormat dollarFormat = NumberFormat.getCurrencyInstance();
return dollarFormat.format(rentalCost());
public String toString() {
String classDescription = "Thank You for renting";
classDescription += " ";
classDescription += "\nRental" + "[";
classDescription += "New Releases = ";
classDescription += NewReleases;
classDescription += ", Number of Regular Video = ";
classDescription += RegularVideo;
classDescription += ", Number of DVDs = ";
classDescription += Dvds;
classDescription += ", Number of Games = ";
classDescription += Games;
classDescription += "]" + ", \n[" + "Time of Sale = ";
classDescription += getFormatteddatetimeOfSale();
classDescription += ", Rental Cost = ";
classDescription += getFormattedRentalCost();
classDescription += "]";
return classDescription;
public static void main(String[] args) {
Rental theRental;
theRental = new Rental(3, 1, 3, 1);
System.out.println(theRental.toString());
* Method findRentalItems.
* @param thevideoId
* @return RentalItems
public static RentalItems findRentalItems(String thevideoId) {
return null;
This is my RentalApplication
public class RentalApplication
public static void main(String[] args)
Rental theRental;
RentalItems theRentalItems;
VideoStore theVideoStore = new VideoStore();
int customerNumber = 1;
boolean newCustomer = true;
boolean moreLookUps = true;
String thevideoId;
NumberFormat numberFormat = NumberFormat.getCurrencyInstance();
DateFormat dateFormat = DateFormat.getDateTimeInstance();
while (newCustomer)
theRental = new Rental(customerNumber);
while (moreLookUps)
thevideoId = JOptionPane.showInputDialog("Enter Video Id's");
theRentalItems = RentalItems.findRentalItems(thevideoId);
System.out.println(theRentalItems.displayRentalItems());
moreLookUps = getOption("Another Videos?");
theVideoStore.addRental(theRental);
System.out.println("Time of sale: "+ dateFormat.format(theRental.getTimeOfSale())
+ "\tNumber of items rented "
+ (theRental.totalAmountRented())
+ "\tTotal of Sale: "
+ numberFormat.format(
theRental.rentalCost()));
newCustomer = getOption("Another Customer");
moreLookUps = true;
customerNumber++;
System.out.println(theVideoStore.displayVideoStore());
System.exit(0);
public static int readInt(String prompt) {
return Integer.parseInt(JOptionPane.showInputDialog(prompt));
public static boolean getOption(String prompt) {
int theNum;
theNum = JOptionPane.showConfirmDialog(null, prompt);
return (theNum == 0);
In your RentalApplication main() method, you do the following:
theRental = new Rental(customerNumber);which calls the
public Rental(int theCustomerNumber)constructor.
In that constructor, you initialize
NewReleases = 0;
RegularVideo = 0;
Dvds = 0;
Games = 0;But nowhere do you ever adjust those values. So the reason you're getting 0 back, I believe, is because that's what you set them to.
Similar Messages
-
How do I get a different URL to show up after an email form has been submitted?
I have created a Form in DW CS5 and have some PHP server side code to mail it out.
However, once the Submit button is pressed it refreshes back to the Form - How do I get a different page to show up after the Form is submitted?
I tried using a behavior - onSubmit - go to URL - that gets me to the page I want to go to but I guess it overrides the PHP Form Action because the email will not send.
Any suggestions would be appreciated.Thank you for the response.
In my form - I have tried inserting a hidden field with the Value set to the redirected page I want to go to
<input type="hidden" name="MM_insert" value="http://www.website.com/page" />
In my form Action PHP Include - I have inserted a header function with the redirected page I want to go to
mail($to, $subject, $body, $headers);
header('http://www.website.com/page');
I have also checked for empty/extra spaces at the start and end of my php tags
None of the above has got me to the redirected page I want to go to after the submit button is selected - the Form page continues to refresh.
Any other suggestions on where I am missing the point would be greatly appreciated - thanks. -
How to use get getResourceAsStream
Gday all,
I gave up trying to comprehend the API doco and tutorials on the How to use get getResourceAsStream. I don't care how the class loader locates resources... I just it to work. Now!
Here's what works... and what doesn't work...
package krc.geometry;
import java.util.Properties;
import java.io.FileInputStream;
import java.io.IOException;
import krc.utilz.io.RuntimeIOException;
abstract class GeometryProperties {
private static Properties properties = new Properties();
static {
try {
// properties.load(new FileInputStream("c:/java/home/src/krc/geometry/Geometry.properties")); //WORKS
// properties.load(new FileInputStream("c:/java/home/classes/krc/geometry/Geometry.properties")); //WORKS
// properties.load( (new Object()).getClass().getResourceAsStream("krc/geometry/Geometry.properties")); //DOES NOT WORK
// properties.load( (new Object()).getClass().getResourceAsStream("krc.geometry.Geometry.properties")); //DOES NOT WORK
// properties.load( (new Object()).getClass().getResourceAsStream("Geometry.properties")); //DOES NOT WORK
// properties.load( (new Object()).getClass().getResourceAsStream("krc\\geometry\\Geometry.properties")); //DOES NOT WORK
properties.load( (new Object()).getClass().getResourceAsStream("/krc/geometry/Geometry.properties")); //WORKS
} catch(IOException e){
throw new RuntimeIOException("Failed to load GeometryProperties: " + e.getMessage());
static Properties get() {
return properties;
static String getProperty(String key) {
return properties.getProperty(key);
public static void main(String... args) {
System.out.println(GeometryProperties.getProperty("format.double"));
}I hope someone finds this helpful someday.
Some related links are:
http://java.sun.com/javase/6/docs/api/java/lang/Class.html#getResourceAsStream(java.lang.String)
http://java.sun.com/javase/6/docs/api/java/lang/ClassLoader.html#getSystemResourceAsStream(java.lang.String)
http://java.sun.com/javase/6/docs/api/java/lang/ClassLoader.html#getSystemClassLoader()
http://www.google.com.au/search?hl=en&q=getResourceAsStream+tutorial&meta=&btnG=Google+Search
http://rachel.sourceforge.net/tutorial.html
http://forum.java.sun.com/thread.jspa?threadID=5227823&messageID=9928698
PS: I think the API has ludicrously complicated explanation of something which can be explained succinctly by example... It's a classic case of a "correct" description which only makes sense once you already know how it works. Whomever wrote that one gets 3 out of 10 stars from me... ie No bananas.
Cheers. Keith.
Edited by: corlettk on Dec 2, 2007 9:28 AM - typos.I've noticed a good google hit rate on this forum, especially on threads with meaningful a subject lines... That's how I found these forums in the first place... I'm hoping that posting solutions and comments here (as well as the occasional question) will make them available to others from google... I doubt that any site I created would earn the same "front page" status as Sun's site.
Besides, doesn't it still cost money to setup a blog or your own homepage?
I admit I'm intrigued despite myself... I'm aware that both http://www.joelonsoftware.com/ and http://www.dreamincode.net/ (and problably many others) started as little personal blogs. -
I've downloaded Adobe acrobat standard Dc only to find out it's not compatible w/windows XP. How do I get a different version?
Hi vincelucy,
If you've purchased a previous version, you can download older installers from this page: Download Acrobat products | Standard, Pro | DC, XI, X (you'll need your serial number to complete the installation).
Best,
Sara -
How to Use JavaScript in Controller Class...
Hi All,
Can any one tell me how to use JavaScript in Controller Class.
Requirement is:
I have
Radio Group(RG1),
Two Radio Buttons(RB1,RB2),
Two messageTextInput(MTI1,MTI2),
if i click RB1 i should Prompt to the end user to "Enter value for MTI1" or
If i click RB2 i should prompt "Enter value for MTI2" while submitting page.
Please let me know the steps to use JavaScript and the above client validation...
Regards
Alem...Using javascript is against the standard. I can tell you a workaround instead of you setting the javascript, check if that would be acceptable.
You can use PPR and set the required property on the messageTextInput on clicking of the radio button. By doing this you will let UIX generate the javascript for you to handle the client side validation. But the validation will happen only on click of the submit button. The visual indicator is good enough to tell that the value has to be entered to the item. -
when I start a new tab yahoo search comes when I start a new tab yahoo search comes and I don't want that. how do I get a different web site to open?
You need to figure out what you have installed which changed that action to Yahoo from a blank tab, which is the default action in Firefox; and then get rid of that add-on. Then you can can install an add-on which allows you to select what you want in the new tab.
https://addons.mozilla.org/en-US/firefox/addon/newtaburl/ -
How can i get struts stub classes using struts_config.xml
Hi
Is there any tools to get Struts stub classes (i.e Action classes,Action Forms) using struts_config.xml?
if there, please provide the information about tools.Hi all,
We have HPROF functionality in our latest roadmap, so you will see that feature in our next major release called JRockit R28.
I recommend, above from the MemLeak documentation suggested by Makiey, the following information on how to use JRockit tools.
Performance Tuning & Profiling:
http://download.oracle.com/docs/cd/E13150_01/jrockit_jvm/jrockit/geninfo/diagnos/part_02.html
Using JRockit tools:
http://download.oracle.com/docs/cd/E13150_01/jrockit_jvm/jrockit/geninfo/diagnos/part_03.html
Diagnostics & Troubleshooting
http://download.oracle.com/docs/cd/E13150_01/jrockit_jvm/jrockit/geninfo/diagnos/part_04.html
Best Regards,
Tuva
JRockit PM -
Same parameter-map used on 2 different classes
Greetings,
If the same parameter-map (type connection or http) is used on two different policy-map classes, will that create a conflict in how traffic for each of serverfarms uses persistence or inactivity timeout (script 1)?
Should we create a different instance of parameter-maps for each policy-map class (script 2)?
Script 1
parameter-map type connection inactivity_2000
set timeout inactivity 2000
parameter-map type http persistence-rebalance
persistence-rebalance
policy-map multi-match L4_POLICY
class L3-4_VIP_A
connection advanced-options inactivity_2000
appl-parameter http advanced-options persistence-rebalance
loadbalance policy L7_Serverfarm_A_Policy
loadbalance vip inservice
loadbalance vip icmp-reply active
class L3-4_VIP_B
connection advanced-options inactivity_2000
appl-parameter http advanced-options persistence-rebalance
loadbalance policy L7_Serverfarm_B_Policy
loadbalance vip inservice
loadbalance vip icmp-reply active
Script 2
parameter-map type connection L3-4_VIP_A_connection
set timeout inactivity 2000
parameter-map type connection L3-4_VIP_B_connection
set timeout inactivity 2000
parameter-map type http L3-4_VIP_A_http
persistence-rebalance
parameter-map type http L3-4_VIP_B_http
persistence-rebalance
policy-map multi-match L4_POLICY
class L3-4_VIP_A
connection advanced-options L3-4_VIP_A_connection
appl-parameter http advanced-options L3-4_VIP_A_http
loadbalance policy L7_Serverfarm_A_Policy
loadbalance vip inservice
loadbalance vip icmp-reply active
class L3-4_VIP_B
connection advanced-options L3-4_VIP_B_connection
appl-parameter http advanced-options L3-4_VIP_B_http
loadbalance policy L7_Serverfarm_B_Policy
loadbalance vip inservice
loadbalance vip icmp-reply active
Thanksyou can reuse the same parameter map.
Gilles. -
How to use commit work in class cl_bls
Hi,
When i have used commit work after email sent,
it goes into dump.
Here is the code segment:
try.
-------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
-------- create and set document -------------------------------
pdf_content = cl_document_bcs=>xstring_to_solix( pdf_tab ).
document = cl_document_bcs=>create_document(
i_type = 'PDF'
i_hex = pdf_content
i_length = bytecount
i_subject = sub ). "#EC NOTEXT
add document object to send request
send_request->set_document( document ).
--------- add recipient (e-mail address) -----------------------
create recipient object
recipient = cl_cam_address_bcs=>create_internet_address( recip-recip ).
add recipient object to send request
send_request->add_recipient( recipient ).
---------- send document ---------------------------------------
sent_to_all = send_request->send( i_with_error_screen = 'X' ).
commit work.
if sent_to_all is initial.
message i500(sbcoms) with recip.
else.
message s022(so).
endif.
------------ exception handling ----------------------------------
replace this rudimentary exception handling with your own one !!!
catch cx_bcs into bcs_exception.
message i865(so) with bcs_exception->error_type.
endtry.
What could be the reason?
Is there any way to use commit work in class while sending email as in SO_NEW_DOCUMENT_ATT_SEND_API1 fm?
Thanks.Hi,
I have used
submit program.....
but in update task i have used it.
"Z_SD_ORDER_UPDATE". program is a print driver program.
However error says:
There is probably an error in the program
"Z_SD_ORDER_UPDATE".
This program is triggered in the update task. There, the
following ABAP/4 statements are not allowed:
- CALL SCREEN
- CALL DIALOG
- CALL TRANSACTION
- SUBMIT
I used submit as:
WAIT UP TO 2 SECONDS.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = ' '
AND RETURN.
Instead of submit i want to use commit work but i also get a dump after commit work too.
How can i use commit work in above code?
Thanks. -
How to Use Pattern and Matcher class.
HI Guys,
I am just trying to use Pattern and Matcher classes for my requirement.
My requirement is :- It should allow the numbers from 1-7 followed by a comma(,) again followed by the numbers from
1-7. For example:- 1,2,3,4,5 or 3,6,1 or 7,1,3 something like that.
But it should not allow 0,8 and 9. And also it should not allow any Alphabets and special characters except comma(,).
I have written some thing like..
Pattern p = Pattern.compile("([1-7])+([\\,])?([1-7])?");
Is there any problem with this pattern ??
Please help out..
I am new to pattern matching concept..
Thanks and regards
Sudheerok guys, this is how my code looks like..
class PatternTest
public static void main(String[] args)
System.out.println("Hello World!");
String input = args[0];
Pattern p = Pattern.compile("([1-7]{1},?)+");
Matcher m = p.matcher(input);
if(m.find()) {
System.out.println("Pattern Found");
} else {
System.out.println("Invalid pattern");
}if I enter 8,1,3 its accepting and saying Pattern Found..
Please correct me if I am wrong.
Actually this is the test code I am presenting here.. I original requirement is..I will be uploading an excel sheets containg 10 columns and n rows.
In one of my column, I need to test whether the data in that column is between 1-7 or not..If I get a value consisting of numbers other than 1-7..Then I should
display him the msg..
Thanks and regards
Sudheer -
HI . my wife wants to get her own Itunes account for her Iphone for music . righ now she is using my apple ID and can only access my Itunes account and password-- any ideas ?
thanks ,
jonHi jmb8989,
Welcome to the Support Communities!
Does your wife have an AppleID for her iCloud already? If so, she would use the same AppleID to sign in to the iTunes store. If not, here is the information to add or change and Apple ID:
Using your Apple ID for Apple services
http://support.apple.com/kb/HT4895
iOS: Changing the signed-in iTunes Store Apple ID account
http://support.apple.com/kb/HT1311?viewlocale=en_US
Frequently asked questions about Apple ID
http://support.apple.com/kb/HT5622?viewlocale=en_US
How do I get an Apple ID?
You may already have an Apple ID, and you only need one for everything you do with Apple. If you aren't sure, visit My Apple ID and click Find your Apple ID.
If you don't have an Apple ID, you can create one at My Apple ID. You can also create one by signing up for an Apple service (such as an iTunes Store or iCloud). You should use your primary email address as your Apple ID.
You do not need to create a separate Apple ID for each Apple service. A single Apple ID can be used to access all other Apple services.
I hope this information helps ....
Happy Holidays!
- Judy -
Firefox version 24.0 is not compatible with a website I frequent. I was told I need to use FIrefox 10.0 ,19.25 or Explorer 9.0 for the documents to be compatible. How do I download a different version of Firefox?
In what way is Firefox not compatible with that website?
Is that a problem with the user agent that is detected wrongly? -
How to use these method of class CL_GUI_PDFVIEWER
how to use these methods in the class CL_GUI_PDFVIEWER
1) CREATE_ANNOTATION
2) GET_ANNOTATION_INFO
3) SET_ANNOTATION_SETTINGSHi,
Refer
https://forums.sdn.sap.com/click.jspa?searchID=10926572&messageID=1803295
Regards
Kiran -
How to use get() method of hashmap in jsp
Hi,
Iam using hashMap in action form from which I want to retrieve the value by giving the key in jsp page.
ex: HashMap m = new HashMap();
m.add("key", "value");
String v = m.get("key");
I want to know how implement m.get("key") in jsp without doing iteration.
Thanks & Regards,
Nasrin.NHi
First of all I would say that there is no "add" method for Hashmap, its put
secondly try this
<bean:write property="map_key" name="mapSetterGetter" /> -
Hi,
I am trying to use Get-WebHandler , Get-Website in Powershell 2.0 version .It is throwing error as below
" Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to
the following error: 80040154 "
It is working fine in powershell 4.0 version but not working in powershell 2.0 version.Can anyone suggest solution to this.
Some IIS commands which are working fine in Powershell 4.0 , are throwing above error in Powershell 2.0 version . Please suggest me the best solution to fix this issuethis is a duplicate post. I suspected the same
http://social.technet.microsoft.com/Forums/windowsserver/en-US/87655dab-84ea-4e1d-8b43-b5c193f8702a/some-powershell-40-version-iis-commands-not-working-in-powershell-20-?forum=winserverpowershell#352bfa16-8c03-49fd-825c-89e3c150522b
Indeed yeah we need to import module
Regards Chen V [MCTS SharePoint 2010]
Maybe you are looking for
-
Why can't I access the featured page on the App Store anymore?
Since a while, I can not access the main page of the App Store anymore. Every time I tried to it just stays blank showing "iTunes Store" on top, sometimes with a notification popping up that there was an error and the request could not be completed o
-
Should I buy 865PE Neo2-LS???
I must say. Buying a motherboard sure is not what it used to be. It seems no matter where you look, or what company you look too there are issues on every board. The price of all this integration perhaps?? SO now my eye is on MSI. In paticular the ne
-
Withholding tax screen in AP Invoice
Hi, I have an issue in that with holding tax screen is not getting enabled in AP Invoice screen. All the values are getting calculated but I cant edit any of the values. Kindly your valuable views on this. Thanks in advance. Regards, Maheswaran.
-
Hi all In which table can i find these fields Bank data :Account RF05A--KONTO Open Item Selection : Account : RF05A--AGKON thanks
-
Problems loading web pages - Macbook Pro
Hi all, so this has been going on a lot recently and I have no idea why. Websites on my Macbook Pro are slow to very slow to load, and sometimes won't load at all. For instance, YouTube hasn't worked on my laptop for approximately 2 weeks. The sites