Я не знаю, в чем моя ошибка, я не понимаю классы
Я прочитал книгу по Java, но ее бесполезные коды и методы классов смущают меня, и хотя вы выясняете мой код, у меня будетлучшее понимание того, что на самом деле делают эти вещи
public double intoxicated(double weight)
{
double numDrinks;
numDrinks = (0.08 + 0.015) * weight /
(12 * 7.5 * alcohol);
return numDrinks;
}
public class Beer
{
private String name;
private double alcohol;
public String getName(){
return name;
}
public void setName(String n)
{
this.name= name;
}
public double getAlcohol()
{
return Alcohol;
}
public void setAlcohol(double a)
{
this.age = age;
}
public double intoxicated(double weight)
{
double numDrinks;
numDrinks = (0.08 + 0.015) * weight /
(12 * 7.5 * alcohol);
return numDrinks;
}
public static void main(String[] args)
{
Beer beer1 = new Beer();
Beer beer2 = new Beer();
beer1.setName("Cors Light");
beer1.setAlcohol(0.042);
beer2.setName("Heinaken");
beer2.setAlcohol(0.042);
double lightWeight = 100.0;
double heavyWeight = 250.0;
double lightDrinks1 = beer1.intoxicated(lightWeight);
System.out.println("The number of " + beer1.getName() +
" drinks needed to make\na person weighing " +
lightWeight + " pounds intoxicated is " + lightDrinks1);
System.out.println();
double heavyDrinks1 = beer1.intoxicated(heavyWeight);
System.out.println("The number of " + beer1.getName() +
" drinks needed to make\na person weighing " +
heavyWeight + " pounds intoxicated is " + heavyDrinks1);
System.out.println();
double lightDrinks2 = beer2.intoxicated(lightWeight);
System.out.println("The number of " + beer2.getName() +
" drinks needed to make\na person weighing " +
lightWeight + " pounds intoxicated is " + lightDrinks2);
System.out.println();
double heavyDrinks2 = beer2.intoxicated(heavyWeight);
System.out.println("The number of " + beer2.getName() +
" drinks needed to make\na person weighing " +
heavyWeight + " pounds intoxicated is " + heavyDrinks2);
System.out.println();
Beer beer3 = new Beer();
beer3.setName("Miller Genuine Draft Light");
beer3.setAlcohol(0.042); // 4.2% alcohol
lightWeight = 100.0;
heavyWeight = 250.0;
double lightDrinks3 = beer3.intoxicated(lightWeight);
System.out.println("The number of " + beer3.getName() +
" drinks needed to make\na person weighing " +
lightWeight + " pounds intoxicated is " + lightDrinks3);
System.out.println();
double heavyDrinks3 = beer3.intoxicated(heavyWeight);
System.out.println("The number of " + beer3.getName() +
" drinks needed to make\na person weighing " +
heavyWeight + " pounds intoxicated is " + heavyDrinks3);
System.out.println();
}
}