What's new

Java Amount Due simple program

chaekayeon

Leecher
Joined
Oct 6, 2021
Posts
12
Reaction
1
1634470919916.png


Is anyone knows this na papaano gawin ito?
 

Attachments

Java:
import java.util.Scanner;

class AmmountDue {

    Scanner s = new Scanner(System.in);
    private final double tax = .12;

    public void computeAmmountDue(double price) {
        double AddTax = price * tax;
        double ammount = price + AddTax;
        System.out.println("Amount due is " + ammount);
    }

    public void computeAmmountDue(double price, int quantity) {
        double AddTax = price * tax;
        double ammount = (price * quantity) + AddTax;
        System.out.println("Amount due is " + ammount);
    }

    public void computeAmmountDue(double price, int quantity, double discount) {
        double AddTax = price * tax;
        double ammount = ((price * quantity) - discount) + AddTax;
        System.out.println("Amount due is " + ammount);
    }

}

public class RunAmmountDue {

    public static void main(String[] args) {
        int num;
        Scanner s = new Scanner(System.in);
        AmmountDue due = new AmmountDue();
        System.out.println("Press any of the then enter values sepaated by spaces: ");
        System.out.println("1  -  Price only");
        System.out.println("2  -  Price, Quantity");
        System.out.println("3  -  Price, Quantity, and discount amount");
        num = s.nextInt();
        switch (num) {
            case 1:
                due.computeAmmountDue(s.nextDouble());
                break;
            case 2:
                due.computeAmmountDue(s.nextDouble(), s.nextInt());
                break;
            case 3:
                due.computeAmmountDue(s.nextDouble(), s.nextInt(), s.nextDouble());
                break;
            default:
                System.out.println("Invalid Input");
                break;
        }
    }
}
 

chaekayeon

Leecher
Java:
import java.util.Scanner;

class AmmountDue {

    Scanner s = new Scanner(System.in);
    private final double tax = .12;

    public void computeAmmountDue(double price) {
        double AddTax = price * tax;
        double ammount = price + AddTax;
        System.out.println("Amount due is " + ammount);
    }

    public void computeAmmountDue(double price, int quantity) {
        double AddTax = price * tax;
        double ammount = (price * quantity) + AddTax;
        System.out.println("Amount due is " + ammount);
    }

    public void computeAmmountDue(double price, int quantity, double discount) {
        double AddTax = price * tax;
        double ammount = ((price * quantity) - discount) + AddTax;
        System.out.println("Amount due is " + ammount);
    }

}

public class RunAmmountDue {

    public static void main(String[] args) {
        int num;
        Scanner s = new Scanner(System.in);
        AmmountDue due = new AmmountDue();
        System.out.println("Press any of the then enter values sepaated by spaces: ");
        System.out.println("1  -  Price only");
        System.out.println("2  -  Price, Quantity");
        System.out.println("3  -  Price, Quantity, and discount amount");
        num = s.nextInt();
        switch (num) {
            case 1:
                due.computeAmmountDue(s.nextDouble());
                break;
            case 2:
                due.computeAmmountDue(s.nextDouble(), s.nextInt());
                break;
            case 3:
                due.computeAmmountDue(s.nextDouble(), s.nextInt(), s.nextDouble());
                break;
            default:
                System.out.println("Invalid Input");
                break;
        }
    }
}

Iniba ko sa akin but it's almost similar to yours po!
 

Attachments

EYSA

Leecher
Java:
import java.util.Scanner;

class AmmountDue {

    Scanner s = new Scanner(System.in);
    private final double tax = .12;

    public void computeAmmountDue(double price) {
        double AddTax = price * tax;
        double ammount = price + AddTax;
        System.out.println("Amount due is " + ammount);
    }

    public void computeAmmountDue(double price, int quantity) {
        double AddTax = price * tax;
        double ammount = (price * quantity) + AddTax;
        System.out.println("Amount due is " + ammount);
    }

    public void computeAmmountDue(double price, int quantity, double discount) {
        double AddTax = price * tax;
        double ammount = ((price * quantity) - discount) + AddTax;
        System.out.println("Amount due is " + ammount);
    }

}

public class RunAmmountDue {

    public static void main(String[] args) {
        int num;
        Scanner s = new Scanner(System.in);
        AmmountDue due = new AmmountDue();
        System.out.println("Press any of the then enter values sepaated by spaces: ");
        System.out.println("1  -  Price only");
        System.out.println("2  -  Price, Quantity");
        System.out.println("3  -  Price, Quantity, and discount amount");
        num = s.nextInt();
        switch (num) {
            case 1:
                due.computeAmmountDue(s.nextDouble());
                break;
            case 2:
                due.computeAmmountDue(s.nextDouble(), s.nextInt());
                break;
            case 3:
                due.computeAmmountDue(s.nextDouble(), s.nextInt(), s.nextDouble());
                break;
            default:
                System.out.println("Invalid Input");
                break;
        }
    }
}
YOU SAVED ME
 

