Wiem, że nie wolno obrażać ludzi, jednak albo @Pan Grzyb to jest troll albo jest "umysłowo cofnięty".
Jeśli te studia to nie medycyna lub historia sztuki a jakieś techniczne to błagam - zrezygnuj z nich i zrób miejsce komuś innemu.
Rozumiem, że do biedaka nie dotarły jeszcze wieści o GPTChat ale nie uwierzę, że o Google też nie słyszał nie uwierzę. Zwykły leń.
https://www.google.com/search?q=java+cost+calculate+fuel+length&oq=java+cost+calculate+fuel+length
https://www.google.com/search?q=java+cost+calculate+fuel+length+swing
Innych słów nie potrafię użyć wobec osoby, która w dzisiejszych czasach na studiach technicznych(tak przypuszczam) nie ogarnia takiego problemu.
Rozwiązanie zadania zajęło mi 3 minuty z GPTChat (dużo więcej zajęło mi wklejanie treści do ego posta):

Kopiuj
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
public class FuelCostCalculator {
public static void main(String[] args) {
JFrame frame = new JFrame("Kalkulator Kosztów Paliwa");
frame.setSize(300, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame.add(panel);
placeComponents(panel);
frame.setVisible(true);
}
private static void placeComponents(JPanel panel) {
panel.setLayout(null);
JLabel distanceLabel = new JLabel("Dystans (w km)");
distanceLabel.setBounds(10, 10, 150, 25);
panel.add(distanceLabel);
JTextField distanceText = new JTextField(20);
distanceText.setBounds(160, 10, 100, 25);
panel.add(distanceText);
JLabel consumptionLabel = new JLabel("Spalanie na 100 km");
consumptionLabel.setBounds(10, 40, 150, 25);
panel.add(consumptionLabel);
JTextField consumptionText = new JTextField(20);
consumptionText.setBounds(160, 40, 100, 25);
panel.add(consumptionText);
JLabel priceLabel = new JLabel("Cena paliwa za litr");
priceLabel.setBounds(10, 70, 150, 25);
panel.add(priceLabel);
JTextField priceText = new JTextField(20);
priceText.setBounds(160, 70, 100, 25);
panel.add(priceText);
JLabel passengerLabel = new JLabel("Ilość pasażerów");
passengerLabel.setBounds(10, 100, 150, 25);
panel.add(passengerLabel);
JTextField passengerText = new JTextField(20);
passengerText.setBounds(160, 100, 100, 25);
panel.add(passengerText);
JButton calculateButton = new JButton("Oblicz");
calculateButton.setBounds(80, 130, 120, 25);
calculateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Get input values
double distance = Double.parseDouble(distanceText.getText());
double consumption = Double.parseDouble(consumptionText.getText());
double price = Double.parseDouble(priceText.getText());
int passengers = Integer.parseInt(passengerText.getText());
// Perform calculations
double totalFuelCost = (distance / 100) * consumption * price;
double costPerPassenger = totalFuelCost / passengers;
double costPer100km = consumption * price;
// Formatting the output to two decimal places
DecimalFormat df = new DecimalFormat("#.##");
// Show results dialog
JOptionPane.showMessageDialog(null,
"Koszt paliwa: " + df.format(totalFuelCost) + " zł\n" +
"Koszt paliwa na osobę: " + df.format(costPerPassenger) + " zł\n" +
"Koszt przejechania 100 km: " + df.format(costPer100km) + " zł",
"Wyniki", JOptionPane.INFORMATION_MESSAGE);
}
});
panel.add(calculateButton);
}
}
Ponieważ w Java nie piszę to nie wiedziałem jak to uruchomić więc musiałem zapytać:

Efekt:

