Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Question, Just need a basic class for an intersection related java project.

ID: 3679552 • Letter: J

Question

Java Question, Just need a basic class for an intersection related java project. The project is to create a traffic intersection with different lanes and queue cars, etc. The class needed is just to generate the cars. This class has to take in values from user inputed values ( percentages ) from a java GUI ( GUI not needed, just that's where the inputs are coming from ) There will be four values 1) for left turning 2) for southbound 3) northbound 4) exiting parkinglot. These percentages then decide how many cars go into which lane. So if there user inputed 25% for each value and there were 4 cars, then there would be 1 car in each lane. Nothing complex is expected nor wanted.

Explanation / Answer

java program:

import java.io.*;
import java.util.Scanner;
public class TrafficTest {
  
public static void main(String[] args)throws IOException{
int cars;
Scanner scan=new Scanner(System.in);
System.out.println(" Total Number of Cars Entered:");
cars=scan.nextInt();
TrafficIntersection ti=new TrafficIntersection(cars);
ti.setValues();
ti.printCarValues();
}
}
class TrafficIntersection{
int cars;
double leftTurn,southBound,northBound,parkingLot;
public TrafficIntersection(int cars){
this.cars=cars;
}
public void setValues()
{
Scanner scan=new Scanner(System.in);
System.out.print(" Percentage of cars leftTurn:");
leftTurn=scan.nextDouble();
System.out.print(" Percentage of cars southBound:");
southBound=scan.nextDouble();
System.out.print(" Percentage of cars northBound:");
northBound=scan.nextDouble();
System.out.print(" Percentage of cars parkingLot:");
parkingLot=scan.nextDouble();
}
public void printCarValues(){
System.out.print(" Number of cars leftTurn:"+(leftTurn/100)*cars);

System.out.print(" Number of cars southBound:"+(southBound/100)*cars);

System.out.print(" Number of cars northBound:"+(northBound/100)*cars);

System.out.print(" Number of cars parkingLot:"+(parkingLot/100)*cars);
}
}

output:

run:

Total Number of Cars Entered:
20

Percentage of cars leftTurn:20

Percentage of cars southBound:30

Percentage of cars northBound:30

Percentage of cars parkingLot:20

Number of cars leftTurn:4.0
Number of cars southBound:6.0
Number of cars northBound:6.0
Number of cars parkingLot:4.0BUILD SUCCESSFUL (total time: 37 seconds)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote