Help Pahelp po, Java

Status
Not open for further replies.

Handnasomepa

Forum Guru
Elite
Paayos naman po nung gawa ko oh 🥺 hindi ko po talaga maayos eh, bakamasilip nyo san ung mali, invalid input po kasi lumalabas eh
Java:
import java.util.Scanner;
public class Task2 {
public static void main(String[] args) {
    
    Scanner input = new Scanner(System.in);

    double amount;
    double charge = 0;
    boolean Error = false;
    int Expertise;
    int Capacity;
    int Projects;

    System.out.println("What is your desired amount? ");
    amount = input.nextDouble();
    System.out.println("Type 1 to 3 (3 being the highest) on how expert you are regarding the job: ");
    Expertise = input.nextInt();

    if(Expertise == 1) {charge = amount - (amount * .3); }
    else if(Expertise == 2) {charge = amount + (amount * .1);}
    else if(Expertise == 3) {charge = amount + (amount * .5);}
    else { Error = true;}   

    System.out.println("Type 1 to 3 (3 being the highest) on how big the client is ");
    Capacity = input.nextInt();

    if(Capacity == 1) {charge = charge + 1000;}
    else if(Capacity == 2) {charge = charge + 10000;}
    else if(Capacity == 3) {charge = charge + 100000;}
    else { Error = true;}


    System.out.println("How you done projects similar to this one? (1 for yes, 0 for no");
    Projects = input.nextInt();
    
    if( Projects == 1) {charge = amount * 2; }
    else if(Projects == 2) {charge = amount / 2; }
    else {Error = true;}

    if (Error) { System.out.println("Invalid input");}
    else  {System.out.println("Charge the client" + charge + "php for the entire project");}
}

}
Salamat po 🥺


IMG_20211023_024301.jpg
 

Attachments

everything is working fine.
System.out.println("How you done projects similar to this one? (1 for yes, 0 for no");
Projects = input.nextInt();

input : 0 which is Projects = input.nextInt();
if( Projects == 1) {charge = amount * 2; }
else if(Projects == 2) {charge = amount / 2; }
else {Error = true;}
there is no zero. auto else.

which trigger. this code. Error is true.
if (Error) { System.out.println("Invalid input");}
else {System.out.println("Charge the client" + charge + "php for the entire project");}
 
everything is working fine.
System.out.println("How you done projects similar to this one? (1 for yes, 0 for no");
Projects = input.nextInt();

input : 0 which is Projects = input.nextInt();
if( Projects == 1) {charge = amount * 2; }
else if(Projects == 2) {charge = amount / 2; }
else {Error = true;}
there is no zero. auto else.

which trigger. this code. Error is true.
if (Error) { System.out.println("Invalid input");}
else {System.out.println("Charge the client" + charge + "php for the entire project");}
Pero ang true exception na na cacapture is

you cannot declare variable assignment inside a conditional statement.

else (Error = true) <-- assignment inside a condition

feel ko typo to. kinulang ng =
 
everything is working fine.
System.out.println("How you done projects similar to this one? (1 for yes, 0 for no");
Projects = input.nextInt();

input : 0 which is Projects = input.nextInt();
if( Projects == 1) {charge = amount * 2; }
else if(Projects == 2) {charge = amount / 2; }
else {Error = true;}
there is no zero. auto else.

which trigger. this code. Error is true.
if (Error) { System.out.println("Invalid input");}
else {System.out.println("Charge the client" + charge + "php for the entire project");}
Oo nga po, hindi ko na napansin, try ko po maya pag tapos ng ate ko sa laptop nya. Sana gumana na. Salamat po!! 💛
 
Status
Not open for further replies.

Similar threads

Back
Top