0% found this document useful (0 votes)
9 views5 pages

Java Code for User Input Applications

java 4

Uploaded by

jikitacwb
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

Java Code for User Input Applications

java 4

Uploaded by

jikitacwb
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import [Link].

Scanner;

public class manuf {


public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);

// Input code number


[Link]("Enter the code number (1-4): ");
int code = [Link]();
// Switch statement to determine manufacturer
switch (code) {
case 1
[Link]("Manufacturer: 3M Corporation");
break;
case 2:
[Link]("Manufacturer: Maxell Corporation");
break;
case 3:
[Link]("Manufacturer: Sony Corporation");
break;
case 4:
[Link]("Manufacturer: Verbatim
Corporation");
break;
default:
[Link]("Invalid code. Please enter a number
between 1 and 4.");
}

[Link]();
}
}
2)
import [Link];

public class StudentStatus {


public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);

// Input code number


[Link]("Enter the code number (1-5): ");
int code = [Link]();

// Switch statement to determine student status


switch (code) {
case 1:
[Link]("Status: Freshman");
break;
case 2:
[Link]("Status: Sophomore");
break;
case 3:
[Link]("Status: Junior");
break;
case 4:
[Link]("Status: Senior");
break;
case 5:
[Link]("Status: Graduate");
break;
default:
[Link]("Invalid code. Please enter a number
between 1 and 5.");
}
[Link]();
}
}

import [Link];
public class RainfallCalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);

// Ask for the number of years


[Link]("Enter the number of years: ");
int years = [Link]();

// Initialize variables
int totalMonths = years * 12;
double totalRainfall = 0;

// Outer loop for each year


for (int year = 1; year <= years; year++) {
[Link]("Year " + year + ":");

// Inner loop for each month


for (int month = 1; month <= 12; month++) {
[Link]("Enter the inches of rainfall for month
" + month + ": ");
double rainfall = [Link]();
totalRainfall += rainfall; // Add monthly rainfall to total
}
}
// Calculate average rainfall
double averageRainfall = totalRainfall / totalMonths;

// Display results
[Link]("Total months: " + totalMonths);
[Link]("Total rainfall: " + totalRainfall + "
inches");
[Link]("Average rainfall per month: " +
averageRainfall + " inches");

[Link]();
}
}

You might also like