EYSA

Leecher
Java:
import java.util.Scanner;

class AmmountDue {

    Scanner s = new Scanner(System.in);
    private final double tax = .12;

    public void computeAmmountDue(double price) {
        double AddTax = price * tax;
        double ammount = price + AddTax;
        System.out.println("Amount due is " + ammount);
    }

    public void computeAmmountDue(double price, int quantity) {
        double AddTax = price * tax;
        double ammount = (price * quantity) + AddTax;
        System.out.println("Amount due is " + ammount);
    }

    public void computeAmmountDue(double price, int quantity, double discount) {
        double AddTax = price * tax;
        double ammount = ((price * quantity) - discount) + AddTax;
        System.out.println("Amount due is " + ammount);
    }

}

public class RunAmmountDue {

    public static void main(String[] args) {
        int num;
        Scanner s = new Scanner(System.in);
        AmmountDue due = new AmmountDue();
        System.out.println("Press any of the then enter values sepaated by spaces: ");
        System.out.println("1  -  Price only");
        System.out.println("2  -  Price, Quantity");
        System.out.println("3  -  Price, Quantity, and discount amount");
        num = s.nextInt();
        switch (num) {
            case 1:
                due.computeAmmountDue(s.nextDouble());
                break;
            case 2:
                due.computeAmmountDue(s.nextDouble(), s.nextInt());
                break;
            case 3:
                due.computeAmmountDue(s.nextDouble(), s.nextInt(), s.nextDouble());
                break;
            default:
                System.out.println("Invalid Input");
                break;
        }
    }
}
Marunong ka nung code sa fruit basket?
 

EYSA

Leecher
Java:
import java.util.Scanner;

class AmmountDue {

    Scanner s = new Scanner(System.in);
    private final double tax = .12;

    public void computeAmmountDue(double price) {
        double AddTax = price * tax;
        double ammount = price + AddTax;
        System.out.println("Amount due is " + ammount);
    }

    public void computeAmmountDue(double price, int quantity) {
        double AddTax = price * tax;
        double ammount = (price * quantity) + AddTax;
        System.out.println("Amount due is " + ammount);
    }

    public void computeAmmountDue(double price, int quantity, double discount) {
        double AddTax = price * tax;
        double ammount = ((price * quantity) - discount) + AddTax;
        System.out.println("Amount due is " + ammount);
    }

}

public class RunAmmountDue {

    public static void main(String[] args) {
        int num;
        Scanner s = new Scanner(System.in);
        AmmountDue due = new AmmountDue();
        System.out.println("Press any of the then enter values sepaated by spaces: ");
        System.out.println("1  -  Price only");
        System.out.println("2  -  Price, Quantity");
        System.out.println("3  -  Price, Quantity, and discount amount");
        num = s.nextInt();
        switch (num) {
            case 1:
                due.computeAmmountDue(s.nextDouble());
                break;
            case 2:
                due.computeAmmountDue(s.nextDouble(), s.nextInt());
                break;
            case 3:
                due.computeAmmountDue(s.nextDouble(), s.nextInt(), s.nextDouble());
                break;
            default:
                System.out.println("Invalid Input");
                break;
        }
    }
}
import java.util.Scanner;
import java.util.Stack;

public class fruitbasket1{

public static void main(String[] args){
Scanner eyy = new Scanner(System.in);
Stack<String>basket = new Stack<String>();

String a = "Apple";
String o = "Orange";
String m = "Mango";
String g = "Guava";

System.out.println("Catch and eat any of these fruits; ('apple),('mango'),('orange'),('orange')");
System.out.print("How many fruits would you like to catch: ");
int num = eyy.nextlnt();
for(int i = 0;i<=num;i++){
System.out.println("Fruits"+i+"of"+num);
char f = eyy.next().charAt(0);
if(f.equals("a")){
Basket.push(a);
}else if(f.equals("o")){
Basket.push(o);
}else if(f.equals("m")){
Basket.push(m);
}else if (f.equals("g")){
Basket.push(g);
}else{
System.out.println("Not Available");
}
}
System.out.println("Your basket now has:" + Basket);
System.out.print("Press E to eat fruit: ");

while(true){
char e = eyy.next().charAt(0);
if(e == 'e'){
Basket.pop();
}
System.out.println("Fruit(s) in the basket:" + Basket);
System.out.print("Press E to eat fruit: ");
if(Basket.isEmpty()){
System.out.println("MO MORE FRUITS");
break;
}
System.out.println("Fruit(s) in the basket:" + Basket);
System.out.print("Press E to eat fruit: ");
}
}
}


