Question

In: Computer Science

Java ProgrammingAssignment 4.1Create an interactive (the user should be able to input thevalues)...

Java Programming

Assignment 4.1

Create an interactive (the user should be able to input the values) Java Application to process your utility bill for at-least 6 months. Use Class-Object methodology and use single dimensional arraysin your application. Write detailed comments in your program. You should have a two classes (for example, MontlyBill.java & MontlyBillTest.java).

.Hint: Use the program (GradeBook) in Fig 7.14 & 7.15(GradeBookTest) as a building template.

Assignment 4.2

Use the same program that you have created in 4.1, and use “two dimensional array”. Your program should display several months and several years.

Hint: Use the program in 7.18 & 7.19 as templates.

Solutions

Expert Solution

Assignment 4.1 :

CODE :

File 1 : MonthlyBillTest.java


package monthlybilltest;

import java.util.Scanner;

public class MonthlyBillTest {

public static void main(String[] args) {
System.out.println("Enter monthly bills here for year 2018 : ");
Scanner sc = new Scanner(System.in);
MonthlyBill[] monthlyBill = new MonthlyBill[12];
double bill;
String monthName;
int year;
// enter details of month 1
System.out.print("Enter month name : ");
monthName = sc.next();
System.out.print("Enter bill amount : ");
bill = sc.nextDouble();
year = 2018;
monthlyBill[0] = (new MonthlyBill(bill, monthName, year));
// enter details of month 2
System.out.print("Enter month name : ");
monthName = sc.next();
System.out.print("Enter bill amount : ");
bill = sc.nextDouble();
year = 2018;
monthlyBill[1] = (new MonthlyBill(bill, monthName, year));
// enter details of month 3
System.out.print("Enter month name : ");
monthName = sc.next();
System.out.print("Enter bill amount : ");
bill = sc.nextDouble();
year = 2018;
monthlyBill[2] = (new MonthlyBill(bill, monthName, year));
// enter details of month 4
System.out.print("Enter month name : ");
monthName = sc.next();
System.out.print("Enter bill amount : ");
bill = sc.nextDouble();
year = 2018;
monthlyBill[3] = (new MonthlyBill(bill, monthName, year));
// enter details of month 5
System.out.print("Enter month name : ");
monthName = sc.next();
System.out.print("Enter bill amount : ");
bill = sc.nextDouble();
year = 2018;
monthlyBill[4] = (new MonthlyBill(bill, monthName, year));
// enter details of month 6
System.out.print("Enter month name : ");
monthName = sc.next();
System.out.print("Enter bill amount : ");
bill = sc.nextDouble();
year = 2018;
monthlyBill[5] = (new MonthlyBill(bill, monthName, year));
  
System.out.println("Printing all entered details : ");
  
// printing details of all 6 months :
for(int i=0; i<6; i++){
monthlyBill[i].printMonthData();
}
  
}
  
}

*******************************************************************

File 2 : MonthlyBill.java

package monthlybilltest;

public class MonthlyBill {
public double electricityBillAmount;
public String monthName;
public int year;

public double getElectricityBillAmount() {
return electricityBillAmount;
}

public void setElectricityBillAmount(double electricityBillAmount) {
this.electricityBillAmount = electricityBillAmount;
}

public String getMonthName() {
return monthName;
}

public void setMonthName(String monthName) {
this.monthName = monthName;
}

public int getYear() {
return year;
}

public void setYear(int year) {
this.year = year;
}

public MonthlyBill(double electricityBillAmount, String monthName, int year) {
this.electricityBillAmount = electricityBillAmount;
this.monthName = monthName;
this.year = year;
}
  
public void printMonthData(){
System.out.println(" "+ this.year + " " + this.monthName + " " + this.electricityBillAmount);
}
}

----------------------------------------------------------------------------------------

Sample output :

-----------------------------------------------------------------------------------

Assignment 4.2 :

Code :

File 1 : MonthlyBillTest.java


package monthlybilltest;

import java.util.Scanner;

public class MonthlyBillTest {

public static void main(String[] args) {
System.out.println("Enter monthly bills here for year 2018 : ");
Scanner sc = new Scanner(System.in);
MonthlyBill[][] monthlyBill = new MonthlyBill[2][12];
// this array will store monthly bills.
// here row 1 will store the details of year 2017
// row 2 will store details of year 2018
  
double bill;
String monthName;
int year;
// enter details for year 2018 :
for(int i=0; i<2; i++){
System.out.print("Enter details for year "+((i == 0)? "2017" : "2018") + "\n");
for(int j = 0; j<12; j++){
System.out.print("Enter month name : ");
monthName = sc.next();
System.out.print("Enter bill amount : ");
bill = sc.nextDouble();
if(i == 0){
year = 2017;
}
else{
year = 2018;
}
monthlyBill[i][j] = (new MonthlyBill(bill, monthName, year));
}
}
System.out.println("Printing all entered details : ");
  
// printing details of all 6 months :
for(int i=0; i<2; i++){
for(int j = 0; j<12; j++){
monthlyBill[i][j].printMonthData();
}
}
  
}
  
}

*********************************************************

File 2 : MonthlyBill.java

package monthlybilltest;

public class MonthlyBill {
public double electricityBillAmount;
public String monthName;
public int year;

public double getElectricityBillAmount() {
return electricityBillAmount;
}

public void setElectricityBillAmount(double electricityBillAmount) {
this.electricityBillAmount = electricityBillAmount;
}

public String getMonthName() {
return monthName;
}

public void setMonthName(String monthName) {
this.monthName = monthName;
}

public int getYear() {
return year;
}

public void setYear(int year) {
this.year = year;
}

public MonthlyBill(double electricityBillAmount, String monthName, int year) {
this.electricityBillAmount = electricityBillAmount;
this.monthName = monthName;
this.year = year;
}
  
public void printMonthData(){
System.out.println(" "+ this.year + " " + this.monthName + " " + this.electricityBillAmount);
}
}

