What's new

Closed I really don;t know how to fix "The assigned value is never used" in Java using Netbeans

Status
Not open for further replies.

arencaru

Addict
Joined
Mar 3, 2020
Posts
19
Reaction
1
Points
73
Good day to all. I'm a new programmer. Patulong naman po if pano ko maayos to? I've been getting these errors all the time.
1583236464827.png
 

Attachments

Try mo e initialize ang value ni "baggage" sa labas ng if-else statement. Sample: int baggage = 0;
 
Last edited:
Simple lang ang solution: di mo nagamit ang isang variable na nadefined mo.
Paano po ba sya ma assign? Here's the code:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication7;

import java.util.Scanner;

/**
*
* @author Allen
*/
public class JavaApplication7 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String customername;
Double ticketprice, meal, insurance, seat, rebookingfee, weight, baggage, tax, subtotal, grandtotal;


Scanner in = new Scanner (System.in);

System.out.println("Customer Name: ");
customername = in.nextLine();

System.out.println("Ticket Price: ");
ticketprice = in.nextDouble();

System.out.println("Meal: ");
meal = in.nextDouble();

System.out.println("Insurance: ");
insurance = in.nextDouble();

System.out.println("Seat: ");
seat = in.nextDouble();

System.out.println("Rebooking Fee: ");
rebookingfee = in.nextDouble();

System.out.println("Baggage Weight(kg): ");
weight = in.nextDouble();

if (weight <=20){
baggage = 700.0;
}else if (weight <=32){
baggage = 1350.0;
}else if (weight <=40){
baggage = 1900.0;
}else if (weight <=70){
baggage = 2500.0;
}else{
System.out.println("Error");

tax = 0.12;
subtotal = ticketprice + meal + insurance + seat + rebookingfee + baggage;
grandtotal = (subtotal * tax) + subtotal;

System.out.println("Customer Name: " + customername);
System.out.println("Ticket Price: " + ticketprice);
System.out.println("Meal: " + meal);
System.out.println("Insurance: " + insurance);
System.out.println("Seat: " + seat);
System.out.println("Rebooking Fee: " + rebookingfee);
System.out.println("Subtotal: " + subtotal);
System.out.println("Grand Total: " + grandtotal);







}
}
}
 
Warning yan na nagdefine ka ng variable na hindi mo ginamit sa program mo.
I need help po. Here's the code:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication7;

import java.util.Scanner;

/**
*
* @author Allen
*/
public class JavaApplication7 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String customername;
Double ticketprice, meal, insurance, seat, rebookingfee, weight, baggage, tax, subtotal, grandtotal;


Scanner in = new Scanner (System.in);

System.out.println("Customer Name: ");
customername = in.nextLine();

System.out.println("Ticket Price: ");
ticketprice = in.nextDouble();

System.out.println("Meal: ");
meal = in.nextDouble();

System.out.println("Insurance: ");
insurance = in.nextDouble();

System.out.println("Seat: ");
seat = in.nextDouble();

System.out.println("Rebooking Fee: ");
rebookingfee = in.nextDouble();

System.out.println("Baggage Weight(kg): ");
weight = in.nextDouble();

if (weight <=20){
baggage = 700.0;
}else if (weight <=32){
baggage = 1350.0;
}else if (weight <=40){
baggage = 1900.0;
}else if (weight <=70){
baggage = 2500.0;
}else{
System.out.println("Error");

tax = 0.12;
subtotal = ticketprice + meal + insurance + seat + rebookingfee + baggage;
grandtotal = (subtotal * tax) + subtotal;

System.out.println("Customer Name: " + customername);
System.out.println("Ticket Price: " + ticketprice);
System.out.println("Meal: " + meal);
System.out.println("Insurance: " + insurance);
System.out.println("Seat: " + seat);
System.out.println("Rebooking Fee: " + rebookingfee);
System.out.println("Subtotal: " + subtotal);
System.out.println("Grand Total: " + grandtotal);







}
}
}
 
Status
Not open for further replies.

Similar threads

Back
Top