- In the extension bar, click the AdBlock Plus icon
- Click the large blue toggle for this website
- Click refresh
- In the extension bar, click the AdBlock icon
- Under "Pause on this site" click "Always"
- In the extension bar, click on the Adguard icon
- Click on the large green toggle for this website
- In the extension bar, click on the Ad Remover icon
- Click "Disable on This Website"
- In the extension bar, click on the orange lion icon
- Click the toggle on the top right, shifting from "Up" to "Down"
- In the extension bar, click on the Ghostery icon
- Click the "Anti-Tracking" shield so it says "Off"
- Click the "Ad-Blocking" stop sign so it says "Off"
- Refresh the page
- In the extension bar, click on the uBlock Origin icon
- Click on the big, blue power button
- Refresh the page
- In the extension bar, click on the uBlock icon
- Click on the big, blue power button
- Refresh the page
- In the extension bar, click on the UltraBlock icon
- Check the "Disable UltraBlock" checkbox
- Please disable your Ad Blocker
- Disable any DNS blocking tools such as AdGuardDNS or NextDNS
- Disable any privacy or tracking protection extensions such as Firefox Enhanced Tracking Protection or DuckDuckGo Privacy.
If the prompt is still appearing, please disable any tools or services you are using that block internet ads (e.g. DNS Servers, tracking protection or privacy extensions).
Question
Tyrfing
Hey,
So,I'm a newbie to Java,I have an assignment and I'm stuck,I know online there's a lot of paid services who'd solve this for me,I don't want the answer.i've been trying to understand this for while.
-I have to use the toString method and have a test class.
-My problem is I don't understand how we'd update the invoice using just one constructor,and a set method(in short,how to make the output appear like it should).I Feel that what I did is wrong.
-Original Question ,output both mine and the how it supposed to be are the attachments.
First class:
public class Invoice {
private String PartNumber;
private String Description;
private int Quantity ;
private double Price ;
public Invoice(String PartNumber,String Description,int Quantity,double Price){
this.PartNumber=PartNumber;
this.Description=Description;
this.Quantity=Quantity;
this.Price=Price;
}
public Invoice(){
PartNumber="1234";
Description ="Hammer";
Quantity=2;
Price=14.95;
}
public void setPartNumber(String PartNumber){
this.PartNumber=PartNumber;
}
public void setDescription(String Description){
this.Description=Description;
}
public void setQuantity(int Quantity){
this.Quantity=Quantity;
}
public void setPrice(double Price){
this.Price=Price;
}
public double getInvoiceAmount(){
return Quantity*Price;
}
public String toString(){
return String.format("Part Number:%s\nDescription:%s\nQuantity:%d\nPrice:%.2f\nInvoice Amount:%.2f",PartNumber,Description,Quantity,Price,getInvoiceAmount());
}
public void display(){
System.out.println(toString());
}
}
Second class:
public class InvoiceTest {
public static void main(String[] args) {
Invoice a1=new Invoice();
a1.display();
Invoice a2=new Invoice();
a2.setDescription("Yellow Hammer");
a2.setPrice(19.49);
a2.setQuantity(3);
a2.display();
Invoice a3=new Invoice("5678"," Paint Brush",0,0.0);
a3.display();
Invoice a4=new Invoice("5678"," Paint Brush",0,0.0);
a4.setQuantity(3);
a4.setPrice(4.94);
a4.display();
}
}
Link to comment
https://www.neowin.net/forum/topic/1358584-stuck-in-a-java-question/Share on other sites
3 answers to this question
Recommended Posts