-------------------------------------------------------------------------

Sample output :

Enter monthly bills here for year 2018 :
Enter details for year 2017
Enter month name : jan
Enter bill amount : 1
Enter month name : feb
Enter bill amount : 2
Enter month name : march
Enter bill amount : 3
Enter month name : april
Enter bill amount : 4
Enter month name : may
Enter bill amount : 5
Enter month name : jun
Enter bill amount : 6
Enter month name : july
Enter bill amount : 7
Enter month name : august
Enter bill amount : 8
Enter month name : sept
Enter bill amount : 9
Enter month name : oct
Enter bill amount : 10
Enter month name : nov
Enter bill amount : 11
Enter month name : dec
Enter bill amount : 12
Enter details for year 2018
Enter month name : jan
Enter bill amount : 1
Enter month name : feb
Enter bill amount : 22
Enter month name : march
Enter bill amount : 33
Enter month name : april
Enter bill amount : 44
Enter month name : may
Enter bill amount : 55
Enter month name : jun
Enter bill amount : 66
Enter month name : july
Enter bill amount : 77
Enter month name : aug
Enter bill amount : 88
Enter month name : sept
Enter bill amount : 99
Enter month name : oct
Enter bill amount : 1010
Enter month name : nov
Enter bill amount : 1111
Enter month name : dec
Enter bill amount : 1212
Printing all entered details :
2017 jan 1.0
2017 feb 2.0
2017 march 3.0
2017 april 4.0
2017 may 5.0
2017 jun 6.0
2017 july 7.0
2017 august 8.0
2017 sept 9.0
2017 oct 10.0
2017 nov 11.0
2017 dec 12.0
2018 jan 1.0
2018 feb 22.0
2018 march 33.0
2018 april 44.0
2018 may 55.0
2018 jun 66.0
2018 july 77.0
2018 aug 88.0
2018 sept 99.0
2018 oct 1010.0
2018 nov 1111.0
2018 dec 1212.0
BUILD SUCCESSFUL (total time: 1 minute 45 seconds)


Related Solutions

Using Java create an interactive (the user should be able to input the values) Java Application to process your utility bill for at-least 6 months.
Java ProgrammingAssignment 7.1 (25 points)Using Java create an interactive (the user should be able to input the values) Java Application to process your utility bill for at-least 6 months. Use Class-Object methodology and use single dimensional arrays in your application. Write detailed comments in your program. You should have a two classes (for example, MontlyBill.java & MontlyBillTest.java). You can also be creative and create your “own problem scenario” and come up with your “solution”.Assignment 7.2 (25 points)Use the same program...
JAVA Take in a user input. if user input is "Leap Year" your program should run...
JAVA Take in a user input. if user input is "Leap Year" your program should run exercise 1 if user input is "word count" your program should run exercise 2 Both exercises should run in separate methods Exercise 1: write a java method to check whether a year(integer) entered by the user is a leap year or not. Exercise 2: Write a java method to count all words in a string.
Write a Java program that reads an input graph data from a user. Then, it should...
Write a Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number of vertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2 0...
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Your Java program should perform the following things:Take the input from the user about the...
Your Java program should perform the following things:Take the input from the user about the patient name, weight, birthdate, and height.Calculate Body Mass Index.Display person name and BMI Category.If the BMI Score is less than 18.5, then underweight.If the BMI Score is between 18.5-24.9, then Normal.If the BMI score is between 25 to 29.9, then Overweight.If the BMI score is greater than 29.9, then Obesity.Calculate Insurance Payment Category based on BMI Category.If underweight, then insurance payment category is low.If Normal...
Instructions JAVA PROGRAMMING 1. Ask the user for a year input (positive integer - should be...
Instructions JAVA PROGRAMMING 1. Ask the user for a year input (positive integer - should be between 1500 and 2019, inclusive). 2. If the year input is not between 1500 and 2019, do not check for leap year, rather print that this year cannot be checked. 3. Take a year input from the user (should be between 1500 and 2019) 4. If the input year is a leap year, print that year is a leap year; otherwise, print that the...
Write an interactive C++·program to have a user input their three initials and the length of...
Write an interactive C++·program to have a user input their three initials and the length of three sides of a triangle. Allow the user to enter the sides in any order. Determine if the entered sides form a valid triangle.The triangle may not have negative sides.The sum of any two sides must be greater than the third side to form a triangle. Determine if the entered sides are part of a scalene, isosceles, or equilateral triangle. Using the Pythagorean Theorem,...
Create in java an interactive GUI application program that will prompt the user to use one...
Create in java an interactive GUI application program that will prompt the user to use one of three calculators, label project name MEDCALC. You can use any color you want for your background other than grey. Be sure to label main java box with “MEDCALC” and include text of “For use only by students” On all three calculators create an alert and signature area for each user. The alert should be something like “All calculations must be confirmed by user...
MIPS ASSEMBLY Have the user input a string and then be able to make changes to...
MIPS ASSEMBLY Have the user input a string and then be able to make changes to the characters that are in the string until they are ready to stop. We will need to read in several pieces of data from the user, including a string and multiple characters. You can set a maximum size for the user string, however, the specific size of the string can change and you can’t ask them how long the string is (see the sample...
Write a Java application with a JavaFXGUI that takes a String input by the user and...
Write a Java application with a JavaFXGUI that takes a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. The GUI needs, at minimum, a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT