Java 如何使用多种方法?
所以,我必须为一个视频商店写一张发票,它有一个Customer类,它有六个属性,客户名称(字符串)、街道地址(字符串)、城市(字符串)、州(字符串)、邮政编码(字符串)和电话号码。我必须使用一个参数化的构造函数来接收属性作为参数,并提供getter和setter。我相信我做得对 接下来,我必须制作一个视频类,它有四个属性:视频名称(字符串)、视频发布年份(整数)、视频拷贝数(整数)和每日租金(双倍)。我还必须为此做一个参数化构造函数、getter和setter 问题从我的Invoice类开始,该类表示向给定客户出租视频,它还没有完成,但应该有四个属性,客户出租视频、正在出租的视频、出租日期(作为输入字符串)和每日出租率(双倍)。它也应该有三种方法,小计,税和总数。我的问题是我已经为客户和视频设置了预设的方法,我只是不知道如何在if语句中有效地使用它们。我不知道我会在我的第四节测试课上放些什么来让它起作用。在这一点上我几乎不知所措,任何朝着正确方向的努力都将不胜感激。这是我的课 客户:Java 如何使用多种方法?,java,class,setter,getter,invoice,Java,Class,Setter,Getter,Invoice,所以,我必须为一个视频商店写一张发票,它有一个Customer类,它有六个属性,客户名称(字符串)、街道地址(字符串)、城市(字符串)、州(字符串)、邮政编码(字符串)和电话号码。我必须使用一个参数化的构造函数来接收属性作为参数,并提供getter和setter。我相信我做得对 接下来,我必须制作一个视频类,它有四个属性:视频名称(字符串)、视频发布年份(整数)、视频拷贝数(整数)和每日租金(双倍)。我还必须为此做一个参数化构造函数、getter和setter 问题从我的Invoice类开始,该
public class Customer {
private String customerName;
private String streetAddress;
private String custCity;
private String custState;
private String custZip;
private String custPhone;
public Customer(String customerName, String streetAddress, String custCity, String custState, String custZip,
String custPhone) {
super();
this.customerName = customerName;
this.streetAddress = streetAddress;
this.custCity = custCity;
this.custState = custState;
this.custZip = custZip;
this.custPhone = custPhone;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getStreetAddress() {
return streetAddress;
}
public void setStreetAddress(String streetAddress) {
this.streetAddress = streetAddress;
}
public String getCustCity() {
return custCity;
}
public void setCustCity(String custCity) {
this.custCity = custCity;
}
public String getCustState() {
return custState;
}
public void setCustState(String custState) {
this.custState = custState;
}
public String getCustZip() {
return custZip;
}
public void setCustZip(String custZip) {
this.custZip = custZip;
}
public String getCustPhone() {
return custPhone;
}
public void setCustPhone(String custPhone) {
this.custPhone = custPhone;
}
}
视频:
public class Video {
private String videoName;
private int videoYear;
private int copyNum;
private double rentalRate;
public Video(String videoName, int videoYear, int copyNum, double rentalRate) {
super();
this.videoName = videoName;
this.videoYear = videoYear;
this.copyNum = copyNum;
this.rentalRate = rentalRate;
}
public String getVideoName() {
return videoName;
}
public void setVideoName(String videoName) {
this.videoName = videoName;
}
public int getVideoYear() {
return videoYear;
}
public void setVideoYear(int videoYear) {
this.videoYear = videoYear;
}
public int getCopyNum() {
return copyNum;
}
public void setCopyNum(int copyNum) {
this.copyNum = copyNum;
}
public double getRentalRate() {
return rentalRate;
}
public void setRentalRate(double rentalRate) {
this.rentalRate = rentalRate;
}
发票(不完整):
程序4(不完整):
你在学习面向对象,对吗?构造类的一种方法是让Invoice类包含一个Customer对象和几个视频对象(列表)。然后,您可以创建添加/删除视频和打印/删除发票的方法。@heniv181是的,我是。我该如何着手构建这样的东西?对不起,我对这个还比较陌生,我觉得我只是错过了一些在我得到它之后看起来很简单的东西
import java.util.Scanner;
public class Invoice {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
Customer Brandon = new Customer("Brandon James" , "112 Oak Street"
, "CityVille" , "Alabama" , "18229",
"912-2248");
Customer Judy = new Customer("Judy Vermooth" , "8008 Ribbit Ln.",
"Metropolis" , "Pennsylvania" , "24057", "241-8009");
Video Easter = new Video("Easter 2", 2002, 4, 2.49);
Video DareDevil3 = new Video ("Dare Devil 3", 2012, 2, 3.62);
if( Prog4.newRental = "Brandon"){
Customer Brandon = newCust
}
}
}
import java.util.*;
public class Prog4 {
private String newRental;
private String vidName;
private String rentalDate;
private String daysRented;
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.println("Enter Customer Name: ");
String newRental = in.nextLine();
System.out.println("Enter Video Name: ");
String vidName = in.nextLine();
System.out.println("Enter Rental date in mm/dd/yyyy format: ");
String rentalDate = in.nextLine();
System.out.println("Enter Number of Days Rented");
int daysRented = in.nextInt();
}
public String getNewRental() {
return newRental;
}
public void setNewRental(String newRental) {
this.newRental = newRental;
}
public String getVidName() {
return vidName;
}
public void setVidName(String vidName) {
this.vidName = vidName;
}
public String getRentalDate() {
return rentalDate;
}
public void setRentalDate(String rentalDate) {
this.rentalDate = rentalDate;
}
public String getDaysRented() {
return daysRented;
}
public void setDaysRented(String daysRented) {
this.daysRented = daysRented;
}
}