Help A Java Newbie With This Simple Java Program - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Help A Java Newbie With This Simple Java Program (1564 Views)
| Help A Java Newbie With This Simple Java Program by halmat(op): 12:00am On Sep 30, 2015*. Modified: 12:16am On Sep 30, 2015 |
Hi everyone, I'm a newbie to programming trying to build some skills around Java. I encountered an exercise in Dietel's Java how to program book. It's requesting to make an invoice program for a hardware store with constructors, get and set methods, and also calculate the total of the purchase on the invoice with quantity * price. I tried my way around it and come up with these two classes. I'm now stock at an error saying partQuantity: an instance of type int cannot be returned by a method 'Java.lang.String' Please help me out with this, I really don't know what next to do. Here are the two classes for the program. public class NewInvoicevoiceAnd here is its Test class import java.util.Scanner;Thanks in anticipation. |
| Re: Help A Java Newbie With This Simple Java Program by FincoApps(m): 2:26am On Sep 30, 2015 |
halmat:First of all, your class and constructor name must be the same. Your class name is NewInvoicevoice and the constructor is NewInvoice(). So rename the class to NewInvoice() halmat:Secondly, the getQuantity() method has a return type of String, however you are returning partQuantity which has a datatype of int. So to fix this, replace "return partQuantity" with "return String.valueOf(partQuantity)" |
| Re: Help A Java Newbie With This Simple Java Program by yungcheda(m): 7:16am On Sep 30, 2015 |
1. Your constructor name and class names have to match 2. Why are you using constructors to set instance variables and still using set method again?? They playing the same roles in a way... 3. Your partQuantity is supposed to return an int type but you put the return type as String. Change the String to int. This exact one is what is causing the error Goodluck |
| Re: Help A Java Newbie With This Simple Java Program by fattbabakay(m): 11:14am On Sep 30, 2015 |
yungcheda:Osheyyyy baddest... |
| Re: Help A Java Newbie With This Simple Java Program by halmat(op): 1:48pm On Sep 30, 2015 |
Thank you all, I really appreciate your efforts. I now got the compiler error out. Although the program is yet to function as I wish, I'm currently battling with it and will post the final code that receive input and print the entered value back to the user. |
| Re: Help A Java Newbie With This Simple Java Program by Nobody: 3:52pm On Sep 30, 2015 |
use quick fix |
| Re: Help A Java Newbie With This Simple Java Program by halmat(op): 7:40pm On Sep 30, 2015 |
Thanks everyone, and here is my final code: public class NewInvoiceAnd its Test class import java.util.Scanner; |
| Re: Help A Java Newbie With This Simple Java Program by FincoApps(m): 7:42pm On Sep 30, 2015 |
| Re: Help A Java Newbie With This Simple Java Program by halmat(op): 7:55pm On Sep 30, 2015*. Modified: 8:59pm On Sep 30, 2015 |
FincoApps:Please elaborate more on quick fix |
| Re: Help A Java Newbie With This Simple Java Program by halmat(op): 7:56pm On Sep 30, 2015 |
FincoApps:Thanks sir. |
| Re: Help A Java Newbie With This Simple Java Program by halmat(op): 8:56pm On Sep 30, 2015 |
FincoApps:Thanks sir |
| Re: Help A Java Newbie With This Simple Java Program by FredSteel: 1:00pm On Nov 07, 2024 |
When deciding between .net vs java, .NET offers excellent performance and security, especially for enterprise applications. Java, however, provides flexibility with its cross-platform capabilities, making it ideal for global applications. Both technologies allow companies to build scalable, secure, and efficient software solutions tailored to their needs. |
Simple Java Calculator Code. • Simple Java Challenge • Java Program To Solve Quadratic Equation-dealwap • 2 • 3 • 4
Help!!! I Formatted My HDD Without Backup, How May I Recover Formatted Files? • 19 Tips For Programmers/software Engineers In 2019 • Comprehensive Study Guide For Data Science : Learn In 9 Months For Free
