Program 1 - Vehicle load capacity Every vehicle has a maximum value, in kilograms, that can be loaded unto the vehicle. You must write a small application in JAVA that can assist a builder to determine if the goods he wants to buy weighs less than load capacity of his truck. Your program must:- 1. Read the load capacity of the vehicle as input 2. Read the name and weight of three items as input 3. Calculate the total weight for the items 4. Display all items and the weight. 5. Display the total weight for all items 6.
//VehicleLoadCapacity.java
import java.util.Scanner;
public class VehicleLoadCapacity {
int load, load1,load2,load3;
String productName;
VehicleLoadCapacity(){
}
//scan load values
public void scanLoad(){
int load1,load2,load3,sum=0;
String productName1,productName2,productName3;
Scanner sc=new Scanner(System.in);
//product details
System.out.println("Please enter the details for the product 1");
System.out.println("Enter product name");
productName1=sc.next();
System.out.println("Enter load in kg");
load1=sc.nextInt();
System.out.println("Name of the product1:"+productName1);
System.out.println("The weight of the load1 is:"+load1);
System.out.println("Please enter the details for the product 2");
System.out.println("Enter product name");
productName2=sc.next();
System.out.println("Enter load in kg");
load2=sc.nextInt();
System.out.println("Name of the product1:"+productName2);
System.out.println("The weight of the load1 is:"+load2);
System.out.println("Please enter the details for the product 3");
System.out.println("Enter product name");
productName3=sc.next();
System.out.println("Enter load in kg");
load3=sc.nextInt();
System.out.println("Name of the product1:"+productName3);
System.out.println("The weight of the load1 is:"+load3);
if(load1<5000){
sum+=load1;
if(sum<5000){
sum+=load2;
if(sum<500){
sum+=load3;
System.out.println("The load of the truck:"+sum);
System.out.println("Name of the product1:"+productName1+","+productName2+"and"+productName3);
}else{
System.out.println("The load of the truck:"+sum);
System.out.println("Name of the product1:"+productName1+"and"+productName2);
}
}else{
System.out.println("The load of the truck:"+sum);
System.out.println("Name of the product1:"+productName1);
}
}else{
System.out.println("Truck is overloaded");
}
}
public int getLoad() {
return load;
}
public void setLoad(int load) {
this.load = load;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
}
//main.java
public class Main{
VehicleLoadCapacity v;
public static void main(String[] args) {
// TODO Auto-generated method stub
VehicleLoadCapacity vlc=new VehicleLoadCapacity();
vlc.scanLoad();
}
}
Comments
Leave a comment