pa ask anong mali
 
import java.util.Scanner;
import java.util.Stack;

public class fruitbasket1{

public static void main(String[] args){
Scanner eyy = new Scanner(System.in);
Stack<String>basket = new Stack<String>();

String a = "Apple";
String o = "Orange";
String m = "Mango";
String g = "Guava";

System.out.println("Catch and eat any of these fruits; ('apple),('mango'),('orange'),('orange')");
System.out.print("How many fruits would you like to catch: ");
int num = eyy.nextlnt();
for(int i = 0;i<=num;i++){
System.out.println("Fruits"+i+"of"+num);
char f = eyy.next().charAt(0);
if(f.equals("a")){
Basket.push(a);
}else if(f.equals("o")){
Basket.push(o);
}else if(f.equals("m")){
Basket.push(m);
}else if (f.equals("g")){
Basket.push(g);
}else{
System.out.println("Not Available");
}
}
System.out.println("Your basket now has:" + Basket);
System.out.print("Press E to eat fruit: ");

while(true){
char e = eyy.next().charAt(0);
if(e == 'e'){
Basket.pop();
}
System.out.println("Fruit(s) in the basket:" + Basket);
System.out.print("Press E to eat fruit: ");
if(Basket.isEmpty()){
System.out.println("MO MORE FRUITS");
break;
}
System.out.println("Fruit(s) in the basket:" + Basket);
System.out.print("Press E to eat fruit: ");
}
}
}


pa ask anong mali
yung sa for loops mo paps +1 mo dapat yung i para 1 of 4 yung lalabasbas
basket yung declare mo pero Basket nilagay mo

ung sa press e ns input lagay mo dapat sa loob ng while loops mo para di na kailangan ulitin yung press e ng system out
Lagay mo lang sa while(!basket.isEmpty){
laman ng basket
}
 
yung sa for loops mo paps +1 mo dapat yung i para 1 of 4 yung lalabasbas
basket yung declare mo pero Basket nilagay mo

ung sa press e ns input lagay mo dapat sa loob ng while loops mo para di na kailangan ulitin yung press e ng system out
Lagay mo lang sa while(!basket.isEmpty){
laman ng basket
}
Code:
import java.util.Scanner;
import java.util.Stack;

public class fruitbasket1 {

    public static void main(String[] args) {
        Scanner eyy = new Scanner(System.in);
        Stack basket = new Stack();

        String a = "Apple";
        String o = "Orange";
        String m = "Mango";
        String g = "Guava";

        System.out.println("Catch and eat any of these fruits; ('apple),('mango'),('orange'),('orange')");
        System.out.print("How many fruits would you like to catch: ");
        int num = eyy.nextInt();

        for (int x = 0; x < num; x++) {
            int xx = x + 1;
            System.out.print("Fruit " + xx + " of " + num + ": ");
            char fr = eyy.next().charAt(0);
            eyy.nextLine();
            String sfr = String.valueOf(fr);//Convert char to string
            if (sfr.equalsIgnoreCase("A")) {
                basket.push(a);
            } else if (sfr.equalsIgnoreCase("O")) {
                basket.push(o);
            } else if (sfr.equalsIgnoreCase("M")) {
                basket.push(m);
            } else if (sfr.equalsIgnoreCase("G")) {
                basket.push(g);
            }
        }

        System.out.println("Your basket now has:" + basket);

        while (true) {
            System.out.print("Press E to eat fruit: ");
            char e = eyy.next().charAt(0);
            eyy.nextLine();
            if (e == 'e') {
                basket.pop();
                while (!basket.isEmpty()) {
                    System.out.println("Fruit(s) in the basket:" + basket);
                    break;
                }
            }
            if (basket.isEmpty()) {
                System.out.println("MO MORE FRUITS");
                break;
            }

        }
    }
}
 

EYSA

Leecher
yung sa for loops mo paps +1 mo dapat yung i para 1 of 4 yung lalabasbas
basket yung declare mo pero Basket nilagay mo

ung sa press e ns input lagay mo dapat sa loob ng while loops mo para di na kailangan ulitin yung press e ng system out
Lagay mo lang sa while(!basket.isEmpty){
laman ng basket
}
wahh moms ako hahaha hindi paps may socmeds kaba? pahinge pm kita haha
 

New Topics

Online statistics

Members online
492
Guests online
753
Total visitors
1,245

Forum statistics

Threads
1,238,235
Posts
21,703,282
Members
1,617,784
Attachments
1,745,004
Profile posts
100,385
Top