0% found this document useful (0 votes)
7 views

Chapter 4 Programs Part 1

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)
7 views

Chapter 4 Programs Part 1

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
You are on page 1/ 5

import java.util.

Scanner;

public class manuf {


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

// Input code number


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

scanner.close();
}
}
2)
import java.util.Scanner;

public class StudentStatus {


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

// Input code number


System.out.print("Enter the code number (1-5): ");
int code = scanner.nextInt();

// Switch statement to determine student status


switch (code) {
case 1:
System.out.println("Status: Freshman");
break;
case 2:
System.out.println("Status: Sophomore");
break;
case 3:
System.out.println("Status: Junior");
break;
case 4:
System.out.println("Status: Senior");
break;
case 5:
System.out.println("Status: Graduate");
break;
default:
System.out.println("Invalid code. Please enter a number
between 1 and 5.");
}
scanner.close();
}
}

import java.util.Scanner;
public class RainfallCalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Ask for the number of years


System.out.print("Enter the number of years: ");
int years = scanner.nextInt();

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

// Outer loop for each year


for (int year = 1; year <= years; year++) {
System.out.println("Year " + year + ":");

// Inner loop for each month


for (int month = 1; month <= 12; month++) {
System.out.print("Enter the inches of rainfall for month
" + month + ": ");
double rainfall = scanner.nextDouble();
totalRainfall += rainfall; // Add monthly rainfall to total
}
}
// Calculate average rainfall
double averageRainfall = totalRainfall / totalMonths;

// Display results
System.out.println("Total months: " + totalMonths);
System.out.println("Total rainfall: " + totalRainfall + "
inches");
System.out.println("Average rainfall per month: " +
averageRainfall + " inches");

scanner.close();
}
}

You might also like