What's new

Mga lods baka alam niyo icode using java??

Status
Not open for further replies.
Just return itemPrice * ItemQuantity
or
amountDue = itemPrice * itemQuantity
return amountDue
eto lods
1632411220662.png
 

Attachments

ano ilalagay sa settotalcost??,nabago kona sa gettotalcost
View attachment 1628017
Sa setTotalCost() dito mo gagawin yung operation.
Java:
public void setTotalCost(double itemPrice, int itemQuantity) {
        this.itemPrice = itemPrice;
        this.itemQuantity = itemQuantity;
        this.amountDue = this.itemPrice * this.itemQuantity;
}

Kung mapapasin mo sa tawag sa kanila dapat alam mo na yung purpose, sa getter dun mo lang kukunin yung value ng variable kaya nga get return value lang, sa setter naman dun mo iseset or ilalagay yung value kaya set.

Sa main class mo gumamit ka ng scanner, gumawa ka ng scanner instance. Stick with the instruction given na din naman yan.
Java:
Scanner s = new Scanner(System.in);
You do not have permission to view the full content of this post. Log in or register now.
 
Last edited:
Sa setTotalCost() dito mo gagawin yung operation.
Java:
public void setTotalCost(double itemPrice, int itemQuantity) {
        this.itemPrice = itemPrice;
        this.itemQuantity = itemQuantity;
        this.amountDue = this.itemPrice * this.itemQuantity;
}

Kung mapapasin mo sa tawag sa kanila dapat alam mo na yung purpose, sa getter dun mo lang kukunin yung value ng variable kaya nga get return value lang, sa setter naman dun mo iseset or ilalagay yung value kaya set.

Sa main class mo gumamit ka ng scanner, gumawa ka ng scanner instance. Stick with the instruction given na din naman yan.
Java:
Scanner s = new Scanner(System.in);
You do not have permission to view the full content of this post. Log in or register now.
dito lods san ako nagkamali?? medj nalito nako dyan eh
1632412372024.png
 

Attachments

dito lods san ako nagkamali?? medj nalito nako dyan eh
View attachment 1628018
Sa readInput() nakalagay sa instruction mag lalagay ng input or sa ibang salita mag seset ka ng values dun sa mga variable. Nakuha mo naman yung idea haha mali lang yung implementation.

So sa pag set mo ng value sa variables ano yung gagamitin mo? malamang yung mga setter
Java:
public void readInput(String name, int quanti, double price) {
    setItemName(name);
    setTotalCost(price, quanti)
}
 
dito lods san ako nagkamali?? medj nalito nako dyan eh
View attachment 1628018
Sa writeOutput() naman display lang naman yung output. Since ok na din naman yung mga setter madali nalang yung pag display sakanila. Gagamitin mo dito yung ilang private variables at syempre yung mga getter.
Java:
public void writeOutput() {
    System.out.println("Your are purchasing " + this.itemQuantity + " " + getItemName() + " at " + this.itemPrice + " each.");
    System.out.println("Amount due is " + getTotalCost());
}
 
Sa writeOutput() naman display lang naman yung output. Since ok na din naman yung mga setter madali nalang yung pag display sakanila. Gagamitin mo dito yung ilang private variables at syempre yung mga getter.
Java:
public void writeOutput() {
    System.out.println("Your are purchasing " + this.itemQuantity + " " + getItemName() + " at " + this.itemPrice + " each.");
    System.out.println("Amount due is " + getTotalCost());
}
lods ito sa main ko ano mali ko??
1632413322802.png
 

Attachments

Ok na yung sinend mo kanina na main.java may idadagdag nalang naman doon at may tatangglin yung line 15 & 16.
yang purchase A = new purchase() idagdag mo doon tapos gamitin mo yung readInput() at writeInput()
paano sir kahit example lang
 
paano sir kahit example lang
Java:
import java.util.*;

class main {
    public static void main (String[] args) {
        Scanner s = new Scanner(System.in);
        purchase receipt = new purchase();
       
        System.out.println("Enter the name of the item you are purchasing: ");
        String name = s.nextLine();
        System.out.println("Enter the quantity and price separated by a space: ")
        int quantity = s.nextInt();
        double price = s.nextDouble();
       
        // insert readInput() method here.
        // insert writeInput() method here.
    }
}

You do not have permission to view the full content of this post. Log in or register now.
 
Java:
import java.util.*;

class main {
    public static void main (String[] args) {
        Scanner s = new Scanner(System.in);
        purchase receipt = new purchase();
      
        System.out.println("Enter the name of the item you are purchasing: ");
        String name = s.nextLine();
        System.out.println("Enter the quantity and price separated by a space: ")
        int quantity = s.nextInt();
        double price = s.nextDouble();
      
        // insert readInput() method here.
        // insert writeInput() method here.
    }
}

You do not have permission to view the full content of this post. Log in or register now.
1632416158479.png

bat may error lods??
 

Attachments

Status
Not open for further replies.
Back
Top