Witam.
Problem prosty ale jakoś nie mogłem sobie z nim poradzić. Mam do napisania program obliczający ile użytkownik musi dopłacić do abonamentu.
Tzn ma w pakiecie 300 darmowych minut i 100 darmowych SMSów. Każda dodatkowa minuta to 8 groszy a każdy SMS to kolejne 5 groszy. Program działa jeśli użytkownik przekroczy osobno minuty i SMSy. W momencie kiedy przekroczy limit dla obu program oblicza tylko dodatkowe minuty, całkowicie ignorując SMSy.
import javax.swing.JOptionPane;
public class Week4PhoneBill
{
public static void main(String[] args)
{
String mins = JOptionPane.showInputDialog("How many minutes did you use?");
String ts = JOptionPane.showInputDialog("How many text messages did you send?");
int minutes = Integer.parseInt(mins);
int texts = Integer.parseInt(ts);
int freeMins = 300;
int freeTexts = 100;
int total = 10*100;
int minute = 8;
int text = 5;
// Within limits
if (minutes <= freeMins && texts <= freeTexts)
{
total = total;
}
// Minutes over limit
else if (minutes > freeMins)
{
total += ((minutes - freeMins) * minute);
}
// Texts over limit
else if (texts > freeTexts)
{
total += ((texts - freeTexts) * text);
}
// Both minutes and texts over limit
else if (minutes > freeMins && texts > freeTexts)
{
total += ((minutes - freeMins) * minute) + ((texts - freeTexts) * text);
}
JOptionPane.showMessageDialog(null, total);
}
}