0

So im making a program that takes inputs which determine whether or not a car can go on a trip with a randomly generated distance and passengers and I can't get my scoring system to work. I'm trying to get my score system to increase/decrease depending on how people answer. (I only have the color of the car and the model of the car if/else statements coded) I was given a link to a question about comparing strings and that's not what I'm trying to do here, I'm trying to increase or decrease the "totalScore" variable by a value of 1 or 2. I also want the "totalScore" to accumulate by the end so it will say whether or not the car is able to go on the trip(must be 10 or higher) My problem is that I can't get the "totalScore" variable to increase or decrease and I want to know how I can make it increase or decrease. Sorry for not being clearer the first time.

Main.java file:

import java.util.*;
public class Main {
   public static void main(String[] args) {
       Random randRdt = new Random();
       Scanner userIn = new Scanner(System.in);
       int totalScore = (10);
       int score = (totalScore);
       boolean posOfOh = (false);
       System.out.println("Travel project start");
       System.out.println("Enter your car's color: ");
       String given_color = userIn.next();
       System.out.println("Enter your car's model: ");
       String given_model = userIn.next();
       System.out.println("Enter the year it was made: ");
       int given_year = userIn.nextInt();
       System.out.println("Enter your car's mpg (miles per galon): ");
       double given_mpg = userIn.nextDouble();
       System.out.println("Enter your car's max fuel (galons): ");
       double given_fuel_level = userIn.nextDouble();
       System.out.println("Enter your car's max cappacity: ");
       int given_max_occupants = userIn.nextInt();
       System.out.println("Enter true or false depending on whether or not your car has apple play: ");
       boolean given_has_music = userIn.nextBoolean();
       Car carObj = new Car(given_color, given_model, given_year, given_mpg, given_fuel_level, given_max_occupants, given_has_music);
       int randOcc = randRdt.nextInt(11);
       System.out.println("Number of people joining the trip: " + randOcc);
       double randDist = randRdt.nextInt(751);
       System.out.println("Distance you will be traveling (miles): " + randDist);
       if (given_color == "black") {
         totalScore = score - 1;
         posOfOh = (true);
       } else if (given_color == "white") {
         totalScore = score + 1;
         posOfOh = (false);
       } else {
         totalScore = (score);
       }
       if (given_model == "tesla") {
         posOfOh = (false);
         totalScore = score + 2;
       } else if (given_model == "volkswagon") {
         totalScore = score - 2;
       } else {
         totalScore = (score);
       }
       System.out.println(totalScore);
   }
}

Car.java file:

class Car {
  String color;
  String model;
  int year;
  double mpg;
  double max_fuel; 
  int max_occupants;
  boolean has_music;
  public Car(String given_color, String given_model, int given_year, double given_mpg, double given_fuel_level, int given_max_occupants, boolean given_has_music)
  {
    color = given_color;
    model = given_model;
    year = given_year;
    mpg = given_mpg;
    max_fuel = given_fuel_level;
    max_occupants = given_max_occupants;
    has_music = given_has_music;
    }
    public double getMax_fuel() {
      return max_fuel;
    }
    public double getMpg() {
      return mpg;
    }
    public boolean isHas_music() {
      return has_music;
    }
    public int getMax_occupants() {
        return max_occupants;
    }
    public String getColor() {
      return color;
    }
    public int getYear() {
      return year;
    }
    public String getModel() {
      return model;
    }
  }

Please help I have almost no clue what I'm doing.

0 Answers0